Re: How to gathered the way items are linked in an ontology

Posted by Jiba on
URL: http://owlready.306.s1.nabble.com/How-to-gathered-the-way-items-are-linked-in-an-ontology-tp344p346.html

Hi,

Normally, .subclasses() can be used to obtain direct subclasses. However, it does not work on Thing (because Thing is strictly speaking not part of your ontology -- Owlready can support several, isolated, "World" but Thing remains common to all of them). This is one of the bug in Owlready for which I cannot find a solution :-(

Currently, you can get direct subclasses of Thing as follows:

     [c for c in onto.classes() if c.__bases__ == (Thing,)]


Regarding your initial problem (finding is_part_of relations), it depends whether you are working on instances/individuals or classes.

With individuals, you can just use individual.is_part_of to get the list of corresponding values.

With classes, it is much more complex because, in OWL, relations does not exist on classes -- they are restriction with an associated qualifier (e.g. some or only). Classes are considered as subclasses of those restrictions, so you need to query the OWL superclasses (with Class.is_a) and to search for some restriction on the is_part_of property.

As a special feature, Owlready exposes "value" OWL restrictions (= restriction between a class and an individual) as class properties. I have some plan to generalize this to "some" restrictions, but it is not done yet.

Best regards,
Jiba