kapps_triplestore_interface.queries.ontology_helpers#
- kapps_triplestore_interface.queries.ontology_helpers.iri_exists(self: GraphDB, iri: str | IRI, as_sub: bool | None = False, as_pred: bool | None = False, as_obj: bool | None = False, include_explicit: bool | None = True, include_implicit: bool | None = True, named_graph: str | IRI | None = None) bool[source]#
Check if an IRI exists as subject, predicate, or object.
- Parameters:
iri (IRILike) – The IRI to check for existence.
as_sub (Optional[bool]) – If True, check existence as subject. Defaults to False.
as_pred (Optional[bool]) – If True, check existence as predicate. Defaults to False.
as_obj (Optional[bool]) – If True, check existence as object. Defaults to False.
include_explicit (Optional[bool]) – Include explicit triples (FROM onto:explicit). Defaults to True.
include_implicit (Optional[bool]) – Include inferred triples (FROM onto:implicit). Defaults to True.
named_graph (Optional[GraphNameLike]) – Override the client’s default named graph.
- Returns:
True if the IRI exists based on the specified criteria, False otherwise.
- Return type:
- Raises:
InvalidInputError – If none of as_sub, as_pred, or as_obj is True.
- kapps_triplestore_interface.queries.ontology_helpers.new_iri(self: GraphDB, base: str | IRI, schema: Callable[[IRI], IRI] | None = None, test_schema: bool = True) IRI[source]#
Generate a new unique IRI within the graph database’s namespace.
- Parameters:
- Returns:
A new unique IRI.
- Return type:
- kapps_triplestore_interface.queries.ontology_helpers.new_blank_id(self: GraphDB, schema: Callable[[], str] | None=<function <lambda>>) str[source]#
Generate a new unique blank node identifier.
- kapps_triplestore_interface.queries.ontology_helpers.is_subclass(self: GraphDB, subclass_iri: str | IRI, class_iri: str | IRI, named_graph: str | IRI | None = None) bool[source]#
Check whether one class is a subclass of another (rdfs:subClassOf).
Asks for subclass_iri rdfs:subClassOf class_iri
- Parameters:
subclass_iri (IRILike) – The IRI of the potential subclass.
class_iri (IRILike) – The IRI of the potential superclass.
named_graph (Optional[GraphNameLike]) – Override the client’s default named graph.
- Returns:
True if subclass_iri is a subclass of class_iri, False otherwise.
- Return type:
- kapps_triplestore_interface.queries.ontology_helpers.owl_is_named_individual(self: GraphDB, iri: str | IRI, named_graph: str | IRI | None = None) bool[source]#
Check if the given IRI corresponds to an OWL named individual.
Asks for iri rdf:type owl:NamedIndividual.
- Parameters:
iri (IRILike) – The IRI to check.
named_graph (Optional[GraphNameLike]) – Override the client’s default named graph.
- Returns:
True if the IRI is a named individual, False otherwise.
- Return type:
- kapps_triplestore_interface.queries.ontology_helpers.owl_get_classes_of_individual(self: GraphDB, instance_iri: str | IRI, ignored_prefixes: List[Namespace] | None = None, local_name: bool | None = False, include_explicit: bool | None = True, include_implicit: bool | None = False, named_graph: str | IRI | None = None) List[str | IRI][source]#
Get the OWL classes associated with a given individual.
Builds a SPARQL query that returns the classes for an instance IRI and optionally filters out results by prefix or returns local names only.
- Parameters:
instance_iri (IRILike) – IRI of the individual to inspect.
ignored_prefixes (Optional[List[Namespace]]) – Prefixes/namespaces to ignore when collecting classes. Defaults to [“owl”, “rdfs”].
local_name (Optional[bool]) – If True, return only the local names of the classes. Defaults to False.
include_explicit (Optional[bool]) – Include explicit triples. Defaults to True.
include_implicit (Optional[bool]) – Include inferred triples. Defaults to False.
named_graph (Optional[GraphNameLike]) – Override the client’s default named graph.
- Returns:
Class IRIs, or local names if local_name=True.
- Return type: