From 2c480d5af3edddc50bb2255b5cbab875ff232131 Mon Sep 17 00:00:00 2001 From: Caglar Demir Date: Tue, 9 Apr 2024 14:29:00 +0200 Subject: [PATCH 1/5] Class expression script will become a python module --- owlapy/class_expression/__init__.py | 2 + owlapy/class_expression/class_expression.py | 107 +++++++++++++ owlapy/class_expression/owl_class.py | 57 +++++++ owlapy/owl_class_expression.py | 157 +------------------- tests/test_class_expression_semantics.py | 27 ++++ 5 files changed, 195 insertions(+), 155 deletions(-) create mode 100644 owlapy/class_expression/__init__.py create mode 100644 owlapy/class_expression/class_expression.py create mode 100644 owlapy/class_expression/owl_class.py create mode 100644 tests/test_class_expression_semantics.py diff --git a/owlapy/class_expression/__init__.py b/owlapy/class_expression/__init__.py new file mode 100644 index 00000000..7bda6ec1 --- /dev/null +++ b/owlapy/class_expression/__init__.py @@ -0,0 +1,2 @@ +from .class_expression import OWLClassExpression, OWLAnonymousClassExpression, OWLBooleanClassExpression, OWLObjectComplementOf +from .owl_class import OWLClass \ No newline at end of file diff --git a/owlapy/class_expression/class_expression.py b/owlapy/class_expression/class_expression.py new file mode 100644 index 00000000..ddb8cefd --- /dev/null +++ b/owlapy/class_expression/class_expression.py @@ -0,0 +1,107 @@ +from ..ranges import OWLPropertyRange, OWLDataRange +from abc import abstractmethod, ABCMeta +from ..meta_classes import HasOperands + +from typing import Final, Iterable +class OWLClassExpression(OWLPropertyRange): + """An OWL 2 Class Expression (https://www.w3.org/TR/owl2-syntax/#Class_Expressions) """ + __slots__ = () + + @abstractmethod + def is_owl_thing(self) -> bool: + """Determines if this expression is the built in class owl:Thing. This method does not determine if the class + is equivalent to owl:Thing. + + Returns: + True if this expression is owl:Thing. + """ + pass + + @abstractmethod + def is_owl_nothing(self) -> bool: + """Determines if this expression is the built in class owl:Nothing. This method does not determine if the class + is equivalent to owl:Nothing. + """ + pass + + @abstractmethod + def get_object_complement_of(self) -> 'OWLObjectComplementOf': + """Gets the object complement of this class expression. + + Returns: + A class expression that is the complement of this class expression. + """ + pass + + @abstractmethod + def get_nnf(self) -> 'OWLClassExpression': + """Gets the negation normal form of the complement of this expression. + + Returns: + A expression that represents the NNF of the complement of this expression. + """ + pass + + +class OWLAnonymousClassExpression(OWLClassExpression, metaclass=ABCMeta): + """A Class Expression which is not a named Class.""" + + def is_owl_nothing(self) -> bool: + # documented in parent + return False + + def is_owl_thing(self) -> bool: + # documented in parent + return False + + def get_object_complement_of(self) -> 'OWLObjectComplementOf': + # documented in parent + return OWLObjectComplementOf(self) + + def get_nnf(self) -> 'OWLClassExpression': + # documented in parent + from owlapy.util import NNF + return NNF().get_class_nnf(self) + + +class OWLBooleanClassExpression(OWLAnonymousClassExpression, metaclass=ABCMeta): + """Represent an anonymous boolean class expression.""" + __slots__ = () + pass + + +class OWLObjectComplementOf(OWLBooleanClassExpression, HasOperands[OWLClassExpression]): + """Represents an ObjectComplementOf class expression in the OWL 2 Specification.""" + __slots__ = '_operand' + type_index: Final = 3003 + + _operand: OWLClassExpression + + def __init__(self, op: OWLClassExpression): + """ + Args: + op: Class expression to complement. + """ + self._operand = op + + def get_operand(self) -> OWLClassExpression: + """ + Returns: + The wrapped expression. + """ + return self._operand + + def operands(self) -> Iterable[OWLClassExpression]: + # documented in parent + yield self._operand + + def __repr__(self): + return f"OWLObjectComplementOf({repr(self._operand)})" + + def __eq__(self, other): + if type(other) is type(self): + return self._operand == other._operand + return NotImplemented + + def __hash__(self): + return hash(self._operand) diff --git a/owlapy/class_expression/owl_class.py b/owlapy/class_expression/owl_class.py new file mode 100644 index 00000000..208f585d --- /dev/null +++ b/owlapy/class_expression/owl_class.py @@ -0,0 +1,57 @@ +from .class_expression import OWLClassExpression, OWLObjectComplementOf +from ..owlobject import OWLObject, OWLEntity +from typing import Final, Union +from ..iri import IRI + + +class OWLClass(OWLClassExpression, OWLEntity): + """An OWL 2 named Class""" + __slots__ = '_iri', '_is_nothing', '_is_thing' + type_index: Final = 1001 + + _iri: 'IRI' + _is_nothing: bool + _is_thing: bool + + def __init__(self, iri: Union[IRI, str]): + """Gets an instance of OWLClass that has the specified IRI. + + Args: + iri: + """ + if isinstance(iri, IRI): + self._iri = iri + else: + self._iri = IRI.create(iri) + + self._is_nothing = self._iri.is_nothing() + self._is_thing = self._iri.is_thing() + + def get_iri(self) -> 'IRI': + # documented in parent + return self._iri + + def is_owl_thing(self) -> bool: + # documented in parent + return self._is_thing + + def is_owl_nothing(self) -> bool: + # documented in parent + return self._is_nothing + + def get_object_complement_of(self) -> OWLObjectComplementOf: + # documented in parent + return OWLObjectComplementOf(self) + + def get_nnf(self) -> 'OWLClass': + # documented in parent + return self + + @property + def str(self): + return self.get_iri().as_str() + + @property + def reminder(self) -> str: + """The reminder of the IRI """ + return self.get_iri().get_remainder() diff --git a/owlapy/owl_class_expression.py b/owlapy/owl_class_expression.py index edb1a96d..43312395 100644 --- a/owlapy/owl_class_expression.py +++ b/owlapy/owl_class_expression.py @@ -9,162 +9,9 @@ from .iri import IRI from owlapy.vocab import OWLRDFVocabulary, XSDVocabulary +from .class_expression import (OWLClassExpression, OWLAnonymousClassExpression, OWLBooleanClassExpression, + OWLObjectComplementOf,OWLClass) -class OWLClassExpression(OWLPropertyRange): - """An OWL 2 Class Expression.""" - __slots__ = () - - @abstractmethod - def is_owl_thing(self) -> bool: - """Determines if this expression is the built in class owl:Thing. This method does not determine if the class - is equivalent to owl:Thing. - - Returns: - True if this expression is owl:Thing. - """ - pass - - @abstractmethod - def is_owl_nothing(self) -> bool: - """Determines if this expression is the built in class owl:Nothing. This method does not determine if the class - is equivalent to owl:Nothing. - """ - pass - - @abstractmethod - def get_object_complement_of(self) -> 'OWLObjectComplementOf': - """Gets the object complement of this class expression. - - Returns: - A class expression that is the complement of this class expression. - """ - pass - - @abstractmethod - def get_nnf(self) -> 'OWLClassExpression': - """Gets the negation normal form of the complement of this expression. - - Returns: - A expression that represents the NNF of the complement of this expression. - """ - pass - - -class OWLAnonymousClassExpression(OWLClassExpression, metaclass=ABCMeta): - """A Class Expression which is not a named Class.""" - - def is_owl_nothing(self) -> bool: - # documented in parent - return False - - def is_owl_thing(self) -> bool: - # documented in parent - return False - - def get_object_complement_of(self) -> 'OWLObjectComplementOf': - # documented in parent - return OWLObjectComplementOf(self) - - def get_nnf(self) -> 'OWLClassExpression': - # documented in parent - from owlapy.util import NNF - return NNF().get_class_nnf(self) - - -class OWLBooleanClassExpression(OWLAnonymousClassExpression, metaclass=ABCMeta): - """Represent an anonymous boolean class expression.""" - __slots__ = () - pass - - -class OWLObjectComplementOf(OWLBooleanClassExpression, HasOperands[OWLClassExpression]): - """Represents an ObjectComplementOf class expression in the OWL 2 Specification.""" - __slots__ = '_operand' - type_index: Final = 3003 - - _operand: OWLClassExpression - - def __init__(self, op: OWLClassExpression): - """ - Args: - op: Class expression to complement. - """ - self._operand = op - - def get_operand(self) -> OWLClassExpression: - """ - Returns: - The wrapped expression. - """ - return self._operand - - def operands(self) -> Iterable[OWLClassExpression]: - # documented in parent - yield self._operand - - def __repr__(self): - return f"OWLObjectComplementOf({repr(self._operand)})" - - def __eq__(self, other): - if type(other) is type(self): - return self._operand == other._operand - return NotImplemented - - def __hash__(self): - return hash(self._operand) - - -class OWLClass(OWLClassExpression, OWLEntity): - """An OWL 2 named Class""" - __slots__ = '_iri', '_is_nothing', '_is_thing' - type_index: Final = 1001 - - _iri: 'IRI' - _is_nothing: bool - _is_thing: bool - - def __init__(self, iri: Union[IRI,str]): - """Gets an instance of OWLClass that has the specified IRI. - - Args: - iri: - """ - if isinstance(iri, IRI): - self._iri = iri - else: - self._iri = IRI.create(iri) - - self._is_nothing = self._iri.is_nothing() - self._is_thing = self._iri.is_thing() - - def get_iri(self) -> 'IRI': - # documented in parent - return self._iri - - def is_owl_thing(self) -> bool: - # documented in parent - return self._is_thing - - def is_owl_nothing(self) -> bool: - # documented in parent - return self._is_nothing - - def get_object_complement_of(self) -> OWLObjectComplementOf: - # documented in parent - return OWLObjectComplementOf(self) - - def get_nnf(self) -> 'OWLClass': - # documented in parent - return self - - @property - def str(self): - return self.get_iri().as_str() - - @property - def reminder(self) -> str: - """The reminder of the IRI """ - return self.get_iri().get_remainder() class OWLNaryBooleanClassExpression(OWLBooleanClassExpression, HasOperands[OWLClassExpression]): """OWLNaryBooleanClassExpression.""" diff --git a/tests/test_class_expression_semantics.py b/tests/test_class_expression_semantics.py new file mode 100644 index 00000000..40dfc428 --- /dev/null +++ b/tests/test_class_expression_semantics.py @@ -0,0 +1,27 @@ +from owlapy.iri import IRI + +from owlapy.owl_class_expression import OWLClass, OWLObjectIntersectionOf, OWLObjectComplementOf, OWLObjectUnionOf +from owlapy.owl_property import OWLObjectProperty +from owlapy.owl_restriction import OWLObjectSomeValuesFrom, OWLObjectAllValuesFrom + +from owlapy.owl2sparql.converter import owl_expression_to_sparql +from owlapy.render import owl_expression_to_dl +from owlapy.owl_class_expression import OWLClassExpression + + +class TestClassExpression: + def test_iri(self): + # Create the male class + C = OWLClass("http://example.com/society#C") + assert isinstance(C, OWLClassExpression) + Not_C=OWLObjectComplementOf(C) + assert isinstance(Not_C, OWLClassExpression) + C_AND_C=OWLObjectIntersectionOf([C, C]) + assert isinstance(C_AND_C, OWLClassExpression) + C_OR_C = OWLObjectUnionOf([C, C]) + assert isinstance(C_OR_C, OWLClassExpression) + + hasChild = OWLObjectProperty("http://example.com/society#hasChild") + assert isinstance(OWLObjectSomeValuesFrom(hasChild, C), OWLClassExpression) + + assert isinstance(OWLObjectAllValuesFrom(hasChild, C), OWLClassExpression) From db48a178dac0b4ac167775680aacdb4dd9147c75 Mon Sep 17 00:00:00 2001 From: Caglar Demir Date: Tue, 9 Apr 2024 19:52:48 +0200 Subject: [PATCH 2/5] OWL CE refactoring --- owlapy/class_expression/__init__.py | 9 ++- .../nary_boolean_expression.py | 48 ++++++++++++++++ owlapy/model/__init__.py | 22 ++++---- owlapy/owl_axiom.py | 2 +- owlapy/owl_class_expression.py | 56 +------------------ owlapy/owl_restriction.py | 2 +- owlapy/render.py | 5 +- tests/test_class_expression_semantics.py | 4 +- tests/test_owlapy_render.py | 1 + 9 files changed, 77 insertions(+), 72 deletions(-) create mode 100644 owlapy/class_expression/nary_boolean_expression.py diff --git a/owlapy/class_expression/__init__.py b/owlapy/class_expression/__init__.py index 7bda6ec1..163c8cda 100644 --- a/owlapy/class_expression/__init__.py +++ b/owlapy/class_expression/__init__.py @@ -1,2 +1,9 @@ from .class_expression import OWLClassExpression, OWLAnonymousClassExpression, OWLBooleanClassExpression, OWLObjectComplementOf -from .owl_class import OWLClass \ No newline at end of file +from .owl_class import OWLClass +from .nary_boolean_expression import OWLNaryBooleanClassExpression, OWLObjectUnionOf, OWLObjectIntersectionOf + +from typing import Final +from ..vocab import OWLRDFVocabulary + +OWLThing: Final = OWLClass(OWLRDFVocabulary.OWL_THING.get_iri()) #: : :The OWL Class corresponding to owl:Thing +OWLNothing: Final = OWLClass(OWLRDFVocabulary.OWL_NOTHING.get_iri()) #: : :The OWL Class corresponding to owl:Nothing diff --git a/owlapy/class_expression/nary_boolean_expression.py b/owlapy/class_expression/nary_boolean_expression.py new file mode 100644 index 00000000..682c8bc2 --- /dev/null +++ b/owlapy/class_expression/nary_boolean_expression.py @@ -0,0 +1,48 @@ +from .class_expression import OWLClassExpression, OWLBooleanClassExpression +from ..meta_classes import HasOperands +from typing import Final, Sequence, Iterable +class OWLNaryBooleanClassExpression(OWLBooleanClassExpression, HasOperands[OWLClassExpression]): + """OWLNaryBooleanClassExpression.""" + __slots__ = () + + _operands: Sequence[OWLClassExpression] + + def __init__(self, operands: Iterable[OWLClassExpression]): + """ + Args: + operands: Class expressions. + """ + self._operands = tuple(operands) + + def operands(self) -> Iterable[OWLClassExpression]: + # documented in parent + yield from self._operands + + def __repr__(self): + return f'{type(self).__name__}({repr(self._operands)})' + + def __eq__(self, other): + if type(other) == type(self): + return self._operands == other._operands + return NotImplemented + + def __hash__(self): + return hash(self._operands) + + + + +class OWLObjectUnionOf(OWLNaryBooleanClassExpression): + """Represents an ObjectUnionOf class expression in the OWL 2 Specification.""" + __slots__ = '_operands' + type_index: Final = 3002 + + _operands: Sequence[OWLClassExpression] + + +class OWLObjectIntersectionOf(OWLNaryBooleanClassExpression): + """Represents an OWLObjectIntersectionOf class expression in the OWL 2 Specification.""" + __slots__ = '_operands' + type_index: Final = 3001 + + _operands: Sequence[OWLClassExpression] diff --git a/owlapy/model/__init__.py b/owlapy/model/__init__.py index df067856..1b6db030 100644 --- a/owlapy/model/__init__.py +++ b/owlapy/model/__init__.py @@ -9,17 +9,23 @@ from owlapy.iri import IRI from owlapy.has import HasIndex from owlapy.meta_classes import HasIRI, HasOperands, HasFiller, HasCardinality -from owlapy.owl_class_expression import OWLNaryBooleanClassExpression, OWLClassExpression, OWLObjectComplementOf, \ - OWLAnonymousClassExpression, OWLBooleanClassExpression, OWLPropertyRange, OWLDataRange, OWLClass, OWLObjectUnionOf, \ - OWLObjectIntersectionOf, OWLThing, OWLNothing +from owlapy.class_expression import OWLClassExpression, OWLNaryBooleanClassExpression, OWLObjectIntersectionOf, \ + OWLObjectUnionOf, OWLObjectComplementOf +from owlapy.class_expression import OWLThing, OWLNothing, OWLClass + +from owlapy.owl_class_expression import OWLPropertyRange, OWLDataRange + from owlapy.owl_property import OWLObjectPropertyExpression, OWLProperty, OWLPropertyExpression, \ OWLDataPropertyExpression, OWLDataProperty, OWLObjectProperty from owlapy.owl_restriction import (OWLRestriction, OWLObjectAllValuesFrom, OWLObjectSomeValuesFrom, OWLQuantifiedRestriction, OWLQuantifiedObjectRestriction, OWLObjectRestriction, OWLHasValueRestriction, OWLDataRestriction, - OWLCardinalityRestriction, OWLObjectMinCardinality, OWLObjectCardinalityRestriction,OWLDataAllValuesFrom, - OWLObjectHasSelf, OWLObjectMaxCardinality, OWLObjectExactCardinality,OWLDataExactCardinality,OWLDataMinCardinality, - OWLDataMaxCardinality,OWLDataSomeValuesFrom,OWLDataHasValue,OWLDataOneOf,OWLQuantifiedDataRestriction,OWLDataCardinalityRestriction) + OWLCardinalityRestriction, OWLObjectMinCardinality, OWLObjectCardinalityRestriction, + OWLDataAllValuesFrom, + OWLObjectHasSelf, OWLObjectMaxCardinality, OWLObjectExactCardinality, + OWLDataExactCardinality, OWLDataMinCardinality, + OWLDataMaxCardinality, OWLDataSomeValuesFrom, OWLDataHasValue, OWLDataOneOf, + OWLQuantifiedDataRestriction, OWLDataCardinalityRestriction) from owlapy.owl_individual import OWLNamedIndividual, OWLIndividual from owlapy.owl_axiom import (OWLEquivalentClassesAxiom, OWLClassAxiom, @@ -28,7 +34,6 @@ from owlapy.types import OWLDatatype from owlapy.owl_literal import OWLLiteral - MOVE(OWLObject, OWLAnnotationObject, OWLAnnotationSubject, OWLAnnotationValue, HasIRI, IRI) _T = TypeVar('_T') #: @@ -39,8 +44,6 @@ _M = TypeVar('_M', bound='OWLOntologyManager') #: - - class OWLOntologyID: """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 @@ -104,7 +107,6 @@ def __eq__(self, other): return NotImplemented - class OWLImportsDeclaration(HasIRI): """Represents an import statement in an ontology.""" __slots__ = '_iri' diff --git a/owlapy/owl_axiom.py b/owlapy/owl_axiom.py index 20fae967..22135c4a 100644 --- a/owlapy/owl_axiom.py +++ b/owlapy/owl_axiom.py @@ -6,7 +6,7 @@ from .types import OWLDatatype, OWLDataRange from .meta_classes import HasOperands from .owl_property import OWLPropertyExpression, OWLProperty -from .owl_class_expression import OWLClassExpression, OWLClass +from .class_expression import OWLClassExpression, OWLClass from .owl_individual import OWLIndividual from .iri import IRI from owlapy.owl_annotation import OWLAnnotationSubject, OWLAnnotationValue diff --git a/owlapy/owl_class_expression.py b/owlapy/owl_class_expression.py index 43312395..3cc02b4e 100644 --- a/owlapy/owl_class_expression.py +++ b/owlapy/owl_class_expression.py @@ -5,58 +5,7 @@ from .ranges import OWLPropertyRange, OWLDataRange from .owl_literal import OWLLiteral from typing import Final, Sequence, Union, Iterable -from .owl_property import OWLDataPropertyExpression, OWLObjectProperty, OWLDataProperty from .iri import IRI -from owlapy.vocab import OWLRDFVocabulary, XSDVocabulary - -from .class_expression import (OWLClassExpression, OWLAnonymousClassExpression, OWLBooleanClassExpression, - OWLObjectComplementOf,OWLClass) - - -class OWLNaryBooleanClassExpression(OWLBooleanClassExpression, HasOperands[OWLClassExpression]): - """OWLNaryBooleanClassExpression.""" - __slots__ = () - - _operands: Sequence[OWLClassExpression] - - def __init__(self, operands: Iterable[OWLClassExpression]): - """ - Args: - operands: Class expressions. - """ - self._operands = tuple(operands) - - def operands(self) -> Iterable[OWLClassExpression]: - # documented in parent - yield from self._operands - - def __repr__(self): - return f'{type(self).__name__}({repr(self._operands)})' - - def __eq__(self, other): - if type(other) == type(self): - return self._operands == other._operands - return NotImplemented - - def __hash__(self): - return hash(self._operands) - -class OWLObjectUnionOf(OWLNaryBooleanClassExpression): - """Represents an ObjectUnionOf class expression in the OWL 2 Specification.""" - __slots__ = '_operands' - type_index: Final = 3002 - - _operands: Sequence[OWLClassExpression] - - -class OWLObjectIntersectionOf(OWLNaryBooleanClassExpression): - """Represents an OWLObjectIntersectionOf class expression in the OWL 2 Specification.""" - __slots__ = '_operands' - type_index: Final = 3001 - - _operands: Sequence[OWLClassExpression] - - class OWLDataComplementOf(OWLDataRange): """Represents DataComplementOf in the OWL 2 Specification.""" type_index: Final = 4002 @@ -115,12 +64,14 @@ def __eq__(self, other): def __hash__(self): return hash(self._operands) + class OWLDataUnionOf(OWLNaryDataRange): """Represents a DataUnionOf data range in the OWL 2 Specification.""" __slots__ = '_operands' type_index: Final = 4005 _operands: Sequence[OWLDataRange] + class OWLDataIntersectionOf(OWLNaryDataRange): """Represents DataIntersectionOf in the OWL 2 Specification.""" __slots__ = '_operands' @@ -128,6 +79,3 @@ class OWLDataIntersectionOf(OWLNaryDataRange): _operands: Sequence[OWLDataRange] - -OWLThing: Final = OWLClass(OWLRDFVocabulary.OWL_THING.get_iri()) #: : :The OWL Class corresponding to owl:Thing -OWLNothing: Final = OWLClass(OWLRDFVocabulary.OWL_NOTHING.get_iri()) #: : :The OWL Class corresponding to owl:Nothing \ No newline at end of file diff --git a/owlapy/owl_restriction.py b/owlapy/owl_restriction.py index 2a664cf6..c1f8e357 100644 --- a/owlapy/owl_restriction.py +++ b/owlapy/owl_restriction.py @@ -1,7 +1,7 @@ from abc import ABCMeta, abstractmethod from .meta_classes import HasFiller, HasCardinality, HasOperands from typing import TypeVar, Generic, Final, Sequence, Union, Iterable -from .owl_class_expression import OWLAnonymousClassExpression, OWLClassExpression, OWLObjectIntersectionOf +from .class_expression import OWLAnonymousClassExpression, OWLClassExpression, OWLObjectIntersectionOf from .owl_property import OWLPropertyExpression, OWLObjectPropertyExpression, OWLDataPropertyExpression from .ranges import OWLPropertyRange, OWLDataRange from .owl_literal import OWLLiteral diff --git a/owlapy/render.py b/owlapy/render.py index 7af5aa15..2969d06f 100644 --- a/owlapy/render.py +++ b/owlapy/render.py @@ -8,11 +8,10 @@ from owlapy import namespaces from .owlobject import OWLObjectRenderer from .owl_property import OWLObjectInverseOf -from .owl_class_expression import OWLClassExpression +from .class_expression import OWLClassExpression, OWLBooleanClassExpression -# from owlapy.io import OWLObjectRenderer from owlapy.model import (OWLLiteral, OWLObject, OWLClass, OWLObjectSomeValuesFrom, \ - OWLObjectAllValuesFrom, OWLObjectUnionOf, OWLBooleanClassExpression, OWLNaryBooleanClassExpression, \ + OWLObjectAllValuesFrom, OWLObjectUnionOf, OWLNaryBooleanClassExpression, \ OWLObjectIntersectionOf, OWLObjectComplementOf, OWLRestriction, \ OWLObjectMinCardinality, OWLObjectExactCardinality, OWLObjectMaxCardinality, OWLObjectHasSelf, OWLNamedIndividual, OWLEntity, IRI, OWLPropertyExpression, OWLDataSomeValuesFrom, \ diff --git a/tests/test_class_expression_semantics.py b/tests/test_class_expression_semantics.py index 40dfc428..270d236e 100644 --- a/tests/test_class_expression_semantics.py +++ b/tests/test_class_expression_semantics.py @@ -1,12 +1,12 @@ from owlapy.iri import IRI -from owlapy.owl_class_expression import OWLClass, OWLObjectIntersectionOf, OWLObjectComplementOf, OWLObjectUnionOf +from owlapy.class_expression import OWLClass, OWLObjectComplementOf, OWLObjectUnionOf +from owlapy.class_expression import OWLBooleanClassExpression, OWLObjectIntersectionOf, OWLClassExpression from owlapy.owl_property import OWLObjectProperty from owlapy.owl_restriction import OWLObjectSomeValuesFrom, OWLObjectAllValuesFrom from owlapy.owl2sparql.converter import owl_expression_to_sparql from owlapy.render import owl_expression_to_dl -from owlapy.owl_class_expression import OWLClassExpression class TestClassExpression: diff --git a/tests/test_owlapy_render.py b/tests/test_owlapy_render.py index af06e63c..7b2c5e4b 100644 --- a/tests/test_owlapy_render.py +++ b/tests/test_owlapy_render.py @@ -5,6 +5,7 @@ IntegerOWLDatatype, OWLDataExactCardinality, OWLDataHasValue, OWLDataAllValuesFrom, \ OWLDataOneOf, OWLDataSomeValuesFrom, OWLLiteral, BooleanOWLDatatype, \ OWLDataMaxCardinality + from owlapy.owl_class_expression import OWLDataComplementOf, OWLDataIntersectionOf, OWLDataUnionOf from owlapy.model.providers import OWLDatatypeMinMaxInclusiveRestriction from owlapy.render import DLSyntaxObjectRenderer, ManchesterOWLSyntaxOWLObjectRenderer From b07f21fc5e899b2735454a9edaac0ab61e53659a Mon Sep 17 00:00:00 2001 From: Caglar Demir Date: Tue, 9 Apr 2024 20:01:04 +0200 Subject: [PATCH 3/5] owl class module created --- .../__init__.py} | 11 ++++++----- owlapy/model/__init__.py | 2 +- owlapy/parser.py | 2 +- owlapy/render.py | 3 ++- owlapy/util.py | 2 +- tests/test_owlapy_nnf.py | 2 +- tests/test_owlapy_parser.py | 2 +- tests/test_owlapy_render.py | 2 +- 8 files changed, 14 insertions(+), 12 deletions(-) rename owlapy/{owl_class_expression.py => data_ranges/__init__.py} (91%) diff --git a/owlapy/owl_class_expression.py b/owlapy/data_ranges/__init__.py similarity index 91% rename from owlapy/owl_class_expression.py rename to owlapy/data_ranges/__init__.py index 3cc02b4e..b745e0c8 100644 --- a/owlapy/owl_class_expression.py +++ b/owlapy/data_ranges/__init__.py @@ -1,11 +1,12 @@ from abc import abstractmethod, ABCMeta -from .owlobject import OWLObject, OWLEntity -from .meta_classes import HasOperands +from ..owlobject import OWLObject, OWLEntity +from ..meta_classes import HasOperands from typing import Final, Iterable, Sequence -from .ranges import OWLPropertyRange, OWLDataRange -from .owl_literal import OWLLiteral +from ..ranges import OWLPropertyRange, OWLDataRange +from ..owl_literal import OWLLiteral from typing import Final, Sequence, Union, Iterable -from .iri import IRI +from ..iri import IRI + class OWLDataComplementOf(OWLDataRange): """Represents DataComplementOf in the OWL 2 Specification.""" type_index: Final = 4002 diff --git a/owlapy/model/__init__.py b/owlapy/model/__init__.py index 1b6db030..61b76192 100644 --- a/owlapy/model/__init__.py +++ b/owlapy/model/__init__.py @@ -13,7 +13,7 @@ OWLObjectUnionOf, OWLObjectComplementOf from owlapy.class_expression import OWLThing, OWLNothing, OWLClass -from owlapy.owl_class_expression import OWLPropertyRange, OWLDataRange +from owlapy.data_ranges import OWLPropertyRange, OWLDataRange from owlapy.owl_property import OWLObjectPropertyExpression, OWLProperty, OWLPropertyExpression, \ OWLDataPropertyExpression, OWLDataProperty, OWLObjectProperty diff --git a/owlapy/parser.py b/owlapy/parser.py index 7d771dab..8978fc5e 100644 --- a/owlapy/parser.py +++ b/owlapy/parser.py @@ -19,7 +19,7 @@ OWLLiteral, OWLDataRange, OWLDataOneOf, OWLDatatype, OWLObjectCardinalityRestriction, \ OWLDataCardinalityRestriction, OWLObjectAllValuesFrom, OWLDataAllValuesFrom, BooleanOWLDatatype -from owlapy.owl_class_expression import OWLDataIntersectionOf, OWLDataUnionOf, OWLDataComplementOf +from owlapy.data_ranges import OWLDataIntersectionOf, OWLDataUnionOf, OWLDataComplementOf from owlapy.owl_restriction import OWLObjectHasValue, OWLDatatypeRestriction, OWLFacetRestriction, OWLObjectOneOf diff --git a/owlapy/render.py b/owlapy/render.py index 2969d06f..ea463229 100644 --- a/owlapy/render.py +++ b/owlapy/render.py @@ -19,7 +19,8 @@ OWLDataHasValue, OWLDataOneOf, OWLDataMaxCardinality, \ OWLDataMinCardinality, OWLDataExactCardinality) from owlapy.vocab import OWLFacet -from .owl_class_expression import OWLNaryDataRange, OWLDataComplementOf, OWLDataUnionOf, OWLDataIntersectionOf + +from .data_ranges import OWLNaryDataRange, OWLDataComplementOf, OWLDataUnionOf, OWLDataIntersectionOf from .owl_restriction import OWLObjectHasValue, OWLFacetRestriction, OWLDatatypeRestriction, OWLObjectOneOf _DL_SYNTAX = types.SimpleNamespace( diff --git a/owlapy/util.py b/owlapy/util.py index 0fad5f48..8b0b25e1 100644 --- a/owlapy/util.py +++ b/owlapy/util.py @@ -11,7 +11,7 @@ OWLDatatype,OWLDataOneOf, OWLLiteral, OWLObjectIntersectionOf, \ OWLDataCardinalityRestriction, OWLNaryBooleanClassExpression, OWLObjectUnionOf, \ OWLDataRange, OWLObject -from .owl_class_expression import OWLDataComplementOf, OWLDataUnionOf, OWLDataIntersectionOf, OWLNaryDataRange +from .data_ranges import OWLDataComplementOf, OWLDataUnionOf, OWLDataIntersectionOf, OWLNaryDataRange from .owl_restriction import OWLObjectHasValue, OWLDatatypeRestriction, OWLFacetRestriction, OWLObjectOneOf _HasIRI = TypeVar('_HasIRI', bound=HasIRI) #: diff --git a/tests/test_owlapy_nnf.py b/tests/test_owlapy_nnf.py index 94535417..3e3d0a6b 100644 --- a/tests/test_owlapy_nnf.py +++ b/tests/test_owlapy_nnf.py @@ -32,7 +32,7 @@ from owlapy.model.providers import OWLDatatypeMinMaxExclusiveRestriction from owlapy.util import NNF -from owlapy.owl_class_expression import OWLDataComplementOf, OWLDataIntersectionOf, OWLDataUnionOf +from owlapy.data_ranges import OWLDataComplementOf, OWLDataIntersectionOf, OWLDataUnionOf from owlapy.owl_restriction import OWLObjectHasValue, OWLObjectOneOf def iri(suffix): diff --git a/tests/test_owlapy_parser.py b/tests/test_owlapy_parser.py index 6abcdce8..a16e0ccd 100644 --- a/tests/test_owlapy_parser.py +++ b/tests/test_owlapy_parser.py @@ -10,7 +10,7 @@ OWLObjectHasSelf, OWLObjectIntersectionOf, OWLObjectMaxCardinality, OWLObjectProperty, OWLDataExactCardinality, OWLDataMaxCardinality, \ OWLDataMinCardinality, OWLDataHasValue, OWLThing, OWLNothing -from owlapy.owl_class_expression import OWLDataIntersectionOf, OWLDataComplementOf, OWLDataUnionOf +from owlapy.data_ranges import OWLDataIntersectionOf, OWLDataComplementOf, OWLDataUnionOf from owlapy.model.providers import OWLDatatypeMinExclusiveRestriction,\ OWLDatatypeMinMaxExclusiveRestriction, OWLDatatypeMaxExclusiveRestriction from owlapy.owl_restriction import OWLDataSomeValuesFrom, OWLDatatypeRestriction, OWLFacetRestriction, OWLObjectSomeValuesFrom, OWLObjectMinCardinality, OWLObjectHasValue,OWLObjectOneOf diff --git a/tests/test_owlapy_render.py b/tests/test_owlapy_render.py index 7b2c5e4b..6dc5f0c4 100644 --- a/tests/test_owlapy_render.py +++ b/tests/test_owlapy_render.py @@ -6,7 +6,7 @@ OWLDataOneOf, OWLDataSomeValuesFrom, OWLLiteral, BooleanOWLDatatype, \ OWLDataMaxCardinality -from owlapy.owl_class_expression import OWLDataComplementOf, OWLDataIntersectionOf, OWLDataUnionOf +from owlapy.data_ranges import OWLDataComplementOf, OWLDataIntersectionOf, OWLDataUnionOf from owlapy.model.providers import OWLDatatypeMinMaxInclusiveRestriction from owlapy.render import DLSyntaxObjectRenderer, ManchesterOWLSyntaxOWLObjectRenderer from owlapy.owl_restriction import OWLObjectHasValue, OWLObjectOneOf From 4cf4cbc452ddf696d44c874508dc49ffb2a01a2a Mon Sep 17 00:00:00 2001 From: Caglar Demir Date: Tue, 9 Apr 2024 20:08:41 +0200 Subject: [PATCH 4/5] data ranges module created --- owlapy/class_expression/class_expression.py | 2 +- owlapy/data_ranges/__init__.py | 17 +++++++++++++++-- owlapy/owl_restriction.py | 2 +- owlapy/ranges.py | 9 --------- owlapy/types.py | 2 +- 5 files changed, 18 insertions(+), 14 deletions(-) delete mode 100644 owlapy/ranges.py diff --git a/owlapy/class_expression/class_expression.py b/owlapy/class_expression/class_expression.py index ddb8cefd..50dbb4f0 100644 --- a/owlapy/class_expression/class_expression.py +++ b/owlapy/class_expression/class_expression.py @@ -1,5 +1,5 @@ -from ..ranges import OWLPropertyRange, OWLDataRange from abc import abstractmethod, ABCMeta +from ..data_ranges import OWLPropertyRange, OWLDataRange from ..meta_classes import HasOperands from typing import Final, Iterable diff --git a/owlapy/data_ranges/__init__.py b/owlapy/data_ranges/__init__.py index b745e0c8..885570b1 100644 --- a/owlapy/data_ranges/__init__.py +++ b/owlapy/data_ranges/__init__.py @@ -1,12 +1,25 @@ +"""https://www.w3.org/TR/owl2-syntax/#Data_Ranges + +DataRange := Datatype | DataIntersectionOf | DataUnionOf | DataComplementOf | DataOneOf | DatatypeRestriction +""" from abc import abstractmethod, ABCMeta from ..owlobject import OWLObject, OWLEntity from ..meta_classes import HasOperands from typing import Final, Iterable, Sequence -from ..ranges import OWLPropertyRange, OWLDataRange -from ..owl_literal import OWLLiteral +# from ..owl_literal import OWLLiteral from typing import Final, Sequence, Union, Iterable from ..iri import IRI +from abc import ABCMeta + +class OWLPropertyRange(OWLObject, metaclass=ABCMeta): + """OWL Objects that can be the ranges of properties.""" + + +class OWLDataRange(OWLPropertyRange, metaclass=ABCMeta): + """Represents a DataRange in the OWL 2 Specification.""" + + class OWLDataComplementOf(OWLDataRange): """Represents DataComplementOf in the OWL 2 Specification.""" type_index: Final = 4002 diff --git a/owlapy/owl_restriction.py b/owlapy/owl_restriction.py index c1f8e357..dbb380a3 100644 --- a/owlapy/owl_restriction.py +++ b/owlapy/owl_restriction.py @@ -3,7 +3,7 @@ from typing import TypeVar, Generic, Final, Sequence, Union, Iterable from .class_expression import OWLAnonymousClassExpression, OWLClassExpression, OWLObjectIntersectionOf from .owl_property import OWLPropertyExpression, OWLObjectPropertyExpression, OWLDataPropertyExpression -from .ranges import OWLPropertyRange, OWLDataRange +from .data_ranges import OWLPropertyRange, OWLDataRange from .owl_literal import OWLLiteral from .owl_individual import OWLIndividual from .types import OWLDatatype diff --git a/owlapy/ranges.py b/owlapy/ranges.py deleted file mode 100644 index 3464da43..00000000 --- a/owlapy/ranges.py +++ /dev/null @@ -1,9 +0,0 @@ -from abc import ABCMeta -from .owlobject import OWLObject -# @TODO: metaclass=ABCMeta inheritance may not be required since OWLObject is defined as such -class OWLPropertyRange(OWLObject, metaclass=ABCMeta): - """OWL Objects that can be the ranges of properties.""" - - -class OWLDataRange(OWLPropertyRange, metaclass=ABCMeta): - """Represents a DataRange in the OWL 2 Specification.""" diff --git a/owlapy/types.py b/owlapy/types.py index 6685e7a2..59884809 100644 --- a/owlapy/types.py +++ b/owlapy/types.py @@ -1,5 +1,5 @@ from .owlobject import OWLObject, OWLEntity -from .ranges import OWLDataRange +from .data_ranges import OWLPropertyRange, OWLDataRange from .iri import IRI from .meta_classes import HasIRI from typing import Final, Union From 76ddc99741c0c5832a2d628f3bf592139d1c990a Mon Sep 17 00:00:00 2001 From: Caglar Demir Date: Tue, 9 Apr 2024 20:19:52 +0200 Subject: [PATCH 5/5] owl entities module created --- owlapy/entities/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 owlapy/entities/__init__.py diff --git a/owlapy/entities/__init__.py b/owlapy/entities/__init__.py new file mode 100644 index 00000000..3af707be --- /dev/null +++ b/owlapy/entities/__init__.py @@ -0,0 +1,8 @@ +# https://www.w3.org/TR/owl2-syntax/#Entities.2C_Literals.2C_and_Anonymous_Individuals +""" +Entities are the fundamental building blocks of OWL 2 ontologies, and they define the vocabulary — the named terms — of an ontology. +In logic, the set of entities is usually said to constitute the signature of an ontology. + +Classes, datatypes, object properties, data properties, annotation properties, and named individuals +are entities, and they are all uniquely identified by an IR. +"""