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

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

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

IWilliams
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
|

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

Richard
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
|

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

Jiba
Administrator
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