-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from dice-group/base_changes
Refactoring and some changes to the base structure
- Loading branch information
Showing
14 changed files
with
762 additions
and
712 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .abstract_owl_ontology_manager import OWLOntologyManager, OWLOntologyChange, OWLOntology | ||
from .abstract_owl_reasoner import OWLReasoner, OWLReasonerEx | ||
|
||
__all__ = ['OWLOntologyManager', 'OWLOntologyChange', 'OWLOntology', 'OWLReasoner', 'OWLReasonerEx'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
from abc import ABCMeta, abstractmethod | ||
from typing import Final, Iterable, Union, Optional, TypeVar | ||
|
||
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_property import OWLDataProperty, OWLObjectProperty | ||
|
||
_M = TypeVar('_M', bound='OWLOntologyManager') # noqa: F821 | ||
_OI = TypeVar('_OI', bound='OWLOntologyID') # noqa: F821 | ||
|
||
|
||
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) -> _OI: | ||
"""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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.