How to gathered the way items are linked in an ontology

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

How to gathered the way items are linked in an ontology

Frack
Hi all,

A quite strange question here, I would like to be able to query my (Protégé) ontology this way:

I have entities:

Owl:Thing
--A
----1
----2
--B
----3
----4
----5
----6

I have relations between some of them, let say for example:
relation : is_part_of
3 is_part_of 1
4 is_part_of 1

Only these 2. So after that I would like to query such an entry : for example I get a question saying, is 5 a part of 1? I then want to query the ontology to then check that, no, 5 is not a part of 1.

If I correctly understood how works the API, I have to re-create my ontology as classes within my python file (classes, relations, properties, ...), so I started by parsing my classes(), but it shows me all the classes and not only the 1st level ones. Do I have to trick and look for Owl:Thing subclasses()?

Don't hesitate if you need further details, it can be a little bit messy I admit :).
Reply | Threaded
Open this post in threaded view
|

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

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

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

Frack
Hi Jiba,

Thanks for your reply. For the direct subclasses I will try what you say, the goal would be later to be able to construct dynamicaly an ontology structure within the API depending on another updated only through Protégé.

For the relation problem, I went some new steps yesterday.
I did not create all my existing entities as classes, but only my relation, to have the class Relation (A >> B)
Then with that, I have been able to create another class using this relation, adding restriction on it :
class UsingRelation (myObject):
    equivalent_to = [myObject & Relation.some(otherObject)]

It seems that this class is able to show me the element dealing with the relation I'm looking for, but what I would then like to have is the name of entities involved by the answer.
This class is not iterable (I think I have to create a function inside the class for that), what do you think?
Reply | Threaded
Open this post in threaded view
|

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

Jiba
Administrator
Hi,

Do you want to list the instances or classes that have some "Relation" with "otherObject" ? In this case, you need to call the reasoner (with sync_reasoner() ), and then to list the instances or subclasses of UsingRelation (with UsingRelation.instances() for instances or UsingRelation.subclasses() for classes).
Reply | Threaded
Open this post in threaded view
|

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

Citlalli
Hello,

I have a related question. Is there a way to get the range class of a restriction?

More specifically, when I make Class.is_a

I get a list of classes mixed up with restrictions of the form property.some(Class1).

Is there a way to get Class1 from the list of subclasses/superclasses?

Best regards,
Citlalli
Reply | Threaded
Open this post in threaded view
|

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

Jiba
Administrator
Hi,

You can get the range class with the ".value" attribute of the restriction. You may also use .property, .cardinality and .type attributes if needed.

Jiba