@@ -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