Skip to content

Commit

Permalink
Merge branch 'adding_tests' of github.com:dice-group/owlapy into addi…
Browse files Browse the repository at this point in the history
…ng_tests
  • Loading branch information
LckyLke committed Oct 30, 2024
2 parents 5d0c904 + b80ad55 commit 09a51eb
Show file tree
Hide file tree
Showing 5 changed files with 751 additions and 711 deletions.
8 changes: 6 additions & 2 deletions owlapy/class_expression/nary_boolean_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ def __init__(self, operands: Iterable[OWLClassExpression]):
Args:
operands: Class expressions.
"""
# TODO: CD: Replace tuple with set
self._operands = tuple(operands)

assert len(self._operands)>1, "OWLNaryBooleanClassExpression requires at least one operand."

def operands(self) -> Iterable[OWLClassExpression]:
# documented in parent
yield from self._operands
Expand All @@ -26,8 +29,9 @@ def __repr__(self):

def __eq__(self, other):
if type(other) is type(self):
return self._operands == other._operands
return NotImplemented
return {i for i in self._operands} == { j for j in other.operands()}
else:
return False

def __hash__(self):
return hash(self._operands)
Expand Down
53 changes: 29 additions & 24 deletions owlapy/class_expression/restriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class OWLObjectCardinalityRestriction(OWLCardinalityRestriction[OWLClassExpressi
__slots__ = ()

_property: OWLObjectPropertyExpression

# @TODO: CD: property shows the in-built function
@abstractmethod
def __init__(self, cardinality: int, property: OWLObjectPropertyExpression, filler: OWLClassExpression):
super().__init__(cardinality, filler)
Expand All @@ -167,8 +167,8 @@ def __eq__(self, other):
return self._property == other._property \
and self._cardinality == other._cardinality \
and self._filler == other._filler
return NotImplemented

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

Expand Down Expand Up @@ -288,7 +288,7 @@ class expression CE, and it contains all those individuals that are connected by
individuals that are instances of CE. (https://www.w3.org/TR/owl2-syntax/#Universal_Quantification)"""
__slots__ = '_property', '_filler'
type_index: Final = 3006

# @TODO: CD: property shows the in-built function
def __init__(self, property: OWLObjectPropertyExpression, filler: OWLClassExpression):
super().__init__(filler)
self._property = property
Expand All @@ -299,7 +299,8 @@ def __repr__(self):
def __eq__(self, other):
if type(other) is type(self):
return self._filler == other._filler and self._property == other._property
return NotImplemented
else:
return False

def __hash__(self):
return hash((self._filler, self._property))
Expand Down Expand Up @@ -337,7 +338,8 @@ def get_property(self) -> OWLObjectPropertyExpression:
def __eq__(self, other):
if type(other) is type(self):
return self._property == other._property
return NotImplemented
else:
return False

def __hash__(self):
return hash(self._property)
Expand All @@ -357,7 +359,7 @@ class OWLObjectHasValue(OWLHasValueRestriction[OWLIndividual], OWLObjectRestrict

_property: OWLObjectPropertyExpression
_v: OWLIndividual

# @TODO: CD: property shows the in-built function
def __init__(self, property: OWLObjectPropertyExpression, individual: OWLIndividual):
"""
Args:
Expand Down Expand Up @@ -433,7 +435,8 @@ def __hash__(self):
def __eq__(self, other):
if type(other) is type(self):
return self._values == other._values
return NotImplemented
else:
return False

def __repr__(self):
return f'OWLObjectOneOf({self._values})'
Expand All @@ -452,8 +455,6 @@ def is_data_restriction(self) -> bool:
# documented in parent
return True

pass


class OWLQuantifiedDataRestriction(OWLQuantifiedRestriction[OWLDataRange],
OWLDataRestriction, metaclass=ABCMeta):
Expand All @@ -465,7 +466,7 @@ class OWLQuantifiedDataRestriction(OWLQuantifiedRestriction[OWLDataRange],
def __init__(self, filler: OWLDataRange):
assert isinstance(filler, OWLDataRange), "filler must be an OWLDataRange"
self._filler = filler

# @TODO:CD: define it as @property
def get_filler(self) -> OWLDataRange:
# documented in parent (HasFiller)
return self._filler
Expand All @@ -478,7 +479,7 @@ class OWLDataCardinalityRestriction(OWLCardinalityRestriction[OWLDataRange],
__slots__ = ()

_property: OWLDataPropertyExpression

# @TODO: CD: property shows the in-built function
@abstractmethod
def __init__(self, cardinality: int, property: OWLDataPropertyExpression, filler: OWLDataRange):
assert isinstance(filler, OWLDataRange), "filler must be an OWLDataRange"
Expand Down Expand Up @@ -513,7 +514,7 @@ class OWLDataMinCardinality(OWLDataCardinalityRestriction):
__slots__ = '_cardinality', '_filler', '_property'

type_index: Final = 3015

# @TODO: CD: property shows the in-built function
def __init__(self, cardinality: int, property: OWLDataPropertyExpression, filler: OWLDataRange):
"""
Args:
Expand All @@ -536,7 +537,7 @@ class OWLDataMaxCardinality(OWLDataCardinalityRestriction):
__slots__ = '_cardinality', '_filler', '_property'

type_index: Final = 3017

# @TODO: CD: property shows the in-built function
def __init__(self, cardinality: int, property: OWLDataPropertyExpression, filler: OWLDataRange):
"""
Args:
Expand All @@ -559,7 +560,7 @@ class OWLDataExactCardinality(OWLDataCardinalityRestriction):
__slots__ = '_cardinality', '_filler', '_property'

type_index: Final = 3016

# @TODO: CD: property shows the in-built function
def __init__(self, cardinality: int, property: OWLDataPropertyExpression, filler: OWLDataRange):
"""
Args:
Expand Down Expand Up @@ -595,7 +596,7 @@ class OWLDataSomeValuesFrom(OWLQuantifiedDataRestriction):
type_index: Final = 3012

_property: OWLDataPropertyExpression

# @TODO: CD: property shows the in-built function
def __init__(self, property: OWLDataPropertyExpression, filler: OWLDataRange):
"""Gets an OWLDataSomeValuesFrom restriction.
Expand All @@ -615,8 +616,8 @@ def __repr__(self):
def __eq__(self, other):
if type(other) is type(self):
return self._filler == other._filler and self._property == other._property
return NotImplemented

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

Expand All @@ -638,7 +639,7 @@ class OWLDataAllValuesFrom(OWLQuantifiedDataRestriction):
type_index: Final = 3013

_property: OWLDataPropertyExpression

# @TODO:CD:property shows the in-built function
def __init__(self, property: OWLDataPropertyExpression, filler: OWLDataRange):
"""Gets an OWLDataAllValuesFrom restriction.
Expand All @@ -658,7 +659,8 @@ def __repr__(self):
def __eq__(self, other):
if type(other) is type(self):
return self._filler == other._filler and self._property == other._property
return NotImplemented
else:
return False

def __hash__(self):
return hash((self._filler, self._property))
Expand All @@ -675,11 +677,13 @@ class OWLDataHasValue(OWLHasValueRestriction[OWLLiteral], OWLDataRestriction):
(https://www.w3.org/TR/owl2-syntax/#Literal_Value_Restriction)
"""
__slots__ = '_property'
# @TODO:CD:What is _v? even if it is inherited from somewhere, we should add it into docstring.
# @TODO:CD: We should also name the class attributes in a more meaningful manner.

type_index: Final = 3014

_property: OWLDataPropertyExpression

# @TODO: CD: property shows the in-built function
def __init__(self, property: OWLDataPropertyExpression, value: OWLLiteral):
"""Gets an OWLDataHasValue restriction.
Expand Down Expand Up @@ -731,7 +735,7 @@ def __init__(self, values: Union[OWLLiteral, Iterable[OWLLiteral]]):
for _ in values:
assert isinstance(_, OWLLiteral)
self._values = tuple(values)

# 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 All @@ -749,8 +753,9 @@ def __hash__(self):

def __eq__(self, other):
if type(other) is type(self):
return self._values == other._values
return NotImplemented
return {i for i in self._values} == {j for j in other._values}
else:
return False

def __repr__(self):
return f'OWLDataOneOf({self._values})'
Expand Down
Loading

0 comments on commit 09a51eb

Please sign in to comment.