Loading Ontologies and using them

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

Loading Ontologies and using them

rami_dhouib
I did some code in owl ready and now I need to import an Ontology to use it. The problem is owlready doesn't do it correctly, no classes found. Like if I try to import go.owl (http://geneontology.org/docs/download-ontology/) and then add a class (for simplicity) named A with code:
with onto:
  class A(GO_0046852):
    pass
I get the error:
NameError: name 'GO_0000030' is not defined
This is because owlready takes into consideration thats the class IRI should be #GO_0000030 not http://purl.obolibrary.org/obo/GO_0046852 or even http://purl.obolibrary.org/obo#GO_0046852 which doesn't make sense. So no class gets detected. How can I fix this, or go around it?

I can't swap to another API now because I already did so much code. This is the code that yields an error:

from owlready2 import *

onto = get_ontology("go.owl").load()
with onto:
    class A(GO_0000030):
        pass
onto.save(file = "test.owl", format = "rdfxml")
Reply | Threaded
Open this post in threaded view
|

Re: Loading Ontologies and using them

Jiba
Administrator
Hi,

You can get GO_0046852 from go.owl as follows:

Method 1:

GO_0046852 = default_world["http://purl.obolibrary.org/obo/GO_0046852"]

Method 2:

obo = get_namespace("http://purl.obolibrary.org/obo/")
GO_0046852 = obo.GO_0046852

Jiba