owlapy.owl_ontology

OWL Ontology

Attributes

logger

OWLREADY2_FACET_KEYS

Classes

OWLOntologyID

An object that identifies an ontology. Since OWL 2, ontologies do not have to have an ontology IRI, or if they

Ontology

Represents an OWL 2 Ontology in the OWL 2 specification.

SyncOntology

Represents an OWL 2 Ontology in the OWL 2 specification.

RDFLibOntology

Represents an OWL 2 Ontology in the OWL 2 specification.

ToOwlready2

FromOwlready2

Map owlready2 classes to owlapy model classes.

Module Contents

owlapy.owl_ontology.logger
class owlapy.owl_ontology.OWLOntologyID(ontology_iri: owlapy.iri.IRI | None = None, version_iri: owlapy.iri.IRI | None = None)[source]

An object that identifies an ontology. Since OWL 2, ontologies do not have to have an ontology IRI, or if they have an ontology IRI then they can optionally also have a version IRI. Instances of this OWLOntologyID class bundle identifying information of an ontology together. If an ontology doesn’t have an ontology IRI then we say that it is “anonymous”.

__slots__ = ('_ontology_iri', '_version_iri')
get_ontology_iri() owlapy.iri.IRI | None[source]

Gets the ontology IRI.

Returns:

Ontology IRI. If the ontology is anonymous, it will return None.

get_version_iri() owlapy.iri.IRI | None[source]

Gets the version IRI.

Returns:

Version IRI or None.

get_default_document_iri() owlapy.iri.IRI | None[source]

Gets the IRI which is used as a default for the document that contain a representation of an ontology with this ID. This will be the version IRI if there is an ontology IRI and version IRI, else it will be the ontology IRI if there is an ontology IRI but no version IRI, else it will be None if there is no ontology IRI. See Ontology Documents in the OWL 2 Structural Specification.

Returns:

the IRI that can be used as a default for an ontology document, or None.

is_anonymous() bool[source]
__repr__()[source]
__eq__(other)[source]
class owlapy.owl_ontology.Ontology(manager: _OM, ontology_iri: owlapy.iri.IRI | str, load: bool)[source]

Bases: owlapy.abstracts.abstract_owl_ontology.AbstractOWLOntology

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__ = ('_manager', '_iri', '_world', '_onto', 'is_modified')
is_modified: bool
__len__() int[source]
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.

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.

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.

properties_in_signature() Iterable[owlapy.owl_property.OWLProperty][source]
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 get_abox_axioms() Iterable[source]
abstract get_tbox_axioms() Iterable[source]
abstract get_abox_axioms_between_individuals() Iterable[source]
abstract get_abox_axioms_between_individuals_and_classes() Iterable[source]
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.

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.

get_owl_ontology_manager() _OM[source]

Gets the manager that manages this ontology.

get_ontology_id() OWLOntologyID[source]

Gets the OWLOntologyID belonging to this object.

Returns:

The OWLOntologyID.

data_property_domain_axioms(pe: 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.

data_property_range_axioms(pe: 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.

object_property_domain_axioms(pe: 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.

object_property_range_axioms(pe: 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.

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.

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.

save(path: str | owlapy.iri.IRI = None, inplace: bool = False, rdf_format='rdfxml')[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.

get_original_iri()[source]

Get the IRI argument that was used to create this ontology.

__eq__(other)[source]
__hash__()[source]
__repr__()[source]
class owlapy.owl_ontology.SyncOntology(manager: _SM, path: owlapy.iri.IRI | str, new: bool = False)[source]

Bases: owlapy.abstracts.abstract_owl_ontology.AbstractOWLOntology

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.

manager
path
new = False
mapper
__eq__(other)[source]
__hash__()[source]
__repr__()[source]
__len__()[source]
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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

get_signature(include_imports_closure: bool = True)[source]

Gets the entities that are in the signature of this ontology.

Parameters:

include_imports_closure – Whether to include/exclude imports from searches.

Returns:

Entities in signature.

get_abox_axioms(include_imports_closure: bool = True) Iterable[owlapy.owl_axiom.OWLAxiom][source]

Get all ABox axioms.

Parameters:

include_imports_closure – Whether to include/exclude imports from searches.

Returns:

ABox axioms.

get_tbox_axioms(include_imports_closure: bool = True) Iterable[owlapy.owl_axiom.OWLAxiom][source]

Get all TBox axioms.

Parameters:

include_imports_closure – Whether to include/exclude imports from searches.

Returns:

TBox axioms.

get_owl_ontology_manager() _M[source]

Gets the manager that manages this ontology.

get_owlapi_ontology()[source]
get_ontology_id() OWLOntologyID[source]

Gets the OWLOntologyID belonging to this object.

Returns:

The OWLOntologyID.

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.

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.

save(path: str = None, document_iri: owlapy.iri.IRI | None = None)[source]
https://github.com/phillord/owl-api/blob/b2a5bfb9a0c6730c8ff950776af8f9bf19c78eac/

contract/src/test/java/org/coode/owlapi/examples/Examples.java#L206

class owlapy.owl_ontology.RDFLibOntology(path: str)[source]

Bases: owlapy.abstracts.abstract_owl_ontology.AbstractOWLOntology

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.

rdflib_graph
str_owl_classes
str_owl_individuals
__len__() int[source]
get_tbox_axioms() Iterable[owlapy.owl_axiom.OWLSubClassOfAxiom | owlapy.owl_axiom.OWLEquivalentClassesAxiom][source]
get_abox_axioms() Iterable[source]
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 properties_in_signature() Iterable[owlapy.owl_property.OWLProperty][source]
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 get_abox_axioms_between_individuals() Iterable[source]
abstract get_abox_axioms_between_individuals_and_classes() Iterable[source]
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(pe: 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(pe: 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(pe: 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(pe: 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 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(path: str | owlapy.iri.IRI = None, inplace: bool = False, rdf_format='rdfxml')[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.

abstract get_ontology_id()[source]

Gets the OWLOntologyID belonging to this object.

Returns:

The OWLOntologyID.

abstract get_owl_ontology_manager()[source]

Gets the manager that manages this ontology.

abstract __eq__(other)[source]
abstract __hash__()[source]
abstract __repr__()[source]
owlapy.owl_ontology.OWLREADY2_FACET_KEYS
class owlapy.owl_ontology.ToOwlready2(world: owlready2.World)[source]
__slots__ = '_world'
abstract map_object(o: owlapy.owl_object.OWLObject)[source]

Map owlapy object classes.

abstract map_concept(o: owlapy.class_expression.OWLClassExpression) owlready2.ClassConstruct | owlready2.ThingClass[source]

Map owlapy concept classes.

abstract map_datarange(p: owlapy.owl_data_ranges.OWLDataRange) owlready2.ClassConstruct | type[source]

Map owlapy data range classes.

class owlapy.owl_ontology.FromOwlready2[source]

Map owlready2 classes to owlapy model classes.

__slots__ = ()
abstract map_concept(c: owlready2.ClassConstruct | owlready2.ThingClass) owlapy.class_expression.OWLClassExpression[source]

Map concept classes.

abstract map_datarange(p: owlready2.ClassConstruct) owlapy.owl_data_ranges.OWLDataRange[source]

Map data range classes.