Skip to content

Commit

Permalink
Moved abstract classes to 'abstracts' directory
Browse files Browse the repository at this point in the history
  • Loading branch information
alkidbaci committed Sep 9, 2024
1 parent aada550 commit 1afb0fa
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 242 deletions.
183 changes: 183 additions & 0 deletions owlapy/abstracts/abstract_owl_ontology.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
from abc import ABCMeta, abstractmethod
from typing import Final, Iterable, Union, Optional

from owlapy.class_expression import OWLClass
from owlapy.iri import IRI
from owlapy.owl_axiom import OWLEquivalentClassesAxiom, OWLClassAxiom, OWLDataPropertyDomainAxiom, \
OWLDataPropertyRangeAxiom, OWLObjectPropertyDomainAxiom, OWLObjectPropertyRangeAxiom, OWLAxiom
from owlapy.owl_individual import OWLNamedIndividual
from owlapy.owl_object import OWLObject
from owlapy.owl_ontology import _M, OWLOntologyID
from owlapy.owl_property import OWLDataProperty, OWLObjectProperty


class OWLOntology(OWLObject, metaclass=ABCMeta):
"""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

@abstractmethod
def classes_in_signature(self) -> Iterable[OWLClass]:
"""Gets the classes in the signature of this object.
Returns:
Classes in the signature of this object.
"""
pass

@abstractmethod
def data_properties_in_signature(self) -> Iterable[OWLDataProperty]:
"""Get the data properties that are in the signature of this object.
Returns:
Data properties that are in the signature of this object.
"""
pass

@abstractmethod
def object_properties_in_signature(self) -> Iterable[OWLObjectProperty]:
"""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.
"""
pass

@abstractmethod
def individuals_in_signature(self) -> Iterable[OWLNamedIndividual]:
"""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.
"""
pass

@abstractmethod
def equivalent_classes_axioms(self, c: OWLClass) -> Iterable[OWLEquivalentClassesAxiom]:
""" Gets all of the equivalent axioms in this ontology that contain the specified class as an operand.
Args:
c: The class for which the EquivalentClasses axioms should be retrieved.
Returns:
EquivalentClasses axioms contained in this ontology.
"""
pass

@abstractmethod
def general_class_axioms(self) -> Iterable[OWLClassAxiom]:
"""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.
"""
pass

@abstractmethod
def data_property_domain_axioms(self, property: OWLDataProperty) -> Iterable[OWLDataPropertyDomainAxiom]:
"""Gets the OWLDataPropertyDomainAxiom objects where the property is equal to the specified property.
Args:
property: The property which is equal to the property of the retrieved axioms.
Returns:
The axioms matching the search.
"""
pass

@abstractmethod
def data_property_range_axioms(self, property: OWLDataProperty) -> Iterable[OWLDataPropertyRangeAxiom]:
"""Gets the OWLDataPropertyRangeAxiom objects where the property is equal to the specified property.
Args:
property: The property which is equal to the property of the retrieved axioms.
Returns:
The axioms matching the search.
"""
pass

@abstractmethod
def object_property_domain_axioms(self, property: OWLObjectProperty) -> Iterable[OWLObjectPropertyDomainAxiom]:
"""Gets the OWLObjectPropertyDomainAxiom objects where the property is equal to the specified property.
Args:
property: The property which is equal to the property of the retrieved axioms.
Returns:
The axioms matching the search.
"""
pass

@abstractmethod
def object_property_range_axioms(self, property: OWLObjectProperty) -> Iterable[OWLObjectPropertyRangeAxiom]:
"""Gets the OWLObjectPropertyRangeAxiom objects where the property is equal to the specified property.
Args:
property: The property which is equal to the property of the retrieved axioms.
Returns:
The axioms matching the search.
"""
pass

@abstractmethod
def get_owl_ontology_manager(self) -> _M:
"""Gets the manager that manages this ontology."""
pass

@abstractmethod
def get_ontology_id(self) -> OWLOntologyID:
"""Gets the OWLOntologyID belonging to this object.
Returns:
The OWLOntologyID.
"""
pass

def is_anonymous(self) -> bool:
"""Check whether this ontology does contain an IRI or not."""
return self.get_ontology_id().is_anonymous()

@abstractmethod
def add_axiom(self, axiom: Union[OWLAxiom, Iterable[OWLAxiom]]):
"""Add the specified axiom/axioms to the ontology.
Args:
axiom: Can be a single axiom or a collection of axioms.
Returns:
Nothing.
"""
pass

@abstractmethod
def remove_axiom(self, axiom: Union[OWLAxiom, Iterable[OWLAxiom]]):
"""Removes the specified axiom/axioms to the ontology.
Args:
axiom: Can be a single axiom or a collection of axioms.
Returns:
Nothing.
"""
pass

def save(self, document_iri: Optional[IRI] = None):
"""Saves this ontology, using its IRI to determine where/how the ontology should be
saved.
Args:
document_iri: Whether you want to save in a different location.
"""
pass
70 changes: 70 additions & 0 deletions owlapy/abstracts/abstract_owl_ontology_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from abc import ABCMeta, abstractmethod
from typing import Union

from owlapy.abstracts.abstract_owl_ontology import OWLOntology
from owlapy.iri import IRI


class OWLOntologyChange(metaclass=ABCMeta):
"""Represents an ontology change."""
__slots__ = ()

_ont: OWLOntology

@abstractmethod
def __init__(self, ontology: OWLOntology):
self._ont = ontology

def get_ontology(self) -> OWLOntology:
"""Gets the ontology that the change is/was applied to.
Returns:
The ontology that the change is applicable to.
"""
return self._ont


class OWLOntologyManager(metaclass=ABCMeta):
"""An OWLOntologyManager manages a set of ontologies. It is the main point for creating, loading and accessing
ontologies."""

@abstractmethod
def create_ontology(self, iri: Union[str, IRI]) -> OWLOntology:
"""Creates a new (empty) ontology that that has the specified ontology IRI (and no version IRI).
Args:
iri: The IRI of the ontology to be created, can also be a string.
Returns:
The newly created ontology.
"""
pass

@abstractmethod
def load_ontology(self, iri: Union[IRI, str]) -> OWLOntology:
"""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.
Args:
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.
"""
pass

@abstractmethod
def apply_change(self, change: OWLOntologyChange):
"""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.
Args:
change: The change to be applied.
Raises:
ChangeApplied.UNSUCCESSFULLY: if the change was not applied successfully.
"""
pass
2 changes: 1 addition & 1 deletion owlapy/abstracts/abstract_owl_reasoner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from owlapy.class_expression import OWLClass
from owlapy.owl_data_ranges import OWLDataRange
from owlapy.owl_object import OWLEntity
from owlapy.owl_ontology import OWLOntology
from owlapy.abstracts.abstract_owl_ontology import OWLOntology
from owlapy.owl_property import OWLObjectPropertyExpression, OWLDataProperty, OWLObjectProperty
from owlapy.owl_individual import OWLNamedIndividual
from owlapy.owl_literal import OWLLiteral
Expand Down
Loading

0 comments on commit 1afb0fa

Please sign in to comment.