pwin / owlready2

GNU Lesser General Public License v3.0
132 stars 22 forks source link

`.min` does not return expected values for cardinality >1 #35

Open liamhuber opened 1 year ago

liamhuber commented 1 year ago

I'm trying to use the min method to count the number of properties (of a particular type) on an object, but I find that counting fails silently for all cardinalities >1. ("silently" = gives unexpected results with no python or java error).

Example:

import owlready2 as owl

for n in [1, 2, 3]:
    onto = owl.get_ontology(f"file://mwe{n}.owl")

    with onto:
        class MyThing(owl.Thing): pass
        class MyProperty(owl.Thing): pass

        class has_for_property(MyThing >> MyProperty):
            class_property_type = "some"
            python_name = "properties"

        class HasAtLeastNProperties(MyThing):
            defined_class = True
            equivalent_to = [MyThing & has_for_property.min(n, MyProperty)]

    has_none = MyThing("none", properties=[])
    has_one = MyThing("one", properties=[MyProperty()])
    has_two = MyThing("two", properties=[MyProperty(), MyProperty()])
    has_three = MyThing("three", properties=[MyProperty(), MyProperty(), MyProperty()])

    owl.close_world(onto.MyThing)
    owl.sync_reasoner_pellet(
        infer_property_values=True, infer_data_property_values=True, debug=0
    )

    print(f"THING, HAS AT LEAST {n} PROPERTIES")
    for thing in [has_none, has_one, has_two, has_three]:
        print('\t', thing.name, HasAtLeastNProperties in thing.INDIRECT_is_a)

Actual output:

THING, HAS AT LEAST 1 PROPERTIES
     none False
     one True
     two True
     three True
THING, HAS AT LEAST 2 PROPERTIES
     none False
     one False
     two False
     three False
THING, HAS AT LEAST 3 PROPERTIES
     none False
     one False
     two False
     three False

Expected output:

THING, HAS AT LEAST 1 PROPERTIES
     none False
     one True
     two True
     three True
THING, HAS AT LEAST 2 PROPERTIES
     none False
     one False
     two True
     three True
THING, HAS AT LEAST 3 PROPERTIES
     none False
     one False
     two False
     three True