Skip to content

Commit

Permalink
Refactoring completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Demirrr committed Apr 10, 2024
1 parent e37e171 commit 02b8548
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 26 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@ ones and finally render and print the last of them in description logics syntax.

```python
from owlapy.iri import IRI
from owlapy.owl_class_expression import OWLClass, OWLObjectIntersectionOf
from owlapy.class_expression import OWLClass, OWLObjectIntersectionOf, OWLObjectSomeValuesFrom
from owlapy.owl_property import OWLObjectProperty
from owlapy.owl_restriction import OWLObjectSomeValuesFrom

from owlapy.owl2sparql.converter import owl_expression_to_sparql
from owlapy.render import owl_expression_to_dl


# Create the male class
male = OWLClass("http://example.com/society#male")

Expand Down
35 changes: 33 additions & 2 deletions owlapy/class_expression/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
from .class_expression import OWLClassExpression, OWLAnonymousClassExpression, OWLBooleanClassExpression, OWLObjectComplementOf
"""https://www.w3.org/TR/owl2-syntax/#Class_Expressions
ClassExpression :=
owl_class.py:
Class
nary_boolean_expression.py:
ObjectIntersectionOf, ObjectUnionOf
class_expression.py: ObjectComplementOf
restriction.py:
ObjectOneOf, ObjectSomeValuesFrom, ObjectAllValuesFrom, ObjectHasValue,ObjectHasSelf,
ObjectMinCardinality, ObjectMaxCardinality, ObjectExactCardinality, DataSomeValuesFrom, DataAllValuesFrom,
DataHasValue, DataMinCardinality, DataMaxCardinality, DataExactCardinality
"""
from .class_expression import OWLClassExpression, OWLAnonymousClassExpression, OWLBooleanClassExpression, \
OWLObjectComplementOf
from .owl_class import OWLClass
from .nary_boolean_expression import OWLNaryBooleanClassExpression, OWLObjectUnionOf, OWLObjectIntersectionOf

from .restriction import (OWLRestriction, OWLQuantifiedRestriction, OWLQuantifiedObjectRestriction,
OWLObjectRestriction,
OWLHasValueRestriction, OWLDataRestriction, OWLCardinalityRestriction,
OWLObjectCardinalityRestriction, OWLObjectHasSelf,
OWLDataOneOf, OWLQuantifiedDataRestriction, OWLDataCardinalityRestriction,
OWLObjectSomeValuesFrom, OWLObjectAllValuesFrom, OWLObjectHasValue,
OWLDatatypeRestriction, OWLFacet, OWLFacetRestriction,
OWLObjectMinCardinality,
OWLObjectMaxCardinality,
OWLObjectExactCardinality,
OWLDataSomeValuesFrom,
OWLDataAllValuesFrom,
OWLDataHasValue,
OWLDataMinCardinality,
OWLDataMaxCardinality,
OWLDataExactCardinality,
OWLObjectOneOf
)
from typing import Final
from ..vocab import OWLRDFVocabulary

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from abc import ABCMeta, abstractmethod
from .meta_classes import HasFiller, HasCardinality, HasOperands
from ..meta_classes import HasFiller, HasCardinality, HasOperands
from typing import TypeVar, Generic, Final, Sequence, Union, Iterable
from .class_expression import OWLAnonymousClassExpression, OWLClassExpression, OWLObjectIntersectionOf
from .owl_property import OWLPropertyExpression, OWLObjectPropertyExpression, OWLDataPropertyExpression
from .data_ranges import OWLPropertyRange, OWLDataRange
from .owl_literal import OWLLiteral
from .owl_individual import OWLIndividual
from .types import OWLDatatype
from .owlobject import OWLObject
from .nary_boolean_expression import OWLObjectIntersectionOf
from .class_expression import OWLAnonymousClassExpression, OWLClassExpression
from ..owl_property import OWLPropertyExpression, OWLObjectPropertyExpression, OWLDataPropertyExpression
from ..data_ranges import OWLPropertyRange, OWLDataRange
from ..owl_literal import OWLLiteral
from ..owl_individual import OWLIndividual
from ..types import OWLDatatype
from ..owlobject import OWLObject
from owlapy.vocab import OWLRDFVocabulary, XSDVocabulary, OWLFacet
from datetime import datetime, date
from pandas import Timedelta
Expand Down
2 changes: 1 addition & 1 deletion owlapy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from owlapy.owl_property import OWLObjectPropertyExpression, OWLProperty, OWLPropertyExpression, \
OWLDataPropertyExpression, OWLDataProperty, OWLObjectProperty
from owlapy.owl_restriction import (OWLRestriction, OWLObjectAllValuesFrom, OWLObjectSomeValuesFrom,
from owlapy.class_expression import (OWLRestriction, OWLObjectAllValuesFrom, OWLObjectSomeValuesFrom,
OWLQuantifiedRestriction, OWLQuantifiedObjectRestriction,
OWLObjectRestriction, OWLHasValueRestriction, OWLDataRestriction,
OWLCardinalityRestriction, OWLObjectMinCardinality, OWLObjectCardinalityRestriction,
Expand Down
2 changes: 1 addition & 1 deletion owlapy/model/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Union
from datetime import datetime, date
from owlapy.owl_literal import OWLLiteral
from owlapy.owl_restriction import OWLDatatypeRestriction, OWLFacet, OWLFacetRestriction
from owlapy.class_expression import OWLDatatypeRestriction, OWLFacet, OWLFacetRestriction
from pandas import Timedelta

Restriction_Literals = Union[OWLLiteral, int, float, Timedelta, datetime, date]
Expand Down
2 changes: 1 addition & 1 deletion owlapy/owl2sparql/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
OWLNamedIndividual, OWLObjectCardinalityRestriction, OWLObjectMinCardinality, OWLObjectExactCardinality, \
OWLObjectMaxCardinality, OWLDataCardinalityRestriction, OWLDataProperty, OWLObjectHasSelf, \
OWLDataSomeValuesFrom, OWLDataAllValuesFrom, OWLDataHasValue, OWLDatatype, TopOWLDatatype, OWLDataOneOf, OWLObjectIntersectionOf
from owlapy.owl_restriction import OWLObjectHasValue, OWLObjectOneOf, OWLDatatypeRestriction
from owlapy.class_expression import OWLObjectHasValue, OWLObjectOneOf, OWLDatatypeRestriction
from owlapy.owl_literal import OWLLiteral
from owlapy.vocab import OWLFacet, OWLRDFVocabulary

Expand Down
2 changes: 1 addition & 1 deletion owlapy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
OWLDataCardinalityRestriction, OWLObjectAllValuesFrom, OWLDataAllValuesFrom, BooleanOWLDatatype

from owlapy.data_ranges import OWLDataIntersectionOf, OWLDataUnionOf, OWLDataComplementOf
from owlapy.owl_restriction import OWLObjectHasValue, OWLDatatypeRestriction, OWLFacetRestriction, OWLObjectOneOf
from owlapy.class_expression import OWLObjectHasValue, OWLDatatypeRestriction, OWLFacetRestriction, OWLObjectOneOf


MANCHESTER_GRAMMAR = Grammar(r"""
Expand Down
2 changes: 1 addition & 1 deletion owlapy/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from owlapy.vocab import OWLFacet

from .data_ranges import OWLNaryDataRange, OWLDataComplementOf, OWLDataUnionOf, OWLDataIntersectionOf
from .owl_restriction import OWLObjectHasValue, OWLFacetRestriction, OWLDatatypeRestriction, OWLObjectOneOf
from .class_expression import OWLObjectHasValue, OWLFacetRestriction, OWLDatatypeRestriction, OWLObjectOneOf

_DL_SYNTAX = types.SimpleNamespace(
SUBCLASS="⊑",
Expand Down
2 changes: 1 addition & 1 deletion owlapy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
OWLDataCardinalityRestriction, OWLNaryBooleanClassExpression, OWLObjectUnionOf, \
OWLDataRange, OWLObject
from .data_ranges import OWLDataComplementOf, OWLDataUnionOf, OWLDataIntersectionOf, OWLNaryDataRange
from .owl_restriction import OWLObjectHasValue, OWLDatatypeRestriction, OWLFacetRestriction, OWLObjectOneOf
from .class_expression import OWLObjectHasValue, OWLDatatypeRestriction, OWLFacetRestriction, OWLObjectOneOf

_HasIRI = TypeVar('_HasIRI', bound=HasIRI) #:
_HasIndex = TypeVar('_HasIndex', bound=HasIndex) #:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_class_expression_semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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.class_expression import OWLObjectSomeValuesFrom, OWLObjectAllValuesFrom

from owlapy.owl2sparql.converter import owl_expression_to_sparql
from owlapy.render import owl_expression_to_dl
Expand Down
30 changes: 30 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

from owlapy.iri import IRI
from owlapy.class_expression import OWLClass, OWLObjectIntersectionOf
from owlapy.owl_property import OWLObjectProperty
from owlapy.class_expression import OWLObjectSomeValuesFrom
from owlapy.owl2sparql.converter import owl_expression_to_sparql
from owlapy.render import owl_expression_to_dl

class TestRunningExamples:
def test_readme(self):
# Create the male class
male = OWLClass("http://example.com/society#male")

# Create an object property using the iri as a string for 'hasChild' property.
hasChild = OWLObjectProperty("http://example.com/society#hasChild")

# Create an existential restrictions
males_with_children = OWLObjectSomeValuesFrom(hasChild, male)

# Let's make it more complex by intersecting with another class
teacher = OWLClass("http://example.com/society#teacher")
male_teachers_with_children = OWLObjectIntersectionOf([males_with_children, teacher])

assert owl_expression_to_dl(male_teachers_with_children)=="(∃ hasChild.male) ⊓ teacher"
assert owl_expression_to_sparql("?x", male_teachers_with_children)=="""SELECT
DISTINCT ?x WHERE {
?x <http://example.com/society#hasChild> ?s_1 .
?s_1 a <http://example.com/society#male> .
?x a <http://example.com/society#teacher> .
}"""
2 changes: 1 addition & 1 deletion tests/test_owlapy_cnf_dnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
OWLObjectIntersectionOf, OWLObjectMinCardinality
from owlapy.model.providers import OWLDatatypeMinExclusiveRestriction
from owlapy.util import TopLevelCNF, TopLevelDNF
from owlapy.owl_restriction import OWLObjectOneOf
from owlapy.class_expression import OWLObjectOneOf

class TopLevelNFTest(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion tests/test_owlapy_nnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from owlapy.util import NNF

from owlapy.data_ranges import OWLDataComplementOf, OWLDataIntersectionOf, OWLDataUnionOf
from owlapy.owl_restriction import OWLObjectHasValue, OWLObjectOneOf
from owlapy.class_expression import OWLObjectHasValue, OWLObjectOneOf

def iri(suffix):
NS = "http://example.org/"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_owlapy_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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
from owlapy.class_expression import OWLDataSomeValuesFrom, OWLDatatypeRestriction, OWLFacetRestriction, OWLObjectSomeValuesFrom, OWLObjectMinCardinality, OWLObjectHasValue,OWLObjectOneOf

from owlapy.parser import DLSyntaxParser, ManchesterOWLSyntaxParser
from owlapy.vocab import OWLFacet
Expand Down
2 changes: 1 addition & 1 deletion tests/test_owlapy_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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 owlapy.class_expression import OWLObjectHasValue, OWLObjectOneOf

class Owlapy_DLRenderer_Test(unittest.TestCase):
def test_ce_render(self):
Expand Down

0 comments on commit 02b8548

Please sign in to comment.