Instance swapping phenomenon

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

Instance swapping phenomenon

I have three ontologies: main_ontology, first_ontology, second_ontology. They have classes: main_item, first_item, second_item respectively. I generate instances for first_item and second_item, and save both ontologies in separate files. After, I import first_ontology and second_ontology into main_ontology, and link main_item to the other two classes through equivalent_to and sync reasoner. Eventually, all the instances are also assigned to main_item. However, the instances of first_item are connected to second_item class and main_item class, and the other way around.
I think it might be happening because of main_item.equivalent_to = [first_item, second_item], instances get transitively assigned as individuals to the other class but why do they lose the connection to the class as instances of which they were created? is there a way to keep the initial connection as well?
Reply | Threaded
Open this post in threaded view

Re: Instance swapping phenomenon


I tried to reproduce your problem using the script below, but I was unable to. Could you help me to reproduce the problem?



from owlready2 import *

onto1 = get_ontology("")
onto2 = get_ontology("")
onto3 = get_ontology("")

with onto1:
  class C1(Thing): pass
with onto2:
  class C2(Thing): pass#equivalent_to = [C1]
with onto3:
  class C3(Thing): pass#equivalent_to = [C1]

w = World() # Use a different world to force reload the ontologies

onto1 = w.get_ontology("/tmp/onto1.owl").load()
onto2 = w.get_ontology("/tmp/onto2.owl").load()
onto3 = w.get_ontology("/tmp/onto3.owl").load()


onto1.C1.equivalent_to = [onto2.C2, onto3.C3]


print(onto2.c2, onto2.c2.is_a)
print(onto3.c3, onto3.c3.is_a)
# => onto2.c2 [onto1.C1, onto2.C2, onto3.C3]
# => onto3.c3 [onto1.C1, onto2.C2, onto3.C3]