Skip to content

Commit ea7054c

Browse files
authored
Merge pull request #207 from dice-group/bug--fixing
Bug fixing
2 parents b919377 + 9ad0917 commit ea7054c

2 files changed

Lines changed: 26 additions & 20 deletions

File tree

owlapy/converter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,9 @@ def _(self, ce: OWLDataHasValue):
553553
@process.register
554554
def _(self, node: OWLDatatype):
555555
if node != TopOWLDatatype:
556-
self.append(f" FILTER ( DATATYPE ( {self.current_variable} = <{node.to_string_id()}> ) ) ")
556+
self.append(f" FILTER ( DATATYPE ( {self.current_variable} ) = <{node.to_string_id()}> ) ")
557+
else:
558+
self.append(f" FILTER ( isLiteral ( {self.current_variable} ) ")
557559

558560
@process.register
559561
def _(self, node: OWLDataOneOf):

owlapy/utils.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -952,28 +952,32 @@ def _merge_card_r_with_same_body(self, restriction, nary_ce = None):
952952
filler=self._simplify(restriction.get_filler()))
953953

954954
def _process_cardinality_restriction(self, restriction, nary_ce = None):
955-
# Check for card restrictions that have the share the same cardinality and property.
956-
# They can be simplified into a single card restriction with a merged filler.
957-
# E.g.:
958-
# (> 1 r.A) ⊔ (> 1 r.B) ≡ > 1 r.(A ⊔ B)
959-
# (< 2 r.xsd:boolean) ⊔ (< 2 r.xsd:integer) ≡ < 2 r.(xsd:boolean ⊔ xsd:integer)
955+
# Check for card restrictions that share the same cardinality and property.
956+
# They can be simplified into a single card restriction with a merged filler,
957+
# but only for scenarios where the equivalence actually holds:
958+
#
959+
# For OWLObjectMinCardinality / OWLDataMinCardinality with cardinality = 1 in a union:
960+
# (≥ 1 r.A) ⊔ (≥ 1 r.B) ≡ ≥ 1 r.(A ⊔ B) ← valid (equivalent to ∃r)
960961
if isinstance(nary_ce, OWLObjectUnionOf):
961-
operands = set(nary_ce.operands())
962-
same_root = []
963-
for op in operands:
964-
if (isinstance(op, type(restriction))
965-
and op.get_cardinality() == restriction.get_cardinality()
966-
and op.get_property() == restriction.get_property()):
967-
same_root.append(op)
968-
if not len(same_root) == 1:
969-
fillers = _sort_by_ordered_owl_object([p.get_filler() for p in same_root])
970-
if isinstance(list(fillers)[0],OWLDataRange):
962+
# Only apply filler merging for min-cardinality restrictions with cardinality == 1
963+
if (isinstance(restriction, (OWLObjectMinCardinality, OWLDataMinCardinality))
964+
and restriction.get_cardinality() == 1):
965+
operands = set(nary_ce.operands())
966+
same_root = []
967+
for op in operands:
968+
if (isinstance(op, type(restriction))
969+
and op.get_cardinality() == restriction.get_cardinality()
970+
and op.get_property() == restriction.get_property()):
971+
same_root.append(op)
972+
if not len(same_root) == 1:
973+
fillers = _sort_by_ordered_owl_object([p.get_filler() for p in same_root])
974+
if isinstance(list(fillers)[0], OWLDataRange):
975+
return type(restriction)(cardinality=restriction.get_cardinality(),
976+
property=restriction.get_property(),
977+
filler=self._simplify(OWLDataUnionOf(fillers)))
971978
return type(restriction)(cardinality=restriction.get_cardinality(),
972979
property=restriction.get_property(),
973-
filler=self._simplify(OWLDataUnionOf(fillers)))
974-
return type(restriction)(cardinality=restriction.get_cardinality(),
975-
property=restriction.get_property(),
976-
filler=self._simplify(OWLObjectUnionOf(fillers)))
980+
filler=self._simplify(OWLObjectUnionOf(fillers)))
977981
return type(restriction)(cardinality=restriction.get_cardinality(),
978982
property=restriction.get_property(),
979983
filler=self._simplify(restriction.get_filler(), None))

0 commit comments

Comments
 (0)