Accessing entities in imported ontologies

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

Accessing entities in imported ontologies

samsontu
Hi,

I am a new user of OWLReady2. I am impressed with the ease of use of OWLReady2. However, I encountered one problem that I haven't been able to solve or see a solution when I browsed the forum. The problem is that I have one ontology A that imports ontology B ("OMOP"). When I ran the code

print(onto.search(iri=“*OMOP*))

I got entities that are in the imported OMOP ontology (OMOP.OBSERVATION etc.). However, when I ran the code

for cls in onto.classes():
   print(cls.name)

I only got classes that are declared in the importing ontology A. Ditto for the properties.

How do I access entities in the imported ontology? What am I missing?

Thank you.

With best regards,
Samson
Reply | Threaded
Open this post in threaded view
|

Re: Accessing entities in imported ontologies

Jiba
Administrator
Hi,

Indeed, it seems that search() does not limit the search to the ontology.

If you want to restrict the search to a given ontology, you may use SPARQL with the GRAPH clause, which is supported in the latest version of Owlready.

If you do not want to restrict the search to any ontology, but to get all classes, you can use search(), SPARQL without the GRAPH clause, or default_world.classes() for listing all classes.

If you want to list all classes in an ontology and the corresponding imported ontologies, the best option is to code a recursive function that calls Ontology.classes() and then iterates over imported ontologies and call their .classes().

Jiba