Skip to content Skip to sidebar Skip to footer

How Can I Tell Stardog To Use Inference When Querying It Through Sparqlwrapper?

I have a SPARQL query that returns results in the Stardog query panel when inference is enabled, but not when it's disabled. When I try the query through python with SPARQLwrapper,

Solution 1:

The documentation of Stardog is pretty good:

HTTP

For HTTP, the reasoning flag is specified with the other HTTP request parameters:

$ curl -u admin:admin -X GET "http://localhost:5822/myDB/query?reasoning=true&query=..."

which means simply add the param ?reasoning=true to the remote URL string.

Solution 2:

I had the exact same problem. The solution is to use addParameter when you build the query which adds the required reasoning=true to the URL.

A skeleton of a query could then look like this:

from SPARQLWrapper import SPARQLWrapper, JSON

endpoint = '<your endpoint>'

sparql = SPARQLWrapper(endpoint)

# add your username and password if required
sparql.setCredentials('<your username>', '<your password>')

rq = """

<your query string>

"""

sparql.setQuery(rq)
sparql.setReturnFormat(JSON)

# use reasoning
sparql.addParameter('reasoning', 'true')

data_json = sparql.query().convert()

Post a Comment for "How Can I Tell Stardog To Use Inference When Querying It Through Sparqlwrapper?"