Skip to content

Commit

Permalink
Merge pull request #64 from dice-group/base_changes
Browse files Browse the repository at this point in the history
Refactoring and some changes to the base structure
  • Loading branch information
alkidbaci authored Sep 10, 2024
2 parents d0abb5d + 612beb9 commit 007563b
Show file tree
Hide file tree
Showing 14 changed files with 762 additions and 712 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OWLAPY
[![Coverage](https://img.shields.io/badge/coverage-78%25-green)](https://dice-group.github.io/owlapy/usage/further_resources.html#coverage-report)
[![Pypi](https://img.shields.io/badge/pypi-1.2.0-blue)](https://pypi.org/project/owlapy/1.2.0/)
[![Docs](https://img.shields.io/badge/documentation-1.2.0-yellow)](https://dice-group.github.io/owlapy/usage/main.html)
[![Pypi](https://img.shields.io/badge/pypi-1.2.2-blue)](https://pypi.org/project/owlapy/1.2.2/)
[![Docs](https://img.shields.io/badge/documentation-1.2.2-yellow)](https://dice-group.github.io/owlapy/usage/main.html)

![OWLAPY](docs/_static/images/owlapy_logo.png)

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

project = 'OWLAPY'
author = 'Ontolearn Team'
release = '1.2.0'
release = '1.2.2'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/main.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# About owlapy

**Version:** owlapy 1.2.0
**Version:** owlapy 1.2.2

**GitHub repository:** [https://github.com/dice-group/owlapy](https://github.com/dice-group/owlapy)

Expand Down
2 changes: 1 addition & 1 deletion owlapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from .parser import (dl_to_owl_expression as dl_to_owl_expression,
manchester_to_owl_expression as manchester_to_owl_expression)
from .converter import owl_expression_to_sparql as owl_expression_to_sparql
__version__ = '1.2.1'
__version__ = '1.2.2'
4 changes: 4 additions & 0 deletions owlapy/abstracts/__init__.py
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']
185 changes: 185 additions & 0 deletions owlapy/abstracts/abstract_owl_ontology.py
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
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
Loading

0 comments on commit 007563b

Please sign in to comment.