Closed Demirrr closed 1 week ago
Changing this: https://github.com/dice-group/owlapy/blob/a82f76f52a76b6c100fa4e6c39a90d3a93761451/owlapy/class_expression/class_expression.py#L64-L66
To check if the provide class expression is already a complement:
def get_object_complement_of(self) -> 'OWLObjectComplementOf':
# documented in parent
if isinstance(self, OWLObjectComplementOf):
return self.get_operand()
return OWLObjectComplementOf(self)
or for more general solution, we could check this in the init of OWLObejctComplementOf? Depends on if this automatic simplification is desired, I guess...
That is by overwriting the __new__ method:
class OWLObjectComplementOf(OWLBooleanClassExpression, HasOperands[OWLClassExpression]):
"""Represents an ObjectComplementOf class expression in the OWL 2 Specification."""
__slots__ = '_operand'
type_index: Final = 3003
_operand: OWLClassExpression
def __new__(cls, op: OWLClassExpression):
"""
Creates a new instance or returns the operand if op is already a complement.
"""
if isinstance(op, OWLObjectComplementOf):
return op.get_operand()
else:
return super(OWLObjectComplementOf, cls).__new__(cls)
def __init__(self, op: OWLClassExpression):
"""
Initializes the instance with the given operand.
"""
self._operand = op
which would also simplify:
print(OWLObjectComplementOf(OWLObjectComplementOf(A)))
-> OWLClass(IRI('http://example.com/father#', 'A'))
I like your proposed solution. What do you think @alkidbaci ?
This is a great solution