ontocast.tool.triple_manager.util¶
Shared helpers for triple store backends: the catalog read, strictly.
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 vann: <http://purl.org/vocab/vann/>\nPREFIX oc: <https://growgraph.dev/ontocast#>\nSELECT DISTINCT ?g ?onto ?versionIri ?version ?prior ?prefix ?namespace ?title ?description\n ?created ?modified ?removed\nWHERE {\n GRAPH ?g {\n ?onto a owl:Ontology .\n OPTIONAL { ?onto owl:versionIRI ?versionIri }\n OPTIONAL { ?onto owl:versionInfo ?version }\n OPTIONAL { ?onto owl:priorVersion ?prior }\n OPTIONAL { ?onto vann:preferredNamespacePrefix ?prefix }\n OPTIONAL { ?onto vann:preferredNamespaceUri ?namespace }\n OPTIONAL { ?onto dcterms:title ?title }\n OPTIONAL { ?onto dcterms:description ?description }\n OPTIONAL { ?onto dcterms:created ?created }\n OPTIONAL { ?onto dcterms:modified ?modified }\n OPTIONAL { ?g a oc:RemovedVersion . BIND(true AS ?removed) }\n }\n}\n'
module-attribute
¶
__all__ = ['CatalogContractError', 'LIST_NAMED_GRAPHS_QUERY', 'LineageT', 'ONTOLOGY_HEADER_QUERY', 'deterministic_turtle_serialization', 'head_headers', 'headers_from_select_rows', 'ontology_from_named_graph']
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
CatalogContractError
¶
Bases: ValueError
A stored graph does not carry the version header this library writes.
Source code in ontocast/onto/ontology_header.py
Functions:¶
deterministic_turtle_serialization(graph)
¶
Create a deterministic Turtle serialization of an RDF graph.
Source code in ontocast/tool/triple_manager/util.py
head_headers(headers)
¶
One head per ontology; diverged ontologies are logged and left out.
A diverged ontology (several heads) is listed by the catalog and its versions can be read, but nothing extracts against it or extends it until a merge makes one head.
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.
?prior is multi-valued, so the query returns a small cross product; rows
sharing a graph describe one version and are merged.
Raises:
| Type | Description |
|---|---|
CatalogContractError
|
a graph's header is incomplete. |
Source code in ontocast/tool/triple_manager/util.py
ontology_from_named_graph(graph_uri, graph)
¶
Build the :class:Ontology stored as the version graph graph_uri.
Raises:
| Type | Description |
|---|---|
CatalogContractError
|
the graph is not a version of an ontology. A foreign graph in an ontologies dataset is a fault, never a silent gap in the catalog. |