在 SPARQL 查询中连接语义端点
我正在尝试发出同时使用 bibleontology 和 dbpedia 语义数据库的请求:
PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?art ?abstract WHERE {
bibleontology:Ezra owl:sameAs ?art .
?art dbo:abstract ?abstract .
}
这种请求既不适用于 bibleontology SPARQL 端点,也不适用于 dbpedia SPARQL 端点。请求的各个部分在每个 SPARQL 端点上运行良好。
可以通过这种方式连接数据库吗?
I'm trying to make a request which uses both bibleontology and dbpedia semantic databases:
PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?art ?abstract WHERE {
bibleontology:Ezra owl:sameAs ?art .
?art dbo:abstract ?abstract .
}
This kind of request works on neither the bibleontology SPARQL endpoint, nor on the dbpedia SPARQL endpoint. Individual parts of the requests work fine on the each SPARQL endpoints.
Is it possible to join databases this way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我是 bibleontology.com 的工程师
bibleontology.com 采用了 SPARQL1.1
I'm Engineer for bibleontology.com
bibleontology.com adopted SPARQL1.1
该查询不适用于 dbpedia 或 bibleontology,因为信息存储在两个不同的数据库中,当您运行 SPARQL 查询时,您基本上会命中其中之一。这意味着您必须从两个数据库下载数据,将它们放入本地三元组存储中,以便能够运行如您所示的 SPARQL 查询。另一种选择是使用可以为您完成此操作的库。
语义 Web 客户端库 将遵循 SPARQL 查询中的所有 URI 并下载来自每个资源的 RDF 数据,以便它可以连接您查询中出现的所有三元组模式并给出答案。
您可以通过一些细微的更改来运行查询:
更改说明:
owl
和dbpedia
命名空间?art dbpedia:abstract ?abstract .
you需要匹配dbpedia:abstract
谓词来获取摘要,而不是bibleontology:abstract
才能从dbpedia
获取摘要仅检索英文摘要的过滤器
,这当然是可选的。下载“语义 Web 库”并将查询放入文件(即:query.sparql)后,您可以运行以下命令来测试您的查询:
所有命令参数均在语义 Web 客户端库文档中进行了解释。
您将得到以下输出:
为了简单起见,我省略了 dbpedia 的长摘要。 “成功取消引用的 URI”列表是图书馆为了回答您的查询而检索的文档。在该库的文档中,您将了解如何在 Java 中以编程方式运行查询。
That query doesn't work on neither dbpedia or bibleontology because the information is stored in two different databases and when you run a SPARQL query you basically hit one or the other. This means that you have to you download the data from both databases to put them in a local triple store in order to able to run a SPARQL query like the one you showed. Another option is to use a library that does that for you.
The Semantic Web Client Library will follow all URIs that you have in your SPARQL query and download the RDF data from each resource so that it can join all the triple patterns that appear in you query and give the answers.
You could run your query with some minor changes :
Explanation of the changes:
owl
anddbpedia
namespaces?art dbpedia:abstract ?abstract .
you need to match thedbpedia:abstract
predicate to get the abstract instead ofbibleontology:abstract
in order to get the abstract fromdbpedia
filter
to only retrieve abstracts in English, this is of course optional.Once you download "The Semantic Web Library" and you put your query in a file (i.e: query.sparql) you can run the following command to test your query:
All the command params are explained in the Semantic Web Client Library documentation.
You would get the following output:
I have omitted the long abstract from dbpedia for simplicity. The list of "Successfully dereferenced URIs" are documents retrieved by the library in order to answer your query. In the documentation of the library you'll see how to run queries programatically in Java.
所有其他答案都是正确的,因为您无法按原样进行查询,因为数据未合并在单个 SPARQL 端点中。如果端点之一支持 SPARQL 1.1 联合查询,那么您可以使用
SERVICE
关键字,如下所示:您可以将上述查询提交到 bibleontology SPARQL 端点,前提是它支持
>SERVICE
关键字,它将部分查询发送到 DBPedia SPARQL 端点。即使您的 SPARQL 端点支持
SERVICE
关键字,那么您仍然依赖两个数据集中的相关数据,即圣经本体需要有一个owl:sameAs
来指向到 DBPedia 资源,以便SERVICE
子句实际找到任何内容。或者
如果您的两个端点都不支持
SERVICE
关键字,那么您可以设置本地端点或使用支持SERVICE
关键字的命令行工具(如果您感兴趣,我会挖掘一些链接)然后发出以下命令:如果您的本地工具/端点支持
SERVICE
那么它将能够将查询的相关部分发送到相关端点并在本地进行连接,希望能返回您想要的结果All the other answers are correct in saying that you can't make the query as is because the data is not combined in a single SPARQL endpoint. If one of the endpoints supports SPARQL 1.1 Federated Querying then you may be able to use the
SERVICE
keyword like so:You'd submit the above query to the bibleontology SPARQL endpoint and provided that it supports the
SERVICE
keyword it sends part of your query to the DBPedia SPARQL endpoint.Even if your SPARQL endpoint supports the
SERVICE
keyword then you are still reliant on the relevant data being in the two datasets i.e. the Bible Ontology needs to have aowl:sameAs
that points to a DBPedia resource in order that theSERVICE
clause actually find anything.Alternatively
If neither of your endpoints support the
SERVICE
keyword then you can set up a local endpoint or use a command line tool that supports theSERVICE
keyword (I'll dig some links up if you're interested) and then issue the following:If your local tool/endpoint supports
SERVICE
then it will be able to send the relevant parts of the query to the relevant endpoints and do the Joining locally and hopefully give back the results you are after