subclass_of

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

subclass_of

tommycarstensen
Does an example exist on how to use subclass_of? It is mentioned here:
https://owlready2.readthedocs.io/en/latest/onto.html

I want to find all classes that are subclasses of a class; irrespective of the depth.
Reply | Threaded
Open this post in threaded view
|

Re: subclass_of

Jiba
Administrator
Hi,

Here is an example :

onto = get_ontology("http://test.org/onto.owl")

with onto:
    class A(Thing): pass
    class B(A): pass
    class C(B): pass

print(list(onto.search(subclass_of = A)))
# prints [onto.A, onto.B, onto.C]


Notice that A is considered as a subclass of itself.

Jiba