Queries using RDFLIB

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

Queries using RDFLIB

Marcos Motta
Hi Everyone I am new in the ontology field, and I don’t know if my question is easy or not. I am a Ph.D. student in Transportation Planning, using an ontology (HBOnto - https://github.com/dzolzaya/HRBModel/blob/master/HBOnto.owl) to deal with a critical task in my thesis. I have been studying the book ontologies-with-python-programming-owl-20-ontologies-with-python-and-owlready2 and testing some examples. Unfortunately, I have not been able to perform queries using rdflib. I did exactly how it is in the book, but can not get the result, I am always receiving a empty list as a result. When i’ve test with the book’s ontology (bacteria) works weel, but with HBOnto doesnt work. I’ve put below some code parts in pictures. I do really apreciate some help. Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Queries using RDFLIB

Jiba
Administrator
Hi,

I tested your ontology. First, it appears that http://localhost/HRBModel/HBOnto.owl#time is both declared as a DataProperty and a Class. This is not supported by Owlready, and is not clearly defined in OWL. I removed the DataProperty definition, as it is not used in the ontology.

Then, it appears that there is no instances of the "working" class. This explains why the SPARQL query returns an empty list.

You may want to search for subclasses of "working", as follows:

from owlready2 import *

onto_path.append("/tmp")
onto = get_ontology("/tmp/HBOnto.owl").load()

graph = default_world.as_rdflib_graph()

print(list(graph.query("""
SELECT ?x WHERE {
  ?x rdfs:subClassOf* <http://localhost/HRBModel/HBOnto.owl#working> .
}
""")))

Jiba