Problem with simple queries : search

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

Problem with simple queries : search

AdelHans
Hello,
I am trying to find the sub classes of a given class with owlready2 but I am having an issue with ontologies like pizza and go . this is my code and what I get when I run it:
----------------------------------------------------------
onto_path = "D:\Projects\SPARQL Translator\Ontologies\pizza.owl"
onto = get_ontology(onto_path).load()
print( onto.base_iri)
for i in onto.search(subclass_of=onto.NamedPizza):
    print( i.iri)

----------------------------------------------------------
Traceback (most recent call last):
  File "D:/Projects/SPARQL Translator/Entity Mapping.py", line 7, in <module>
    for i in onto.search(subclass_of=onto.NamedPizza):
  File "C:\Users\Adel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\owlready2\namespace.py", line 349, in search
    else:                                   v2 = v.storid
AttributeError: 'NoneType' object has no attribute 'storid'
http://www.co-ode.org/ontologies/pizza/
------------------------------------------------------------
Best Regards
Adel Hansali
Reply | Threaded
Open this post in threaded view
|

Re: Problem with simple queries : search

Mike Bergman

I think you can use this Owlready2 method:

print(onto.NamedPizza.descendants())

Best, Mike

On 4/30/2020 11:08 AM, AdelHans [via Owlready] wrote:
Hello,
I am trying to find the sub classes of a given class with owlready2 but I am having an issue with ontologies like pizza and go . this is my code and what I get when I run it:
----------------------------------------------------------
onto_path = "D:\Projects\SPARQL Translator\Ontologies\pizza.owl"
onto = get_ontology(onto_path).load()
print( onto.base_iri)
for i in onto.search(subclass_of=onto.NamedPizza):
    print( i.iri)

----------------------------------------------------------
Traceback (most recent call last):
  File "D:/Projects/SPARQL Translator/Entity Mapping.py", line 7, in <module>
    for i in onto.search(subclass_of=onto.NamedPizza):
  File "C:\Users\Adel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\owlready2\namespace.py", line 349, in search
    else:                                   v2 = v.storid
AttributeError: 'NoneType' object has no attribute 'storid'
http://www.co-ode.org/ontologies/pizza/
------------------------------------------------------------
Best Regards
Adel Hansali


If you reply to this email, your message will be added to the discussion below:
http://owlready.8326.n8.nabble.com/Problem-with-simple-queries-search-tp1752.html
To unsubscribe from Owlready, click here.
NAML

  



	
	
	
	
Reply | Threaded
Open this post in threaded view
|

Re: Problem with simple queries : search

AdelHans
Same problem
I think the problem is related to the namespace
Thank you
Reply | Threaded
Open this post in threaded view
|

Re: Problem with simple queries : search

Jiba
Administrator
In reply to this post by AdelHans
Hi,

There are several version of the pizza ontology, some define the classes in the ontology namespace and other don't.

Please try :

    print(onto.NamedPizza)

If it is None, then the NamedPizza is defined in another namespace.

For example, if you use this pizza ontology :

    https://raw.githubusercontent.com/owlcs/pizza-ontology/master/pizza.owl

The full name of NamedPizza is "http://www.co-ode.org/ontologies/pizza/pizza.owl#NamedPizza" while the ontology is named "http://www.co-ode.org/ontologies/pizza". so the ".owl" is missing.

You can use a namespace as follows to solve this problem:


onto = get_ontology("pizza.owl").load()

namespace = get_namespace("http://www.co-ode.org/ontologies/pizza/pizza.owl#")
print(namespace.NamedPizza)
print(default_world.search(subclass_of = namespace.NamedPizza))


Jiba