ontocast.tool.triple_manager.util¶
Shared helpers for triple store backends.
Attributes¶
LIST_NAMED_GRAPHS_QUERY = '\nSELECT DISTINCT ?g WHERE {\n GRAPH ?g { ?s ?p ?o }\n}\n'
module-attribute
¶
LineageT = TypeVar('LineageT', bound=OntologyPropertiesWithLineage)
module-attribute
¶
ONTOLOGY_HEADER_QUERY = '\nPREFIX owl: <http://www.w3.org/2002/07/owl#>\nPREFIX dcterms: <http://purl.org/dc/terms/>\nPREFIX prov: <http://www.w3.org/ns/prov#>\nSELECT DISTINCT ?g ?onto ?version ?created ?identifier ?parent\nWHERE {\n GRAPH ?g {\n ?onto a owl:Ontology .\n OPTIONAL { ?onto owl:versionInfo ?version }\n OPTIONAL { ?onto dcterms:created ?created }\n OPTIONAL {\n ?onto dcterms:identifier ?identifier\n FILTER(STRSTARTS(STR(?identifier), "hash:"))\n }\n OPTIONAL {\n ?onto prov:wasDerivedFrom ?parent\n FILTER(STRSTARTS(STR(?parent), "urn:hash:"))\n }\n }\n}\n'
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
Functions:¶
dedupe_terminal_ontologies(all_ontologies)
¶
Keep the latest terminal version per ontology IRI.
Works on anything carrying lineage metadata, so the same selection runs over
materialized :class:~ontocast.onto.ontology.Ontology objects and over
graph-less :class:~ontocast.onto.ontology_header.OntologyHeader records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_ontologies
|
Sequence[LineageT]
|
Every stored version, across all IRIs. The parent-hash sweep needs the full set, not just candidate terminals. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list[LineageT]
|
One entry per distinct IRI, of the same type that was passed in. |
Source code in ontocast/tool/triple_manager/util.py
deterministic_turtle_serialization(graph)
¶
Create a deterministic Turtle serialization of an RDF graph.
Source code in ontocast/tool/triple_manager/util.py
headers_from_select_rows(rows)
¶
Fold :data:ONTOLOGY_HEADER_QUERY rows into one header per named graph.
?parent is multi-valued, so the query returns a small cross product; rows
sharing a (?g, ?onto) pair describe one ontology version and are merged,
accumulating parent_hashes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
Iterable[dict[str, str]]
|
SELECT bindings, each mapping variable name to lexical value. |
required |
Returns:
| Type | Description |
|---|---|
list[OntologyHeader]
|
list[OntologyHeader]: One header per stored ontology version, ordered by |
list[OntologyHeader]
|
graph URI for determinism. |
Source code in ontocast/tool/triple_manager/util.py
ontology_from_named_graph(graph_uri, graph)
¶
Build an :class:Ontology from a named-graph export.
Source code in ontocast/tool/triple_manager/util.py
ontology_iri_for_named_graph(graph_uri, ontology_subject)
¶
Resolve the catalog IRI for an ontology stored in graph_uri.
A versioned graph name (<iri>#<hash>) identifies the ontology by its base
IRI; an unversioned graph name defers to the owl:Ontology subject.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_uri
|
str
|
Named graph URI the ontology was read from. |
required |
ontology_subject
|
str
|
Subject typed |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The ontology's catalog IRI. |