ontoenv module¶
- class ontoenv.OntoEnv(path=None, recreate=False, create_or_use_cached=False, read_only=False, search_directories=None, require_ontology_names=False, strict=False, offline=False, use_cached_ontologies=False, resolution_policy=Ellipsis, root=Ellipsis, includes=None, excludes=None, include_ontologies=None, exclude_ontologies=None, temporary=False, remote_cache_ttl_secs=None, graph_store=None)¶
Bases:
object- add(location, overwrite=False, fetch_imports=True, force=False)¶
Add a new ontology to the OntoEnv
- add_no_imports(location, overwrite=False, force=False)¶
Add a new ontology to the OntoEnv without exploring owl:imports.
- close()¶
- dump(includes=None)¶
Print the contents of the OntoEnv
- flush()¶
- get_closure(uri, destination_graph=None, rewrite_sh_prefixes=True, remove_owl_imports=True, recursion_depth=Ellipsis)¶
Merge the imports closure of uri into a single graph and return it alongside the closure list.
The first element of the returned tuple is either the provided destination_graph (after mutation) or a brand-new rdflib.Graph. The second element is an ordered list of ontology IRIs in the resolved closure starting with uri. Set rewrite_sh_prefixes or remove_owl_imports to control post-processing of the merged triples.
- get_dependencies(graph, graph_name=None, recursion_depth=Ellipsis, fetch_missing=False)¶
Get the dependency closure of a given graph and return it as a new graph.
This method will look for owl:imports statements in the provided graph, then find those ontologies within the OntoEnv and compute the full dependency closure. The triples of all ontologies in the closure are returned as a new graph. The original graph is never modified.
- Parameters:
graph (rdflib.Graph) – The graph to find dependencies for.
graph_name (Optional[str]) – If provided, all
owl:Ontologydeclarations from the closure are replaced with a single one for this URI andsh:prefixesare rewritten to point at it. IfNone(default), each ontology in the closure retains its ownowl:Ontologydeclaration (a proper union of the closure graphs);sh:prefixesare left distributed and no root is imposed.recursion_depth (int) – The maximum depth for recursive import resolution. A negative value (default) means no limit.
fetch_missing (bool) – If True, will fetch ontologies that are not in the environment.
- Returns:
A tuple containing the populated dependency graph and the sorted list of imported ontology IRIs.
- Return type:
tuple[rdflib.Graph, list[str]]
- get_graph(uri)¶
Get the graph with the given URI as an rdflib.Graph
- get_importers(uri)¶
Get the names of all ontologies that import the given ontology
- get_namespaces(ontology=None, include_closure=False)¶
Get namespace prefix mappings.
Prefixes are extracted from both parser-level declarations (
@prefixin Turtle,PREFIXin SPARQL-style syntaxes, XML namespace declarations) and SHACLsh:declareentries. SHACL entries take precedence when the same prefix appears in both sources.- Parameters:
ontology – The IRI of the ontology to query. If
None, returns merged namespaces from every ontology in the environment.include_closure – When
True, namespaces from the full transitiveowl:importsclosure of the ontology are included. Ignored whenontologyisNone.
- Returns:
A
dict[str, str]mapping prefix names (e.g."owl") to namespace IRIs (e.g."http://www.w3.org/2002/07/owl#").
- get_ontology(uri)¶
Get the ontology metadata with the given URI
- get_ontology_names()¶
Get the names of all ontologies in the OntoEnv
- import_dependencies(graph, recursion_depth=Ellipsis, fetch_missing=False)¶
Import the dependencies referenced by owl:imports triples in graph.
When fetch_missing is true, the environment attempts to download unresolved imports before computing the closure. After merging the closure triples into graph, all owl:imports statements are removed. The returned list contains the deduplicated ontology IRIs that were successfully imported.
- import_graph(destination_graph, uri, recursion_depth=Ellipsis)¶
- is_offline()¶
- is_strict()¶
- list_closure(uri, recursion_depth=Ellipsis)¶
List the ontologies in the imports closure of the given ontology
- requires_ontology_names()¶
- resolution_policy()¶
- set_offline(offline)¶
- set_require_ontology_names(require)¶
- set_resolution_policy(policy)¶
- set_strict(strict)¶
- store_path()¶
- to_rdflib_dataset()¶
Convert the OntoEnv to an in-memory rdflib.Dataset populated with all named graphs
- update(all=False)¶
- class ontoenv.Ontology¶
Bases:
object- id¶
- imports¶
- last_updated¶
- location¶
- name¶
- namespace_map¶
- version_properties¶
- ontoenv.run_cli(args)¶
Run the Rust CLI implementation and return its process-style exit code.