Login  Register

No results when running the same SPARQL query in Owlready compared to Protege

classic Classic list List threaded Threaded
3 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

No results when running the same SPARQL query in Owlready compared to Protege

IWilliams
29 posts
I tried the SPARQL query below in protege and got results. However, when I followed the documentation for Owlready2, I am not getting any results.
#code snippet in python

onto = get_ontology("file://../Ontology/newOnto.owl").load()
graph = default_world.as_rdflib_graph()
r = list(graph.query("""
    PREFIX UC: <http://www.semanticweb.org/myonto#>
    SELECT ?UseCase WHERE {
    ?UseCase UC:hasBoundary 'D'.
    }"""))

print (r)
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: No results when running the same SPARQL query in Owlready compared to Protege

Richard
6 posts
It would be cool to see this working in owlready2. Here's what I've been doing with just rdflib:

from rdflib.plugins.sparql import prepareQuery
from rdflib import URIRef

onto = get_ontology("file://../Ontology/newOnto.owl").load()
graph = default_world.as_rdflib_graph()

UC = URIRef('http://www.semanticweb.org/myonto#')
q = prepareQuery('''SELECT ?UseCase
                       WHERE {
                                 ?UseCase UC:hasBoundary 'D' .}""", initNs={'UC':UC} )
for row in graph.query(q):
    print(row)
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: No results when running the same SPARQL query in Owlready compared to Protege

Jiba
Administrator
1186 posts
Hello,

There was a bug in the RDFlib support that prevented the SPARQL query on string. I fixed this bug in the development version.

I also added the .query_owlready() method that automatically converts the results in Python and Owlready objects.

Best regards,
Jean-Baptiste Lamy
MCF HDR, Laboratoire LIMICS, Université Paris 13