2

我正在尝试执行以下 Sparql 查询

select * where { 
    ?s ?p ?o .
} limit 100 

它运行良好并根据http://localhost:7200/sparql的要求产生结果,即 GraphDB Workbench。我想使用 python 进行相同的查询,为此我通过单击 GraphDB 界面中的“获取当前查询的 URL”来生成以下查询 URL。

http://localhost:7200/sparql?name=&infer=true&sameAs=false&query=select+*+where+%7B+%0A%09%3Fs+%3Fp+%3Fo+.%0A%7D+limit+100+%0A&execute=

我尝试为此编写 Python 代码

 import pycurl
 from StringIO import StringIO
 url="http://localhost:7200/sparql?name=&infer=true&sameAs=false&query=select+*+where+%7B+%0A%09%3Fs+%3Fp+%3Fo+.%0A%7D+limit+100+%0A&execute="
 response_buffer = StringIO()
 curl = pycurl.Curl()
 curl.setopt(curl.URL,url)
 curl.setopt(curl.USERPWD, '%s:%s' % (' ' , ' '))
 curl.setopt(curl.WRITEFUNCTION, response_buffer.write)
 curl.perform()
 curl.close()
 response_value = response_buffer.getvalue()
 print response_value

但是这会返回:错误 - http 状态 (404) - 没有消息,请查看服务器日志以获取更多信息

我是否需要为在 Python 中查询 GraphDB 做任何额外的设置。我可以得到一些关于如何使用 Python 和 Sparql 查询 GraphDB 的指导吗?

4

1 回答 1

4

GraphDB 数据库为每个 RDF 存储库公开一个 SPARQL 端点。正确的 SPARQL 端点地址可以从 Workbench 的界面 Setup > Repositories > 存储库名称旁边的链接图标(“Copy Repository URL to Clipboard”)中复制。

您的 HTTP 请求应如下所示:

http://localhost:7200/repositories/%repositoryID%?name=&infer=true&sameAs=false&query=select+*+where+%7B+%0A%09%3Fs+%3Fp+%3Fo+.%0A%7D+limit+100+%0A&execute=

其中%repositoryID%值是存储库的 ID。

于 2017-03-04T08:39:09.537 回答