How to get subclasses of a restriction?

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

How to get subclasses of a restriction?

Dave
Hi There,

I am trying to find the parts of organs in Uberon. For example, to find all the parts of the liver I am looking for subclasses of the restriction "part_of some liver".

For example, you can see using biliary ductile:

biliary_ductile = uberon.search_one(iri="http://purl.obolibrary.org/obo/UBERON_0004058")
print(biliary_ductile.is_a)

>[obo.UBERON_0000025, obo.UBERON_0004119, obo.BFO_0000050.some(obo.UBERON_0002107), obo.BFO_0000050.some(obo.UBERON_0002394), obo.RO_0002220.some(obo.UBERON_0001175)]


that biliary ductile "is_a" obo.BFO_0000050.some(obo.UBERON_0002107) .
BFO_0000050 = part_of and UBERON_0002107 = liver.

I can create a restriction like:

part_of = uberon.search_one(iri="http://purl.obolibrary.org/obo/BFO_0000050")
liver = uberon.search_one(iri="http://purl.obolibrary.org/obo/UBERON_0002107")
posl_restriction = part_of.some(liver)


However, I can not figure out how to use the posl_restriction to query for its subclasses (like biliary ductile).


With owlready2 how can I get the classes that declare a given restriction like obo.BFO_0000050.some(obo.UBERON_0002107)?

Thanks for your help!
Cheers,
D







Reply | Threaded
Open this post in threaded view
|

Re: How to get subclasses of a restriction?

Jiba
Administrator
Hi,

You can use restriction.subclasses() to get its subclasses. However, this returns only subclasses of the particular instance of restriction -- subclasses of another restriction on the same property and value class will not be returned. Consequently, it will return an empty list for a freshly created restriction.

If you want to get all subclasses of a restriction, defined by property and value class, you should build a SPARQL query. Here is a simple example:


from owlready2 import *

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

with onto:
  class C(Thing): pass
  class D(Thing): pass
  class p(Thing >> Thing): pass
 
  class C1(C): is_a = [p.some(D)]
  class C2(C): equivalent_to = [p.some(D)]
 
l = default_world.sparql("""
SELECT ?class {
  ?class (rdfs:subClassOf|owl:equivalentClass)+ ?restriction .
  ?restriction owl:onProperty onto:p .
  ?restriction owl:someValuesFrom onto:D .
}
""")
print(list(l))


Jiba
Reply | Threaded
Open this post in threaded view
|

Re: How to get subclasses of a restriction?

Dave
Jiba, Thank you.

Yes if I create a new instance of the restriction or try to access any of the restrictions found calling some_class.is_a the subclasses are empty.

Will give the SPARQL approach a try. Thanks for the detailed example!

Cheers,
D