about is_a and is_instance_of

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

about is_a and is_instance_of

William
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
Reply | Threaded
Open this post in threaded view
|

Re: about is_a and is_instance_of

Jiba
Administrator
Hi,

is_instance_of includes only direct assertions. Currently, you can check if an individual is an instance of a class with isinstance, e.g. isinstance(i, Person) or isinstance(i, Thing).

INDIRECT_is_instance_of is not implemented currently, but it's a good idea. I'm adding it in the development version (expect a new release soon).

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: about is_a and is_instance_of

Brownson
Hi Jiba,

Have you now added the INDIRECT_is_instance?

Thanks
Brownson
Reply | Threaded
Open this post in threaded view
|

Re: about is_a and is_instance_of

Jiba
Administrator
Hi,

Yes, it has been added. You can use either INDIRECT_is_a or INDIRECT_is_instance_of.

Jiba