Instance swapping phenomenon

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

Instance swapping phenomenon

emir
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

Jiba
Administrator
Hi,

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

Jiba

----8<---------


from owlready2 import *


onto1 = get_ontology("http://test.org/onto1.owl")
onto2 = get_ontology("http://test.org/onto2.owl")
onto3 = get_ontology("http://test.org/onto3.owl")

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

onto1.save("/tmp/onto1.owl")
onto2.save("/tmp/onto2.owl")
onto3.save("/tmp/onto3.owl")


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.imported_ontologies.append(onto2)
onto1.imported_ontologies.append(onto3)

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

sync_reasoner(w)

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]