Skip to content

Commit

Permalink
added property iri and str, removed get_iri()
Browse files Browse the repository at this point in the history
  • Loading branch information
alkidbaci committed Apr 17, 2024
1 parent e6ad4b9 commit ca99232
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 55 deletions.
6 changes: 3 additions & 3 deletions owlapy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .render import owl_expression_to_dl, owl_expression_to_manchester
from .parser import dl_to_owl_expression, manchester_to_owl_expression
from .converter import owl_expression_to_sparql
# from .render import owl_expression_to_dl, owl_expression_to_manchester
# from .parser import dl_to_owl_expression, manchester_to_owl_expression
# from .converter import owl_expression_to_sparql
__version__ = '0.1.3'
4 changes: 2 additions & 2 deletions owlapy/class_expression/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
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
OWLThing: Final = OWLClass(OWLRDFVocabulary.OWL_THING.iri) #: : :The OWL Class corresponding to owl:Thing
OWLNothing: Final = OWLClass(OWLRDFVocabulary.OWL_NOTHING.iri) #: : :The OWL Class corresponding to owl:Nothing
19 changes: 11 additions & 8 deletions owlapy/class_expression/owl_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ def __init__(self, iri: Union[IRI, str]):
self._is_nothing = self._iri.is_nothing()
self._is_thing = self._iri.is_thing()

def get_iri(self) -> 'IRI':
@property
def iri(self) -> 'IRI':
# documented in parent
return self._iri

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

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

def is_owl_thing(self) -> bool:
# documented in parent
return self._is_thing
Expand All @@ -49,11 +59,4 @@ 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()
4 changes: 2 additions & 2 deletions owlapy/iri.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def is_nothing(self):
:True if this IRI is equal to <http://www.w3.org/2002/07/owl#Nothing> and otherwise False.
"""
from owlapy.vocab import OWLRDFVocabulary
return self == OWLRDFVocabulary.OWL_NOTHING.get_iri()
return self == OWLRDFVocabulary.OWL_NOTHING.iri

def is_thing(self):
"""Determines if this IRI is equal to the IRI that owl:Thing is named with.
Expand All @@ -115,7 +115,7 @@ def is_thing(self):
:True if this IRI is equal to <http://www.w3.org/2002/07/owl#Thing> and otherwise False.
"""
from owlapy.vocab import OWLRDFVocabulary
return self == OWLRDFVocabulary.OWL_THING.get_iri()
return self == OWLRDFVocabulary.OWL_THING.iri

def is_reserved_vocabulary(self) -> bool:
"""Determines if this IRI is in the reserved vocabulary. An IRI is in the reserved vocabulary if it starts with
Expand Down
13 changes: 12 additions & 1 deletion owlapy/meta_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@ class HasIRI(metaclass=ABCMeta):
"""Simple class to access the IRI."""
__slots__ = ()

@property
@abstractmethod
def get_iri(self) -> 'IRI':
def iri(self) -> 'IRI':
"""Gets the IRI of this object.
Returns:
The IRI of this object.
"""
pass

@property
@abstractmethod
def str(self) -> str:
"""Gets the string representation of this object
Returns:
The IRI as string
"""
pass


class HasOperands(Generic[_T], metaclass=ABCMeta):
"""An interface to objects that have a collection of operands.
Expand Down
17 changes: 12 additions & 5 deletions owlapy/owl_axiom.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""OWL Axioms"""
from abc import ABCMeta, abstractmethod

from typing import TypeVar, List, Optional, Iterable, Generic, Final
from typing import TypeVar, List, Optional, Iterable, Generic, Final, Union
from .owl_property import OWLDataPropertyExpression, OWLObjectPropertyExpression
from .owl_object import OWLObject, OWLEntity
from .owl_datatype import OWLDatatype, OWLDataRange
Expand Down Expand Up @@ -635,18 +635,25 @@ class OWLAnnotationProperty(OWLProperty):

_iri: IRI

def __init__(self, iri: IRI):
def __init__(self, iri: Union[IRI, str]):
"""Get a new OWLAnnotationProperty object.
Args:
iri: New OWLAnnotationProperty IRI.
"""
self._iri = iri
if isinstance(iri, IRI):
self._iri = iri
else:
self._iri = IRI.create(iri)

def get_iri(self) -> IRI:
# documented in parent
@property
def iri(self) -> IRI:
return self._iri

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


class OWLAnnotation(OWLObject):
"""Annotations are used in the various types of annotation axioms, which bind annotations to their subjects
Expand Down
10 changes: 7 additions & 3 deletions owlapy/owl_datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ def __init__(self, iri: Union[IRI, HasIRI]):
iri: The IRI.
"""
if isinstance(iri, HasIRI):
self._iri = iri.get_iri()
self._iri = iri.iri
else:
assert isinstance(iri, IRI)
self._iri = iri

def get_iri(self) -> IRI:
# documented in parent
@property
def iri(self) -> IRI:
return self._iri

@property
def str(self) -> str:
return self._iri.as_str()
7 changes: 1 addition & 6 deletions owlapy/owl_individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ def __init__(self, iri: Union[IRI, str]):
else:
self._iri = IRI.create(iri)

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

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

@property
Expand Down
8 changes: 4 additions & 4 deletions owlapy/owl_literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,13 @@ def __repr__(self):


#: the built in top object property
OWLTopObjectProperty: Final = OWLObjectProperty(OWLRDFVocabulary.OWL_TOP_OBJECT_PROPERTY.get_iri())
OWLTopObjectProperty: Final = OWLObjectProperty(OWLRDFVocabulary.OWL_TOP_OBJECT_PROPERTY.iri)
#: the built in bottom object property
OWLBottomObjectProperty: Final = OWLObjectProperty(OWLRDFVocabulary.OWL_BOTTOM_OBJECT_PROPERTY.get_iri())
OWLBottomObjectProperty: Final = OWLObjectProperty(OWLRDFVocabulary.OWL_BOTTOM_OBJECT_PROPERTY.iri)
#: the built in top data property
OWLTopDataProperty: Final = OWLDataProperty(OWLRDFVocabulary.OWL_TOP_DATA_PROPERTY.get_iri())
OWLTopDataProperty: Final = OWLDataProperty(OWLRDFVocabulary.OWL_TOP_DATA_PROPERTY.iri)
#: the built in bottom data property
OWLBottomDataProperty: Final = OWLDataProperty(OWLRDFVocabulary.OWL_BOTTOM_DATA_PROPERTY.get_iri())
OWLBottomDataProperty: Final = OWLDataProperty(OWLRDFVocabulary.OWL_BOTTOM_DATA_PROPERTY.iri)

DoubleOWLDatatype: Final = OWLDatatype(XSDVocabulary.DOUBLE) #: An object representing a double datatype.
IntegerOWLDatatype: Final = OWLDatatype(XSDVocabulary.INTEGER) #: An object representing an integer datatype.
Expand Down
2 changes: 1 addition & 1 deletion owlapy/owl_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class OWLEntity(OWLNamedObject, metaclass=ABCMeta):
__slots__ = ()

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

def is_anonymous(self) -> bool:
return False
Expand Down
7 changes: 6 additions & 1 deletion owlapy/owl_ontology_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def __init__(self, import_iri: IRI):
"""
self._iri = import_iri

def get_iri(self) -> IRI:
@property
def iri(self) -> IRI:
"""Gets the import IRI.
Returns:
Expand All @@ -130,6 +131,10 @@ def get_iri(self) -> IRI:
"""
return self._iri

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


class AddImport(OWLOntologyChange):
"""Represents an ontology change where an import statement is added to an ontology."""
Expand Down
17 changes: 8 additions & 9 deletions owlapy/owl_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,9 @@ def str(self) -> str:
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()
return self.str == "http://www.w3.org/2002/07/owl#topObjectProperty"


class OWLObjectInverseOf(OWLObjectPropertyExpression):
Expand Down Expand Up @@ -200,10 +195,14 @@ def __init__(self, iri: 'IRI'):
"""
self._iri = iri

def get_iri(self) -> 'IRI':
# documented in parent
@property
def iri(self) -> IRI:
return self._iri

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

def is_owl_top_data_property(self) -> bool:
# documented in parent
return self.get_iri() == OWLRDFVocabulary.OWL_TOP_DATA_PROPERTY.get_iri()
return self.str == "http://www.w3.org/2002/07/owl#topDataProperty"
10 changes: 5 additions & 5 deletions owlapy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ def visit_abbreviated_iri(self, node, children):
def visit_simple_iri(self, node, children) -> IRI:
simple_iri = _node_text(node)
if simple_iri == "Thing":
return OWLRDFVocabulary.OWL_THING.get_iri()
return OWLRDFVocabulary.OWL_THING.iri
elif simple_iri == "Nothing":
return OWLRDFVocabulary.OWL_NOTHING.get_iri()
return OWLRDFVocabulary.OWL_NOTHING.iri
elif self.ns is not None:
return IRI(self.ns, simple_iri)
else:
Expand Down Expand Up @@ -726,9 +726,9 @@ def visit_facet(self, node, children) -> OWLFacet:
def visit_class_iri(self, node, children) -> OWLClass:
top_bottom = _node_text(node)
if top_bottom == _DL_SYNTAX.TOP:
return OWLClass(OWLRDFVocabulary.OWL_THING.get_iri())
return OWLClass(OWLRDFVocabulary.OWL_THING.iri)
elif top_bottom == _DL_SYNTAX.BOTTOM:
return OWLClass(OWLRDFVocabulary.OWL_NOTHING.get_iri())
return OWLClass(OWLRDFVocabulary.OWL_NOTHING.iri)
else:
return OWLClass(children[0])

Expand All @@ -749,7 +749,7 @@ def visit_full_iri(self, node, children) -> IRI:
iri = _node_text(node)[1:-1]
return IRI.create(iri)
except IndexError:
raise ValueError(f"{iri} is not a valid IRI.")
raise ValueError(f"{_node_text(node)[1:-1]} is not a valid IRI.")

def visit_abbreviated_iri(self, node, children):
# TODO: Add support for prefixes
Expand Down
2 changes: 1 addition & 1 deletion owlapy/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@


def _simple_short_form_provider(e: OWLEntity) -> str:
iri: IRI = e.get_iri()
iri: IRI = e.iri
sf = iri.get_short_form()
for ns in [namespaces.XSD, namespaces.OWL, namespaces.RDFS, namespaces.RDF]:
if iri.get_namespace() == ns:
Expand Down
6 changes: 3 additions & 3 deletions owlapy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ def _comparison_chain(self):
if isinstance(self.o, OWLRestriction):
c.append(OrderedOWLObject(as_index(self.o.get_property())))
if isinstance(self.o, OWLObjectInverseOf):
c.append(self.o.get_named_property().get_iri().as_str())
c.append(self.o.get_named_property().str)
if isinstance(self.o, HasFiller):
c.append(OrderedOWLObject(self.o.get_filler()))
if isinstance(self.o, HasCardinality):
c.append(self.o.get_cardinality())
if isinstance(self.o, HasOperands):
c.append(tuple(map(OrderedOWLObject, self.o.operands())))
if isinstance(self.o, HasIRI):
c.append(self.o.get_iri().as_str())
c.append(self.o.str)
if isinstance(self.o, OWLDataComplementOf):
c.append(OrderedOWLObject(self.o.get_data_range()))
if isinstance(self.o, OWLDatatypeRestriction):
c.append((OrderedOWLObject(self.o.get_datatype()),
tuple(map(OrderedOWLObject, self.o.get_facet_restrictions()))))
if isinstance(self.o, OWLFacetRestriction):
c.append((self.o.get_facet().get_iri().as_str(), self.o.get_facet_value().get_literal()))
c.append((self.o.get_facet().str, self.o.get_facet_value().get_literal()))
if isinstance(self.o, OWLLiteral):
c.append(self.o.get_literal())
if len(c) == 1:
Expand Down
7 changes: 6 additions & 1 deletion owlapy/vocab.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ def __init__(self, namespace: Namespaces, remainder: str):
self._remainder = remainder
self._iri = IRI(namespace, remainder)

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

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

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

Expand Down

0 comments on commit ca99232

Please sign in to comment.