Skip to content

Commit

Permalink
Reverted: __eq__ does not throw runtime error if two objects not belo…
Browse files Browse the repository at this point in the history
…ning to the same class. This is too restrictive
  • Loading branch information
Demirrr committed Nov 8, 2024
1 parent 254e164 commit f0c5592
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
57 changes: 22 additions & 35 deletions owlapy/class_expression/restriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..owl_individual import OWLIndividual
from ..owl_datatype import OWLDatatype
from ..owl_object import OWLObject
from owlapy.vocab import OWLFacet
from ..vocab import OWLFacet
from datetime import datetime, date
from pandas import Timedelta

Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(self, value: _T):
def __eq__(self, other):
if type(other) is type(self):
return self._v == other._v
return NotImplemented
return False

def __hash__(self):
return hash(self._v)
Expand Down Expand Up @@ -273,7 +273,7 @@ def __eq__(self, other):
if type(other) is type(self):
return self._filler == other._filler and self._property == other._property
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")
return False

def __hash__(self):
return hash(("OWLObjectSomeValuesFrom",self._filler, self._property))
Expand Down Expand Up @@ -301,7 +301,7 @@ def __eq__(self, other):
if type(other) is type(self):
return self._filler == other._filler and self._property == other._property
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")
return False

def __hash__(self):
return hash(("OWLObjectAllValuesFrom",self._filler, self._property))
Expand Down Expand Up @@ -340,7 +340,7 @@ def __eq__(self, other):
if type(other) is type(self):
return self._property == other._property
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")
return False


def __hash__(self):
Expand Down Expand Up @@ -430,17 +430,13 @@ def as_object_union_of(self) -> OWLClassExpression:
if len(self._values) == 1:
return self
return OWLObjectUnionOf(map(lambda _: OWLObjectOneOf(_), self.individuals()))

def __hash__(self):
return hash(("OWLObjectOneOf", self._values))

def __eq__(self, other):
if type(other) is type(self):
return self._values == other._values
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")


return False
def __repr__(self):
return f'OWLObjectOneOf({self._values})'

Expand Down Expand Up @@ -488,27 +484,22 @@ def __init__(self, cardinality: int, property: OWLDataPropertyExpression, filler
assert isinstance(filler, OWLDataRange), "filler must be an OWLDataRange"
super().__init__(cardinality, filler)
self._property = property

def get_property(self) -> OWLDataPropertyExpression:
# documented in parent
return self._property

def __hash__(self):
return hash(("OWLDataCardinalityRestriction",self._property, self._cardinality, self._filler))
def __repr__(self):
return f"{type(self).__name__}(" \
f"property={repr(self.get_property())},{self.get_cardinality()},filler={repr(self.get_filler())})"

def __eq__(self, other):
if type(other) is type(self):
return self._property == other._property \
and self._cardinality == other._cardinality \
and self._filler == other._filler
return (self._property == other._property and self._cardinality == other._cardinality
and self._filler == other._filler)
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")


def __hash__(self):
return hash(("OWLDataCardinalityRestriction",self._property, self._cardinality, self._filler))
return False

def get_property(self) -> OWLDataPropertyExpression:
# documented in parent
return self._property

class OWLDataMinCardinality(OWLDataCardinalityRestriction):
"""A minimum cardinality expression DataMinCardinality( n DPE DR ) consists of a nonnegative integer n, a data
Expand Down Expand Up @@ -622,8 +613,7 @@ def __eq__(self, other):
if type(other) is type(self):
return self._filler == other._filler and self._property == other._property
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")

return False
def __hash__(self):
return hash(("OWLDataSomeValuesFrom",self._filler, self._property))

Expand Down Expand Up @@ -666,8 +656,7 @@ def __eq__(self, other):
if type(other) is type(self):
return self._filler == other._filler and self._property == other._property
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")

return False
def __hash__(self):
return hash(("OWLDataAllValuesFrom",self._filler, self._property))

Expand Down Expand Up @@ -709,8 +698,8 @@ def __repr__(self):
def __eq__(self, other):
if type(other) is type(self):
return self._v == other._v and self._property == other._property
return NotImplemented

else:
return False
def __hash__(self):
return hash(("OWLDataHasValue",self._v, self._property))

Expand Down Expand Up @@ -751,8 +740,7 @@ def __eq__(self, other):
if type(other) is type(self):
return {i for i in self._values} == {j for j in other._values}
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")

return False
# TODO:CD: define it as @property as the name of the class method does not correspond to an action
def values(self) -> Iterable[OWLLiteral]:
"""Gets the values that are in the oneOf.
Expand Down Expand Up @@ -798,8 +786,8 @@ def __eq__(self, other):
if type(other) is type(self):
return self._type == other._type \
and self._facet_restrictions == other._facet_restrictions
return NotImplemented

else:
return False
def __hash__(self):
return hash((self._type, self._facet_restrictions))

Expand Down Expand Up @@ -834,8 +822,7 @@ def __eq__(self, other):
if type(other) is type(self):
return self._facet == other._facet and self._literal == other._literal
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")

return False

def __hash__(self):
return hash(("OWLFacetRestriction",self._facet, self._literal))
Expand Down
3 changes: 2 additions & 1 deletion owlapy/owl_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def __eq__(self, other):
if type(other) is type(self):
return self._iri == other._iri
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")
return False
# raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")

def __lt__(self, other):
if type(other) is type(self):
Expand Down

0 comments on commit f0c5592

Please sign in to comment.