Inverse proeprty is not updated when in other ontology

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

Inverse proeprty is not updated when in other ontology

franzlst
When I have a individual in ontology o1 and update a property, it's inverse property is not updated, when I am in the context of another ontology o2.

Here is a short code snippet that reproduces the issue:


from owlready2 import *

o1 = get_ontology("http://test.de/o1")
o2 = get_ontology("http://test.de/o2")

with o1:  # all information defined in o1
    class A(Thing):
        pass

    class B(Thing):
        pass

    class parent(ObjectProperty, FunctionalProperty):
        domain = [A]
        range = [B]

    class child(ObjectProperty):
        domain = [A]
        range = [B]
        inverse_property = parent

    a = A()
    b = B()
    a.parent = b
    assert b.child == [a]

with o2:  # updating property in other ontology context
    a.parent = None
    assert b.child is None  # AssertionError: b.child is still set to [a]


Is this supposed to happen? It's irritating and I think this is a bug.
Reply | Threaded
Open this post in threaded view
|

Re: Inverse proeprty is not updated when in other ontology

Jiba
Administrator
Hi,

"with o2:" means that all modification to the quadstore is stored in ontology o2. Here, the removal of the parent relation is thus applied in o2. But as it is actually defined in o1, nothing is changed in the quadstore (hence the inverse relation is still present), but the value of the parent property, cached in memory, is wrongly updated.

I'm going to try to find a solution to that problem, in order to avoid having this inconsistent state... possibly the only solution is to raise an error when removing a relation from an ontology that does not contains this relation.

Also, notice that "assert b.child is None" is not a valid test here because b.child is a list. You should rather use "assert not b.child" or "assert b.child == []".

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Inverse proeprty is not updated when in other ontology

franzlst
Thank you for the explanation.

What you say makes sense, it is however not so user friendly: If I want to make updates to an individual, which includes removing previously set properties, I first have to switch to another ontology for removal of triples (if they were defined in another ontology), before I can add new triples.

What happens in the following case?

with o1:
    a.prop = [b1, b2]

with o2:
    a.prop = [b1, b3]

I guess b2 is not deleted and b3 is added in o2. I guess owlready2 is smart enough to recognizes that the relation to b1 hasn't changed and keeps it?

Is a relation always defined in the ontology where the subject is residing in?

> Also, notice that "assert b.child is None" is not a valid test here because b.child is a list. You should rather use "assert not b.child" or "assert b.child == []".

Yes, thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Inverse proeprty is not updated when in other ontology

Jiba
Administrator
Hello,

I finally changed my mind and considered that you are right. I modified Owlready development version so as RDF triple deletions are no longer ontology-specific (only triple additions are).

Consequently, your example result as "a prop b1" and "a prop b2" in the quadstore, as expected.

Please report me if you find any missing deletion operations that I may have forgotten to fix.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Inverse proeprty is not updated when in other ontology

franzlst
Thank you for adapting the code. My team and I will test the changes within the next weeks and months and will report eventual issues.