Strange behaviour with pizza ontology: 'NoneType' object is not callable

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

Strange behaviour with pizza ontology: 'NoneType' object is not callable

eliskav
We've been having some strange issues trying to instantiate classes from the Pizza ontology (from protege's website, url below in code). It seems to work when instantiated inside the onto.classes() for loop, so it should be loaded correctly, but fails outside of it with TypeError: 'NoneType' object is not callable error. This exception does not seem to occur when we try the same thing with other ontologies, at least what we've found so far (both the example bacteria ontology and our work ontology work just fine with directly using onto.<class_name>()).

    onto = get_ontology("https://protege.stanford.edu/ontologies/pizza/pizza.owl")
    onto.load()
    for onto_class in onto.classes():
        print(onto_class)
        individual = onto_class()
        print(individual)

        # acts as expected to this point

    # out of the loop, starts acting strange
    print(f"`onto.Veneziana` returns: {onto.Veneziana}")
    test_pizza = onto.Veneziana("example_id")
    # Error: TypeError: 'NoneType' object is not callable

Am I missing something? Are we calling the class wrong, or is something wrong with the ontology itself?
Reply | Threaded
Open this post in threaded view
|

Re: Strange behaviour with pizza ontology: 'NoneType' object is not callable

felix
This is an issue with the namespaces. Note how the pizza ontology's entities do not include the URL you load the ontology from - for example, it is
"http://www.co-ode.org/ontologies/pizza/pizza.owl#Veneziana"
instead of
"https://protege.stanford.edu/ontologies/pizza/pizza.owl#Veneziana"
This means you have to specify the correct namespace via the "get_namespace" method, see also the documentation
In your case, the following should work:

from owlready2 import *

onto = get_ontology("https://protege.stanford.edu/ontologies/pizza/pizza.owl").load()
pizza = get_namespace("http://www.co-ode.org/ontologies/pizza/pizza.owl#")

print(list(onto.classes()))
print(pizza.Veneziana)
with onto:
    test_pizza = pizza.Veneziana("example_id")
print(onto.example_id)