Following is the code. The result is not want I expect. Thing is not in i.is_instance_of, even when I added it into the list (It was reparented!). As syllogism, i is an instance of Person, Person is a Thing, then i is an instance of Thing. I tried to use INDIRECT_is_instance_of, but it dose not have such property. I think there should be a native method that is equivalent to ∈ in set theory (and ⊆).
import pathlib
from owlready2 import *
PATH = pathlib.Path("kb")
onto_path.append(PATH)
test = get_ontology("
http://test.org/test.owl")
with test:
class Person(Thing):
pass
class Teacher(Person):
pass
i = Person('i')
n = Teacher('n')
i.is_instance_of=i.is_instance_of+[Thing]
print(i.is_instance_of)
#close_world(test) # close or not close
sync_reasoner(debug=0)
print(i.is_instance_of)
print(Thing in i.is_instance_of)
print(Person in i.is_instance_of)
print(Teacher in n.is_instance_of)
print(Person in n.is_instance_of)
print(Thing in n.is_instance_of)
==>
[test.Person]
False
True
True
False
False