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, I get no results. I tried with a different query, which doesn't rely on inference, and got the same results through the Stardog query panel without inference and through SPARQLwrapper. So I suspect reasoning is not being applied when I query through python, and that this is why there's no results. So my question is How can I tell Stardog to use inference when querying it through SPARQLwrapper?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答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.
回答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()