owlapy.agen_kg.graph_extracting_models

Submodules

Classes

DomainGraphExtractor

Base class for all graph extractors.

OpenGraphExtractor

Base class for all graph extractors.

Package Contents

class owlapy.agen_kg.graph_extracting_models.DomainGraphExtractor(enable_logging=False, examples_cache_dir: str | None = None)[source]

Bases: owlapy.agen_kg.graph_extractor.GraphExtractor

Base class for all graph extractors. Provides common functionality for entity clustering, coherence checking, text chunking for large documents, and utility methods shared across all extractor types.

domain_detector
few_shot_generator
entity_extractor
triples_extractor
type_asserter
type_generator
literal_extractor
spl_triples_extractor
examples_cache
generate_domain_specific_examples(domain: str) → dict[source]

Generate domain-specific few-shot examples for all task types.

Automatically caches examples to disk for future reuse. If examples have been previously generated for the domain, they will be loaded from cache.

Parameters:

domain – The domain for which to generate examples.

Returns:

‘entity_extraction’, ‘triples_extraction’, ‘type_assertion’, ‘type_generation’, ‘literal_extraction’, ‘triples_with_numeric_literals_extraction’

Return type:

Dictionary containing few-shot examples for each task type, keyed by

clear_domain_cache(domain: str) → bool[source]

Clear the cached examples for a specific domain.

Parameters:

domain – The domain for which to clear cached examples.

Returns:

True if the cache was cleared successfully, False otherwise.

clear_all_domain_caches() → bool[source]

Clear all cached domain examples.

Returns:

True if all caches were cleared successfully, False otherwise.

list_cached_domains() → list[source]

List all domains that have cached examples.

Returns:

List of domain names with cached examples.

is_domain_cached(domain: str) → bool[source]

Check if examples exist for a domain in the cache.

Parameters:

domain – The domain to check.

Returns:

True if examples are cached for the domain, False otherwise.

get_cache_file_path(domain: str) → str[source]

Get the full path to the cache file for a domain.

Parameters:

domain – The domain name.

Returns:

String path to the cache file.

generate_ontology(text: Union[str, pathlib.Path], domain: str = None, query: str = None, ontology_namespace=f'http://ontology.local/{uuid.uuid4()}#', entity_types: List[str] = None, generate_types=False, extract_spl_triples=False, create_class_hierarchy=False, use_chunking: bool = None, use_incremental_merging=False, fact_reassurance: bool = True, generate_rdfs_annotations: bool = False, save_path='generated_ontology.owl') → owlapy.owl_ontology.Ontology[source]

Generate a domain-specific ontology from text.

Supports automatic chunking for large texts that exceed the LLM’s context window.

Parameters:
  • text – Input text or file path to extract ontology from. Supports files: .txt, .pdf, .docx, .doc, .rtf, .html, .htm

  • domain – The domain of the text. If None, will be detected automatically.

  • query – A custom prompt to give directions to the agent.

  • ontology_namespace – Namespace for the ontology.

  • entity_types – List of entity types to assign.

  • generate_types – Whether to generate types automatically.

  • extract_spl_triples – Whether to extract subject-property-literal triples.

  • create_class_hierarchy – Whether to create class hierarchy from DBpedia.

  • use_chunking – Whether to use text chunking for large documents. - None (default): Auto-detect based on text size (uses auto_chunk_threshold). - True: Force chunking even for smaller texts. - False: Disable chunking (may fail for very large texts).

  • use_incremental_merging – Whether to use incremental merging when chunking is enabled (default: False).

  • fact_reassurance – Whether to perform the coherence check on triples (default: True).

  • save_path – Path to save the ontology.

Returns:

Generated Ontology object.

class owlapy.agen_kg.graph_extracting_models.OpenGraphExtractor(enable_logging=False)[source]

Bases: owlapy.agen_kg.graph_extractor.GraphExtractor

Base class for all graph extractors. Provides common functionality for entity clustering, coherence checking, text chunking for large documents, and utility methods shared across all extractor types.

entity_extractor
triples_extractor
type_asserter
type_generator
literal_extractor
spl_triples_extractor
generate_ontology(text: Union[str, pathlib.Path], ontology_namespace=f'http://ontology.local/{uuid.uuid4()}#', query: str = None, entity_types: List[str] = None, generate_types=False, extract_spl_triples=False, create_class_hierarchy=False, entity_clustering=True, use_chunking: bool = None, use_incremental_merging: bool = False, examples_for_entity_extraction=EXAMPLES_FOR_ENTITY_EXTRACTION, examples_for_triples_extraction=EXAMPLES_FOR_TRIPLES_EXTRACTION, examples_for_type_assertion=EXAMPLES_FOR_TYPE_ASSERTION, examples_for_type_generation=EXAMPLES_FOR_TYPE_GENERATION, examples_for_literal_extraction=EXAMPLES_FOR_LITERAL_EXTRACTION, examples_for_spl_triples_extraction=EXAMPLES_FOR_SPL_TRIPLES_EXTRACTION, fact_reassurance=True, generate_rdfs_annotations: bool = False, save_path='generated_ontology.owl') → owlapy.owl_ontology.Ontology[source]

Generate an ontology from the given text or file.

Supports automatic chunking for large texts that exceed the LLM’s context window.

Parameters:
  • text – Input text or file path.

  • ontology_namespace – Namespace for the ontology.

  • query – A custom prompt to give directions to the agent.

  • entity_types – List of entity types to assign.

  • generate_types – Whether to generate types automatically.

  • extract_spl_triples – Whether to extract subject-property-literal triples.

  • create_class_hierarchy – Whether to create class hierarchy from DBpedia.

  • entity_clustering – Whether to perform entity clustering.

  • use_chunking – Whether to use text chunking for large documents. - None (default): Auto-detect based on text size (uses auto_chunk_threshold). - True: Force chunking even for smaller texts. - False: Disable chunking (may fail for very large texts).

  • use_incremental_merging – Whether to use incremental merging when chunking is enabled (default: False).

  • examples_for_entity_extraction – Few-shot examples for entity extraction.

  • examples_for_triples_extraction – Few-shot examples for triple extraction.

  • examples_for_type_assertion – Few-shot examples for type assertion.

  • examples_for_type_generation – Few-shot examples for type generation and assertion.

  • examples_for_literal_extraction – Few-shot examples for literal extraction.

  • examples_for_spl_triples_extraction – Few-shot examples for s-p-l triples extraction.

  • fact_reassurance – Whether to enforce as step of fact checking after triple extraction.

  • save_path – Path to save the ontology.

Returns:

Generated Ontology object.