owlapy.abstracts

Submodules

Classes

AbstractOWLOntologyManager

An OWLOntologyManager manages a set of ontologies. It is the main point for creating, loading and accessing

AbstractOWLOntologyChange

Represents an ontology change.

AbstractOWLOntology

Represents an OWL 2 Ontology in the OWL 2 specification.

AbstractOWLReasoner

An OWLReasoner reasons over a set of axioms (the set of reasoner axioms) that is based on the imports closure of

Package Contents

class owlapy.abstracts.AbstractOWLOntologyManager[source]

An OWLOntologyManager manages a set of ontologies. It is the main point for creating, loading and accessing ontologies.

abstract create_ontology(iri: str | owlapy.iri.IRI) owlapy.abstracts.abstract_owl_ontology.AbstractOWLOntology[source]

Creates a new (empty) ontology that that has the specified ontology IRI (and no version IRI).

Parameters:

iri – The IRI of the ontology to be created, can also be a string.

Returns:

The newly created ontology.

abstract load_ontology(iri: owlapy.iri.IRI | str) owlapy.abstracts.abstract_owl_ontology.AbstractOWLOntology[source]

Loads an ontology that is assumed to have the specified ontology IRI as its IRI or version IRI. The ontology IRI will be mapped to an ontology document IRI.

Parameters:

iri

The IRI that identifies the ontology, can also be a string.

It is expected that the ontology will also have this IRI

(although the OWL API should tolerate situations where this is not the case).

Returns:

The OWLOntology representation of the ontology that was loaded.

abstract apply_change(change: AbstractOWLOntologyChange)[source]

A convenience method that applies just one change to an ontology. When this method is used through an OWLOntologyManager implementation, the instance used should be the one that the ontology returns through the get_owl_ontology_manager() call.

Parameters:

change – The change to be applied.

Raises:

ChangeApplied.UNSUCCESSFULLY – if the change was not applied successfully.

class owlapy.abstracts.AbstractOWLOntologyChange(ontology: owlapy.abstracts.abstract_owl_ontology.AbstractOWLOntology)[source]

Represents an ontology change.

__slots__ = ()
get_ontology() owlapy.abstracts.abstract_owl_ontology.AbstractOWLOntology[source]

Gets the ontology that the change is/was applied to.

Returns:

The ontology that the change is applicable to.

class owlapy.abstracts.AbstractOWLOntology[source]

Bases: owlapy.owl_object.OWLObject

Represents an OWL 2 Ontology in the OWL 2 specification.

An OWLOntology consists of a possibly empty set of OWLAxioms and a possibly empty set of OWLAnnotations. An ontology can have an ontology IRI which can be used to identify the ontology. If it has an ontology IRI then it may also have an ontology version IRI. Since OWL 2, an ontology need not have an ontology IRI. (See the OWL 2 Structural Specification).

An ontology cannot be modified directly. Changes must be applied via its OWLOntologyManager.

__slots__ = ()
type_index: Final = 1
abstract classes_in_signature() Iterable[owlapy.class_expression.OWLClass][source]

Gets the classes in the signature of this object.

Returns:

Classes in the signature of this object.

abstract data_properties_in_signature() Iterable[owlapy.owl_property.OWLDataProperty][source]

Get the data properties that are in the signature of this object.

Returns:

Data properties that are in the signature of this object.

abstract object_properties_in_signature() Iterable[owlapy.owl_property.OWLObjectProperty][source]

A convenience method that obtains the object properties that are in the signature of this object.

Returns:

Object properties that are in the signature of this object.

abstract individuals_in_signature() Iterable[owlapy.owl_individual.OWLNamedIndividual][source]

A convenience method that obtains the individuals that are in the signature of this object.

Returns:

Individuals that are in the signature of this object.

abstract equivalent_classes_axioms(c: owlapy.class_expression.OWLClass) Iterable[owlapy.owl_axiom.OWLEquivalentClassesAxiom][source]

Gets all of the equivalent axioms in this ontology that contain the specified class as an operand.

Parameters:

c – The class for which the EquivalentClasses axioms should be retrieved.

Returns:

EquivalentClasses axioms contained in this ontology.

abstract general_class_axioms() Iterable[owlapy.owl_axiom.OWLClassAxiom][source]
Get the general class axioms of this ontology. This includes SubClass axioms with a complex class expression

as the sub class and EquivalentClass axioms and DisjointClass axioms with only complex class expressions.

Returns:

General class axioms contained in this ontology.

abstract data_property_domain_axioms(property: owlapy.owl_property.OWLDataProperty) Iterable[owlapy.owl_axiom.OWLDataPropertyDomainAxiom][source]

Gets the OWLDataPropertyDomainAxiom objects where the property is equal to the specified property.

Parameters:

property – The property which is equal to the property of the retrieved axioms.

Returns:

The axioms matching the search.

abstract data_property_range_axioms(property: owlapy.owl_property.OWLDataProperty) Iterable[owlapy.owl_axiom.OWLDataPropertyRangeAxiom][source]

Gets the OWLDataPropertyRangeAxiom objects where the property is equal to the specified property.

Parameters:

property – The property which is equal to the property of the retrieved axioms.

Returns:

The axioms matching the search.

abstract object_property_domain_axioms(property: owlapy.owl_property.OWLObjectProperty) Iterable[owlapy.owl_axiom.OWLObjectPropertyDomainAxiom][source]

Gets the OWLObjectPropertyDomainAxiom objects where the property is equal to the specified property.

Parameters:

property – The property which is equal to the property of the retrieved axioms.

Returns:

The axioms matching the search.

abstract object_property_range_axioms(property: owlapy.owl_property.OWLObjectProperty) Iterable[owlapy.owl_axiom.OWLObjectPropertyRangeAxiom][source]

Gets the OWLObjectPropertyRangeAxiom objects where the property is equal to the specified property.

Parameters:

property – The property which is equal to the property of the retrieved axioms.

Returns:

The axioms matching the search.

abstract get_owl_ontology_manager() _M[source]

Gets the manager that manages this ontology.

abstract get_ontology_id() _OI[source]

Gets the OWLOntologyID belonging to this object.

Returns:

The OWLOntologyID.

is_anonymous() bool[source]

Check whether this ontology does contain an IRI or not.

abstract add_axiom(axiom: owlapy.owl_axiom.OWLAxiom | Iterable[owlapy.owl_axiom.OWLAxiom])[source]

Add the specified axiom/axioms to the ontology.

Parameters:

axiom – Can be a single axiom or a collection of axioms.

Returns:

Nothing.

abstract remove_axiom(axiom: owlapy.owl_axiom.OWLAxiom | Iterable[owlapy.owl_axiom.OWLAxiom])[source]

Removes the specified axiom/axioms to the ontology.

Parameters:

axiom – Can be a single axiom or a collection of axioms.

Returns:

Nothing.

abstract save(document_iri: owlapy.iri.IRI | None = None)[source]

Saves this ontology, using its IRI to determine where/how the ontology should be saved.

Parameters:

document_iri – Whether you want to save in a different location.

class owlapy.abstracts.AbstractOWLReasoner(ontology: owlapy.abstracts.abstract_owl_ontology.AbstractOWLOntology)[source]

An OWLReasoner reasons over a set of axioms (the set of reasoner axioms) that is based on the imports closure of a particular ontology - the “root” ontology.

__slots__ = ()
abstract data_property_domains(pe: owlapy.owl_property.OWLDataProperty, direct: bool = False) Iterable[owlapy.class_expression.OWLClassExpression][source]
Gets the class expressions that are the direct or indirect domains of this property with respect to the

imports closure of the root ontology.

Parameters:
  • pe – The property expression whose domains are to be retrieved.

  • direct – Specifies if the direct domains should be retrieved (True), or if all domains should be retrieved (False).

Returns:

Let N = equivalent_classes(DataSomeValuesFrom(pe rdfs:Literal)). If direct is True: then if N is not empty then the return value is N, else the return value is the result of super_classes(DataSomeValuesFrom(pe rdfs:Literal), true). If direct is False: then the result of super_classes(DataSomeValuesFrom(pe rdfs:Literal), false) together with N if N is non-empty. (Note, rdfs:Literal is the top datatype).

abstract object_property_domains(pe: owlapy.owl_property.OWLObjectProperty, direct: bool = False) Iterable[owlapy.class_expression.OWLClassExpression][source]
Gets the class expressions that are the direct or indirect domains of this property with respect to the

imports closure of the root ontology.

Parameters:
  • pe – The property expression whose domains are to be retrieved.

  • direct – Specifies if the direct domains should be retrieved (True), or if all domains should be retrieved (False).

Returns:

Let N = equivalent_classes(ObjectSomeValuesFrom(pe owl:Thing)). If direct is True: then if N is not empty then the return value is N, else the return value is the result of super_classes(ObjectSomeValuesFrom(pe owl:Thing), true). If direct is False: then the result of super_classes(ObjectSomeValuesFrom(pe owl:Thing), false) together with N if N is non-empty.

abstract object_property_ranges(pe: owlapy.owl_property.OWLObjectProperty, direct: bool = False) Iterable[owlapy.class_expression.OWLClassExpression][source]
Gets the class expressions that are the direct or indirect ranges of this property with respect to the

imports closure of the root ontology.

Parameters:
  • pe – The property expression whose ranges are to be retrieved.

  • direct – Specifies if the direct ranges should be retrieved (True), or if all ranges should be retrieved (False).

Returns:

Let N = equivalent_classes(ObjectSomeValuesFrom(ObjectInverseOf(pe) owl:Thing)). If direct is True: then if N is not empty then the return value is N, else the return value is the result of super_classes(ObjectSomeValuesFrom(ObjectInverseOf(pe) owl:Thing), true). If direct is False: then the result of super_classes(ObjectSomeValuesFrom(ObjectInverseOf(pe) owl:Thing), false) together with N if N is non-empty.

abstract equivalent_classes(ce: owlapy.class_expression.OWLClassExpression) Iterable[owlapy.class_expression.OWLClassExpression][source]

Gets the class expressions that are equivalent to the specified class expression with respect to the set of reasoner axioms.

Parameters:

ce – The class expression whose equivalent classes are to be retrieved.

Returns:

All class expressions C where the root ontology imports closure entails EquivalentClasses(ce C). If ce is not a class name (i.e. it is an anonymous class expression) and there are no such classes C then there will be no result. If ce is unsatisfiable with respect to the set of reasoner axioms then owl:Nothing, i.e. the bottom node, will be returned.

abstract disjoint_classes(ce: owlapy.class_expression.OWLClassExpression) Iterable[owlapy.class_expression.OWLClassExpression][source]

Gets the class expressions that are disjoint with specified class expression with respect to the set of reasoner axioms.

Parameters:

ce – The class expression whose disjoint classes are to be retrieved.

Returns:

All class expressions D where the set of reasoner axioms entails EquivalentClasses(D ObjectComplementOf(ce)) or StrictSubClassOf(D ObjectComplementOf(ce)).

abstract different_individuals(ind: owlapy.owl_individual.OWLNamedIndividual) Iterable[owlapy.owl_individual.OWLNamedIndividual][source]

Gets the individuals that are different from the specified individual with respect to the set of reasoner axioms.

Parameters:

ind – The individual whose different individuals are to be retrieved.

Returns:

All individuals x where the set of reasoner axioms entails DifferentIndividuals(ind x).

abstract same_individuals(ind: owlapy.owl_individual.OWLNamedIndividual) Iterable[owlapy.owl_individual.OWLNamedIndividual][source]

Gets the individuals that are the same as the specified individual with respect to the set of reasoner axioms.

Parameters:

ind – The individual whose same individuals are to be retrieved.

Returns:

All individuals x where the root ontology imports closure entails SameIndividual(ind x).

abstract equivalent_object_properties(op: owlapy.owl_property.OWLObjectPropertyExpression) Iterable[owlapy.owl_property.OWLObjectPropertyExpression][source]

Gets the simplified object properties that are equivalent to the specified object property with respect to the set of reasoner axioms.

Parameters:

op – The object property whose equivalent object properties are to be retrieved.

Returns:

All simplified object properties e where the root ontology imports closure entails EquivalentObjectProperties(op e). If op is unsatisfiable with respect to the set of reasoner axioms then owl:bottomDataProperty will be returned.

abstract equivalent_data_properties(dp: owlapy.owl_property.OWLDataProperty) Iterable[owlapy.owl_property.OWLDataProperty][source]

Gets the data properties that are equivalent to the specified data property with respect to the set of reasoner axioms.

Parameters:

dp – The data property whose equivalent data properties are to be retrieved.

Returns:

All data properties e where the root ontology imports closure entails EquivalentDataProperties(dp e). If dp is unsatisfiable with respect to the set of reasoner axioms then owl:bottomDataProperty will be returned.

abstract data_property_values(e: owlapy.owl_object.OWLEntity, pe: owlapy.owl_property.OWLDataProperty) Iterable[owlapy.owl_literal.OWLLiteral][source]

Gets the data property values for the specified entity and data property expression.

Parameters:
  • e – The owl entity (usually an individual) that is the subject of the data property values.

  • pe – The data property expression whose values are to be retrieved for the specified entity.

Note: Can be used to get values, for example, of ‘label’ property of owl entities such as classes and properties too (not only individuals).

Returns:

A set of OWLLiterals containing literals such that for each literal l in the set, the set of reasoner axioms entails DataPropertyAssertion(pe ind l).

abstract object_property_values(ind: owlapy.owl_individual.OWLNamedIndividual, pe: owlapy.owl_property.OWLObjectPropertyExpression) Iterable[owlapy.owl_individual.OWLNamedIndividual][source]

Gets the object property values for the specified individual and object property expression.

Parameters:
  • ind – The individual that is the subject of the object property values.

  • pe – The object property expression whose values are to be retrieved for the specified individual.

Returns:

The named individuals such that for each individual j, the set of reasoner axioms entails ObjectPropertyAssertion(pe ind j).

abstract instances(ce: owlapy.class_expression.OWLClassExpression, direct: bool = False, timeout: int = 1000) Iterable[owlapy.owl_individual.OWLNamedIndividual][source]

Gets the individuals which are instances of the specified class expression.

Parameters:
  • ce – The class expression whose instances are to be retrieved.

  • direct – Specifies if the direct instances should be retrieved (True), or if all instances should be retrieved (False).

  • timeout – Time limit in seconds until results must be returned, else empty set is returned.

Returns:

If direct is True, each named individual j where the set of reasoner axioms entails DirectClassAssertion(ce, j). If direct is False, each named individual j where the set of reasoner axioms entails ClassAssertion(ce, j). If ce is unsatisfiable with respect to the set of reasoner axioms then nothing returned.

abstract sub_classes(ce: owlapy.class_expression.OWLClassExpression, direct: bool = False) Iterable[owlapy.class_expression.OWLClassExpression][source]

Gets the set of named classes that are the strict (potentially direct) subclasses of the specified class expression with respect to the reasoner axioms.

Parameters:
  • ce – The class expression whose strict (direct) subclasses are to be retrieved.

  • direct – Specifies if the direct subclasses should be retrieved (True) or if the all subclasses (descendant) classes should be retrieved (False).

Returns:

If direct is True, each class C where reasoner axioms entails DirectSubClassOf(C, ce). If direct is False, each class C where reasoner axioms entails StrictSubClassOf(C, ce). If ce is equivalent to owl:Nothing then nothing will be returned.

abstract disjoint_object_properties(op: owlapy.owl_property.OWLObjectPropertyExpression) Iterable[owlapy.owl_property.OWLObjectPropertyExpression][source]

Gets the simplified object properties that are disjoint with the specified object property with respect to the set of reasoner axioms.

Parameters:

op – The object property whose disjoint object properties are to be retrieved.

Returns:

All simplified object properties e where the root ontology imports closure entails EquivalentObjectProperties(e ObjectPropertyComplementOf(op)) or StrictSubObjectPropertyOf(e ObjectPropertyComplementOf(op)).

abstract disjoint_data_properties(dp: owlapy.owl_property.OWLDataProperty) Iterable[owlapy.owl_property.OWLDataProperty][source]

Gets the data properties that are disjoint with the specified data property with respect to the set of reasoner axioms.

Parameters:

dp – The data property whose disjoint data properties are to be retrieved.

Returns:

All data properties e where the root ontology imports closure entails EquivalentDataProperties(e DataPropertyComplementOf(dp)) or StrictSubDataPropertyOf(e DataPropertyComplementOf(dp)).

abstract sub_data_properties(dp: owlapy.owl_property.OWLDataProperty, direct: bool = False) Iterable[owlapy.owl_property.OWLDataProperty][source]

Gets the set of named data properties that are the strict (potentially direct) subproperties of the specified data property expression with respect to the imports closure of the root ontology.

Parameters:
  • dp – The data property whose strict (direct) subproperties are to be retrieved.

  • direct – Specifies if the direct subproperties should be retrieved (True) or if the all subproperties (descendants) should be retrieved (False).

Returns:

If direct is True, each property P where the set of reasoner axioms entails DirectSubDataPropertyOf(P, pe). If direct is False, each property P where the set of reasoner axioms entails StrictSubDataPropertyOf(P, pe). If pe is equivalent to owl:bottomDataProperty then nothing will be returned.

abstract super_data_properties(dp: owlapy.owl_property.OWLDataProperty, direct: bool = False) Iterable[owlapy.owl_property.OWLDataProperty][source]

Gets the stream of data properties that are the strict (potentially direct) super properties of the specified data property with respect to the imports closure of the root ontology.

Parameters:
  • dp (OWLDataProperty) – The data property whose super properties are to be retrieved.

  • direct (bool) – Specifies if the direct super properties should be retrieved (True) or if the all super properties (ancestors) should be retrieved (False).

Returns:

Iterable of super properties.

abstract sub_object_properties(op: owlapy.owl_property.OWLObjectPropertyExpression, direct: bool = False) Iterable[owlapy.owl_property.OWLObjectPropertyExpression][source]

Gets the stream of simplified object property expressions that are the strict (potentially direct) subproperties of the specified object property expression with respect to the imports closure of the root ontology.

Parameters:
  • op – The object property expression whose strict (direct) subproperties are to be retrieved.

  • direct – Specifies if the direct subproperties should be retrieved (True) or if the all subproperties (descendants) should be retrieved (False).

Returns:

If direct is True, simplified object property expressions, such that for each simplified object property expression, P, the set of reasoner axioms entails DirectSubObjectPropertyOf(P, pe). If direct is False, simplified object property expressions, such that for each simplified object property expression, P, the set of reasoner axioms entails StrictSubObjectPropertyOf(P, pe). If pe is equivalent to owl:bottomObjectProperty then nothing will be returned.

abstract super_object_properties(op: owlapy.owl_property.OWLObjectPropertyExpression, direct: bool = False) Iterable[owlapy.owl_property.OWLObjectPropertyExpression][source]

Gets the stream of object properties that are the strict (potentially direct) super properties of the specified object property with respect to the imports closure of the root ontology.

Parameters:
  • op (OWLObjectPropertyExpression) – The object property expression whose super properties are to be retrieved.

  • direct (bool) – Specifies if the direct super properties should be retrieved (True) or if the all super properties (ancestors) should be retrieved (False).

Returns:

Iterable of super properties.

abstract types(ind: owlapy.owl_individual.OWLNamedIndividual, direct: bool = False) Iterable[owlapy.class_expression.OWLClass][source]

Gets the named classes which are (potentially direct) types of the specified named individual.

Parameters:
  • ind – The individual whose types are to be retrieved.

  • direct – Specifies if the direct types should be retrieved (True), or if all types should be retrieved (False).

Returns:

If direct is True, each named class C where the set of reasoner axioms entails DirectClassAssertion(C, ind). If direct is False, each named class C where the set of reasoner axioms entails ClassAssertion(C, ind).

abstract get_root_ontology() owlapy.abstracts.abstract_owl_ontology.AbstractOWLOntology[source]

Gets the “root” ontology that is loaded into this reasoner. The reasoner takes into account the axioms in this ontology and its import’s closure.

abstract super_classes(ce: owlapy.class_expression.OWLClassExpression, direct: bool = False) Iterable[owlapy.class_expression.OWLClassExpression][source]

Gets the stream of named classes that are the strict (potentially direct) super classes of the specified class expression with respect to the imports closure of the root ontology.

Parameters:
  • ce – The class expression whose strict (direct) super classes are to be retrieved.

  • direct – Specifies if the direct super classes should be retrieved (True) or if the all super classes (ancestors) classes should be retrieved (False).

Returns:

If direct is True, each class C where the set of reasoner axioms entails DirectSubClassOf(ce, C). If direct is False, each class C where set of reasoner axioms entails StrictSubClassOf(ce, C). If ce is equivalent to owl:Thing then nothing will be returned.

data_property_ranges(pe: owlapy.owl_property.OWLDataProperty, direct: bool = False) Iterable[owlapy.owl_data_ranges.OWLDataRange][source]

Gets the data ranges that are the direct or indirect ranges of this property with respect to the imports closure of the root ontology.

Parameters:
  • pe – The property expression whose ranges are to be retrieved.

  • direct – Specifies if the direct ranges should be retrieved (True), or if all ranges should be retrieved (False).

Returns:

all_data_property_values(pe: owlapy.owl_property.OWLDataProperty, direct: bool = True) Iterable[owlapy.owl_literal.OWLLiteral][source]

Gets all values for the given data property expression that appear in the knowledge base.

Parameters:
  • pe – The data property expression whose values are to be retrieved

  • direct – Specifies if only the direct values of the data property pe should be retrieved (True), or if the values of sub properties of pe should be taken into account (False).

Returns:

A set of OWLLiterals containing literals such that for each literal l in the set, the set of reasoner axioms entails DataPropertyAssertion(pe ind l) for any ind.

ind_data_properties(ind: owlapy.owl_individual.OWLNamedIndividual, direct: bool = True) Iterable[owlapy.owl_property.OWLDataProperty][source]

Gets all data properties for the given individual that appear in the knowledge base.

Parameters:
  • ind – The named individual whose data properties are to be retrieved

  • direct – Specifies if the direct data properties should be retrieved (True), or if all data properties should be retrieved (False), so that sub properties are taken into account.

Returns:

All data properties pe where the set of reasoner axioms entails DataPropertyAssertion(pe ind l) for atleast one l.

ind_object_properties(ind: owlapy.owl_individual.OWLNamedIndividual, direct: bool = True) Iterable[owlapy.owl_property.OWLObjectProperty][source]

Gets all object properties for the given individual that appear in the knowledge base.

Parameters:
  • ind – The named individual whose object properties are to be retrieved

  • direct – Specifies if the direct object properties should be retrieved (True), or if all object properties should be retrieved (False), so that sub properties are taken into account.

Returns:

All data properties pe where the set of reasoner axioms entails ObjectPropertyAssertion(pe ind ind2) for atleast one ind2.