pwin / owlready2

GNU Lesser General Public License v3.0
140 stars 23 forks source link

Crashing trying to get INDIRECT_get_classes_properties() of entities with Inverse relations #32

Open carolreis opened 1 year ago

carolreis commented 1 year ago

Error:

    if   r.property._class_property_some and ((r.type == VALUE) or (r.type == SOME) or ((r.type == EXACTLY) and r.cardinality >= 1) or ((r.type == MIN) and r.cardinality >= 1)):
AttributeError: 'Inverse' object has no attribute '_class_property_some'

The following code doesn't treat the case of Inverse property, which has no _class_property_some nor _class_property_only property.

def INDIRECT_get_class_properties(Class):
    l = set()
    for r in _inherited_properties_value_restrictions(Class, None, set()):
      if   r.property._class_property_some and ((r.type == VALUE) or (r.type == SOME) or ((r.type == EXACTLY) and r.cardinality >= 1) or ((r.type == MIN) and r.cardinality >= 1)):
        l.add(r.property)
      elif r.property._class_property_only and  (r.type == ONLY):
        l.add(r.property)

    for storid in Class.namespace.world._get_triples_s_p(Class.storid):
      Prop = Class.namespace.world._get_by_storid(storid)
      if not Prop is None: # None is is-a,...
        l.add(Prop)
    return l

Output of Inverse attributes (_class_property_only and _class_property_some are NOT here):

['__and__', '__class__', '__deepcopy__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__invert__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__or__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_create_triples', '_destroy_triples', '_set_ontology', '_set_ontology_copy_if_needed', 'ancestors', 'destroy', 'exactly', 'is_a', 'max', 'min', 'only', 'ontology', 'property', 'some', 'storid', 'subclasses', 'value']

Output of other property attributes (_class_property_only and _class_property_some ARE here):

['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_class_property_only', '_class_property_relation', '_class_property_some', '_class_property_type', '_domain', '_equivalent_to', '_inverse_property', '_inverse_storid', '_name', '_property_chain', '_python_name', '_range', 'get_relations', 'is_a', 'is_functional_for', 'namespace', 'storid']