Skip to content

Commit

Permalink
Merge pull request #14 from dice-group/iri_owl
Browse files Browse the repository at this point in the history
Iri owl
  • Loading branch information
Demirrr authored Apr 2, 2024
2 parents 512e489 + f40732f commit 459d337
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
73 changes: 43 additions & 30 deletions owlapy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,11 @@ def str(self):
return self.get_iri().as_str()

@property
def reminder(self)->str:
def reminder(self) -> str:
"""The reminder of the IRI """
return self.get_iri().get_remainder()


class OWLPropertyExpression(OWLObject, metaclass=ABCMeta):
"""Represents a property or possibly the inverse of a property."""
__slots__ = ()
Expand Down Expand Up @@ -382,36 +383,44 @@ class OWLObjectProperty(OWLObjectPropertyExpression, OWLProperty):
__slots__ = '_iri'
type_index: Final = 1002

_iri: IRI
_iri: Union[IRI, str]

def get_named_property(self) -> 'OWLObjectProperty':
# documented in parent
return self

def __init__(self, iri: IRI):
def __init__(self, iri: Union[IRI, str]):
"""Gets an instance of OWLObjectProperty that has the specified IRI.
Args:
iri: The IRI.
"""
self._iri = iri
if isinstance(iri, IRI):
self._iri = iri
else:
self._iri = IRI.create(iri)

def get_inverse_property(self) -> 'OWLObjectInverseOf':
# documented in parent
return OWLObjectInverseOf(self)

@property
def str(self) -> str:
return self._iri.as_str()

@property
def iri(self) -> str:
return self._iri

def get_iri(self) -> IRI:
# TODO:CD: can be deprecated
# documented in parent
return self._iri

def is_owl_top_object_property(self) -> bool:
# documented in parent
return self.get_iri() == OWLRDFVocabulary.OWL_TOP_OBJECT_PROPERTY.get_iri()

@property
def str(self)->str:
return self.get_iri().as_str()


class OWLObjectInverseOf(OWLObjectPropertyExpression):
"""Represents the inverse of a property expression (ObjectInverseOf). This can be used to refer to the inverse of
Expand Down Expand Up @@ -722,8 +731,8 @@ def __repr__(self):
def __eq__(self, other):
if type(other) == type(self):
return self._property == other._property \
and self._cardinality == other._cardinality \
and self._filler == other._filler
and self._cardinality == other._cardinality \
and self._filler == other._filler
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -925,18 +934,22 @@ class OWLNamedIndividual(OWLIndividual, OWLEntity):

_iri: IRI

def __init__(self, iri: IRI):
def __init__(self, iri: Union[IRI, str]):
"""Gets an instance of OWLNamedIndividual that has the specified IRI.
Args:
iri: The IRI.
iri: an instance of IRI Class or a string representing the iri
Returns:
An OWLNamedIndividual that has the specified IRI.
"""
self._iri = iri
if isinstance(iri, IRI):
self._iri = iri
else:
self._iri = IRI.create(iri)

def get_iri(self) -> IRI:
# TODO:CD: can be deprecated
# documented in parent
return self._iri

Expand Down Expand Up @@ -1077,7 +1090,7 @@ class OWLDatatypeRestriction(OWLDataRange):
_facet_restrictions: Sequence['OWLFacetRestriction']

def __init__(self, type_: OWLDatatype, facet_restrictions: Union['OWLFacetRestriction',
Iterable['OWLFacetRestriction']]):
Iterable['OWLFacetRestriction']]):
self._type = type_
if isinstance(facet_restrictions, OWLFacetRestriction):
facet_restrictions = facet_restrictions,
Expand All @@ -1092,7 +1105,7 @@ def get_facet_restrictions(self) -> Sequence['OWLFacetRestriction']:
def __eq__(self, other):
if type(other) is type(self):
return self._type == other._type \
and self._facet_restrictions == other._facet_restrictions
and self._facet_restrictions == other._facet_restrictions
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -1656,8 +1669,8 @@ def __repr__(self):
def __eq__(self, other):
if type(other) == type(self):
return self._property == other._property \
and self._cardinality == other._cardinality \
and self._filler == other._filler
and self._cardinality == other._cardinality \
and self._filler == other._filler
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -2084,7 +2097,7 @@ def get_datarange(self) -> OWLDataRange:
def __eq__(self, other):
if type(other) is type(self):
return self._datatype == other._datatype and self._datarange == other._datarange \
and self._annotations == other._annotations
and self._annotations == other._annotations
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -2120,8 +2133,8 @@ def operands(self) -> Iterable[OWLPropertyExpression]:
def __eq__(self, other):
if type(other) is type(self):
return self._class_expression == other._class_expression \
and self._property_expressions == other._property_expressions \
and self._annotations == other._annotations
and self._property_expressions == other._property_expressions \
and self._annotations == other._annotations
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -2406,7 +2419,7 @@ def get_super_class(self) -> OWLClassExpression:
def __eq__(self, other):
if type(other) is type(self):
return self._super_class == other._super_class and self._sub_class == other._sub_class \
and self._annotations == other._annotations
and self._annotations == other._annotations
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -2445,7 +2458,7 @@ def get_owl_disjoint_classes_axiom(self) -> OWLDisjointClassesAxiom:
def __eq__(self, other):
if type(other) is type(self):
return self._cls == other._cls and self._class_expressions == other._class_expressions \
and self._annotations == other._annotations
and self._annotations == other._annotations
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -2484,7 +2497,7 @@ def get_class_expression(self) -> OWLClassExpression:
def __eq__(self, other):
if type(other) is type(self):
return self._class_expression == other._class_expression and self._individual == other._individual \
and self._annotations == other._annotations
and self._annotations == other._annotations
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -2647,7 +2660,7 @@ def get_super_property(self) -> OWLAnnotationProperty:
def __eq__(self, other):
if type(other) is type(self):
return self._sub_property == other._sub_property and self._super_property == other._super_property \
and self._annotations == other._annotations
and self._annotations == other._annotations
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -2680,7 +2693,7 @@ def get_domain(self) -> IRI:
def __eq__(self, other):
if type(other) is type(self):
return self._property == other._property and self._domain == other._domain \
and self._annotations == other._annotations
and self._annotations == other._annotations
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -2713,7 +2726,7 @@ def get_range(self) -> IRI:
def __eq__(self, other):
if type(other) is type(self):
return self._property == other._property and self._range == other._range \
and self._annotations == other._annotations
and self._annotations == other._annotations
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -2749,7 +2762,7 @@ def get_super_property(self) -> _P:
def __eq__(self, other):
if type(other) is type(self):
return self._sub_property == other._sub_property and self._super_property == other._super_property \
and self._annotations == other._annotations
and self._annotations == other._annotations
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -2815,7 +2828,7 @@ def get_object(self) -> _C:
def __eq__(self, other):
if type(other) is type(self):
return self._subject == other._subject and self._property == other._property and \
self._object == other._object and self._annotations == other._annotations
self._object == other._object and self._annotations == other._annotations
return NotImplemented

def __hash__(self):
Expand Down Expand Up @@ -3000,7 +3013,7 @@ def get_domain(self) -> OWLClassExpression:
def __eq__(self, other):
if type(other) is type(self):
return self._property == other._property and self._domain == other._domain \
and self._annotations == other._annotations
and self._annotations == other._annotations
return NotImplemented

def __hash__(self):
Expand All @@ -3027,7 +3040,7 @@ def get_range(self) -> _R:
def __eq__(self, other):
if type(other) is type(self):
return self._property == other._property and self._range == other._range \
and self._annotations == other._annotations
and self._annotations == other._annotations
return NotImplemented

def __hash__(self):
Expand Down
4 changes: 2 additions & 2 deletions owlapy/owl2sparql/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,9 @@ def as_query(self,


def owl_expression_to_sparql(root_variable: str = "?x",
ce: OWLClassExpression = None,
expression: OWLClassExpression = None,
count: bool = False,
values: Optional[Iterable[OWLNamedIndividual]] = None,
named_individuals: bool = False)->str:
"""Convert an OWL Class Expression (https://www.w3.org/TR/owl2-syntax/#Class_Expressions) into a SPARQL query"""
return converter.as_query(root_variable, ce, count, values, named_individuals)
return converter.as_query(root_variable, expression, count, values, named_individuals)

0 comments on commit 459d337

Please sign in to comment.