Ontology tree

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

Ontology tree

Tomáš Müller
Hi,

I'm trying to use owlready2 for quite simple task - build ontology class tree and let users pick classes. I already done it with Ontobio library but I like the sqlite concept very much for I might use some really big ontologies (in terms of million classes).

I'm finding hard to navigate in the model since the Docs are more focused on creation and analysis and ipython introspection doesn't work out very well here.

What I'd like to do:
1) Let's Bioassay Ontology for example - it's composed of maybe 20 or so other ontologies
http://www.bioassayontology.org/bao/bao_complete.owl

2) I need to get the root classes i.e. classes with no parents (or just the owl.Thing parent) and some children (to exclude singletons)

3) For each class I need to get relations - parents, ancestors, children, descendants

4) For a class I need to get all related data - properties. I already found the 'get_class_properties' method, that should do what I need

The result should look like this https://bioportal.bioontology.org/ontologies/BAO/?p=classes&conceptid=root
But better off course :-)

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

Re: Ontology tree

William
You can read the author's paper. There is a Correspondence between DLs.

Reply | Threaded
Open this post in threaded view
|

Re: Ontology tree

Jiba
Administrator
In reply to this post by Tomáš Müller
Hi,

2) You can use Thing.subclasses() to get direct subclasses of Thing.

Finding classes that have NO superclass, even not Thing, is much much harder... (if a class is not declared as a class and has no instance and no subclass, how can we guess that it is a class?).

Then, the presence of children can be tested by calling subclasses() on the resulting classes.

3) use Class.is_a, .ancestors(), .subclasses() and .descendants()
The parameter include_self = False can be used to avoid returning the class itself in ancestors() and descendants().

4) get_class_properties() is what you need.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Ontology tree

Jiba
Administrator
Sorry, I think I have confounded OWL Thing and Class in my previous response!

Thing.subclasses() returns all classes that have only Thing as parent, or that have no parent al all. So it corresponds to what you want.

By the way, I've optimized Thing.subclasses() in the development version of Owlready; it is now much faster on large ontologies.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Ontology tree

Tomáš Müller
Great, thanks for help.

Parents, children etc. is clear now... is there some API reference somewhere? That would help a lot.

What is the proper way to "get" Thing (like import or obtain it from some method). I used the Thing you get from .ancestors() (owl.Thing) method and calling .subclasses() returns empty just list. Now I just scan all the classes for their ancestors and children but that doesn't matter much since I need to do this just once and cache the result.

I'm not sure that I got the World concept right. Is it supposed to contain all (unrelated) ontologies? Because I loaded 2 ontology sets into my World  and If I used .search() method on one ontology, it returned even some classes from unrelated ontology, like it searched the World. So now I have separate World for each ontology set (i.e. ontologies that import each other) and that works for me well.

Thanks very much, this starts to look great :-)
Reply | Threaded
Open this post in threaded view
|

Re: Ontology tree

Jiba
Administrator
You can get Thing simply by importing it from owlready2, e.g. from owlready2 import *.

Worlds are isolated universe of discourses. They can be used if you want to load several incompatible ontologies, such as different version of the same ontology.

If you use World, you need to specify the world you are working on when calling Thing.subclasses():

    Thing.subclasses(world = your_world)

(this is required because, unlike other classes, Thing is common to all worlds).

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Ontology tree

Sumit Purohit
I am also trying to build an ontology tree But i see that owlready2 loads files differently.
I have three Owl ontologies in .nt format. A, B ,C
Both A, and B have classes which are rdfs:subClassOf classes defined in C

The issue is that parent of every class in A is listed as "C.nt.ClassName1" where as the parent of every class in B is listed as "C.ClassName1". (without ".nt"

Because of this, "Thing" only lists "C.nt.ClassName1" as its child so there is not way for me to traverse to classes of B using "Thing".

Why does owlready creates parent class names in two different ways ?

Thanks