getting NoneType for entities that should be in ontology

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

getting NoneType for entities that should be in ontology

Mark L.
Hello,

Just getting started with Owlready2.  I love it in theory, but I'm getting hung up on something that I think should be easy.

Following the docs, this works:


In [3]: from owlready2 import *
   ...: onto = get_ontology("http://www.lesfleursdunormal.fr/static/_downloads/pizza_onto.owl")
   ...: onto.load()
   ...:
Out[3]: get_ontology("http://www.lesfleursdunormal.fr/static/_downloads/pizza_onto.owl#")
In [4]: list(onto.classes())
   ...:
Out[4]:
[pizza_onto.CheeseTopping,
 pizza_onto.FishTopping,
 pizza_onto.MeatTopping,
 pizza_onto.Pizza,
 pizza_onto.TomatoTopping,
 pizza_onto.Topping]
In [5]: onto.CheeseTopping
Out[5]: pizza_onto.CheeseTopping


That is, I am able to list the classes, and to access any of the classes using dot notation. But when I try with any other ontologies, I get a NoneType when I try to access the class. For instance, with the pizza ontology at https://github.com/owlcs/pizza-ontology/blob/master/pizza.owl, this is what the same procedure looks like:

In [6]: onto = get_ontology("/Users/ml/Sandbox/ontology_scratch/pizza_ontology.xml")
   ...: onto.load()
   ...:
Out[6]: get_ontology("http://www.co-ode.org/ontologies/pizza/")
In [7]: list(onto.classes())[0:10]
Out[7]:
[pizza.Pizza,
 pizza.PizzaBase,
 pizza.Food,
 pizza.Spiciness,
 pizza.PizzaTopping,
 pizza.American,
 pizza.NamedPizza,
 pizza.MozzarellaTopping,
 pizza.PeperoniSausageTopping,
 pizza.TomatoTopping]
In [8]: onto.Pizza

In [9]: type(onto.Pizza)
Out[9]: NoneType

This is happening for any ontology I try, other than the example provided in the docs, so I'm pretty certain I'm doing something wrong or misunderstanding how this should work.  How could the classes be NoneType if they are listed as classes in onto.classes?

Thank you!

Mark

Reply | Threaded
Open this post in threaded view
|

Re: getting NoneType for entities that should be in ontology

Mark L.
This is also happening for the Radlex ontology (the one I'm really interested in), available at http://radlex.org/ 
(go to 'Accessing Radlex'->'Download Radlex',  select 'RadLex OWL')
The radlex ontology is also available on bioportal, but I think that one has puns.
Reply | Threaded
Open this post in threaded view
|

Re: getting NoneType for entities that should be in ontology

Mark L.
Reply | Threaded
Open this post in threaded view
|

Re: getting NoneType for entities that should be in ontology

Jiba
Administrator
Hi,

The problem is that the IRI if the classes are not of the form "Ontology base IRI + class name".

This can be verified as follows:

>>> onto = get_ontology("https://raw.githubusercontent.com/owlcs/pizza-ontology/master/pizza.owl").load()

# Base IRI if the ontology:
>>> onto.base_iri
'http://www.co-ode.org/ontologies/pizza/'

# IRI of a class (I took the last one):
>>> c = list(onto.classes())[-1]
>>> c.iri
'http://www.co-ode.org/ontologies/pizza/pizza.owl#Veneziana'


When you write "onto.Veneziana", Owlready builds the IRI "http://www.co-ode.org/ontologies/pizza/Veneziana" (ontology base IRI + class name), which is not the IRI of the class.

To access these classes, you can create a namespace with the classes base IRI, as follows:

>>> namespace = onto.get_namespace("http://www.co-ode.org/ontologies/pizza/pizza.owl#")
>>> namespace.Veneziana
pizza.Veneziana

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: getting NoneType for entities that should be in ontology

Mark L.
perfect, thank you Jiba!