Error about AttributeError: 'Not' object has no attribute '_equivalent_to'

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Error about AttributeError: 'Not' object has no attribute '_equivalent_to'

sbin
Hi, I have some code that tries to add a new Class.

            pred_class.equivalent_to.append(my_restr)

my_restr is `male`, which is equivalent to Not(female)

Maybe some more information is missing from my description (trying to get a minimal example if needed)

It reaches the following error:

  File "export.py", line 25, in export_concepts
    pred_class.equivalent_to.append(my_restr)
  File "owlready2/util.py", line 77, in append
    def append(self, x):          old = list(self); super().append(x)         ; self._callback(self._obj, old)
  File "owlready2/entity.py", line 219, in _class_equivalent_to_changed
    for x2 in x.equivalent_to._indirect: x2._equivalent_to._indirect = None

Any ideas?
Reply | Threaded
Open this post in threaded view
|

Re: Error about AttributeError: 'Not' object has no attribute '_equivalent_to'

Jiba
Administrator
Hi,

I tried to reproduce your problem as follows:


onto = get_ontology('http://test.org/test.owl')

with onto:
  class Male(Thing): pass
  class Female(Thing):
    equivalent_to = [Not(Male)]

  class C(Thing): pass

  C.equivalent_to.append(Male)


However, it yields no error.

Could you adapt this small example so as it exhibits the error you get, please?

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Error about AttributeError: 'Not' object has no attribute '_equivalent_to'

sbin
Hi,

thanks for looking into it.

my colleague helped me to reproduce the issue. Please try this

    onto = owlready2.get_ontology('http://test.org/test.owl')

    with onto:
        class A(owlready2.Thing): pass
        class B(owlready2.Thing): pass
        class C(owlready2.Thing): pass

        A.equivalent_to = [owlready2.Not(B)]
        print(A.INDIRECT_equivalent_to)
        C.equivalent_to = [A]


gives this stack trace on my try

    Traceback (most recent call last):
      File "test.py", line 12, in <module>
        C.equivalent_to = [A]
      File "owlready2/entity.py", line 574, in __setattr__
        super().__setattr__(attr, value)
      File "owlready2/entity.py", line 232, in __setattr__
        type.__setattr__(Class, attr, value)
      File "owlready2/entity.py", line 188, in set_equivalent_to
        def set_equivalent_to(Class, value): Class.equivalent_to.reinit(value)
      File "owlready2/util.py", line 76, in reinit
        def reinit(self, l):          old = list(self); super().__init__(l)       ; self._callback(self._obj, old)
      File "owlready2/entity.py", line 219, in _class_equivalent_to_changed
        for x2 in x.equivalent_to._indirect: x2._equivalent_to._indirect = None
      File "owlready2/class_construct.py", line 117, in __getattr__
        return super().__getattribute__(attr)
    AttributeError: 'Not' object has no attribute '_equivalent_to'
Reply | Threaded
Open this post in threaded view
|

Re: Error about AttributeError: 'Not' object has no attribute '_equivalent_to'

Jiba
Administrator
Hi,

I've been able to reproduce the problem, and to fix it in the development version of Owlready (on Bitbucket). It will be part of the next release.

Thank you for reporting this bug,
Jiba