在 SPARQL 查询中连接语义端点

发布于 2024-10-15 03:00:58 字数 410 浏览 8 评论 0原文

我正在尝试发出同时使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烈酒灼喉 2024-10-22 03:00:58

我是 bibleontology.com 的工程师

bibleontology.com 采用了 SPARQL1.1

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?art ?abstract
WHERE {
SERVICE <http://bibleontology.com/sparql/> { bibleontology:Ezra owl:sameAs ?art . }
SERVICE <http://dbpedia.org/sparql> { ?art dbo:abstract ?abstract . } }

I'm Engineer for bibleontology.com

bibleontology.com adopted SPARQL1.1

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?art ?abstract
WHERE {
SERVICE <http://bibleontology.com/sparql/> { bibleontology:Ezra owl:sameAs ?art . }
SERVICE <http://dbpedia.org/sparql> { ?art dbo:abstract ?abstract . } }
耀眼的星火 2024-10-22 03:00:58

该查询不适用于 dbpedia 或 bibleontology,因为信息存储在两个不同的数据库中,当您运行 SPARQL 查询时,您基本上会命中其中之一。这意味着您必须从两个数据库下载数据,将它们放入本地三元组存储中,以便能够运行如您所示的 SPARQL 查询。另一种选择是使用可以为您完成此操作的库。

语义 Web 客户端库 将遵循 SPARQL 查询中的所有 URI 并下载来自每个资源的 RDF 数据,以便它可以连接您查询中出现的所有三元组模式并给出答案。

您可以通过一些细微的更改来运行查询:

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dbpedia: <http://dbpedia.org/ontology/> 

SELECT * WHERE { 
bibleontology:Ezra owl:sameAs ?art .
?art dbpedia:abstract ?abstract .
FILTER langMatches( lang(?abstract), "EN" )
} 

更改说明:

  1. 包括 owldbpedia 命名空间
  2. ?art dbpedia:abstract ?abstract . you需要匹配 dbpedia:abstract 谓词来获取摘要,而不是 bibleontology:abstract 才能从
  3. 我还包含的 dbpedia 获取摘要仅检索英文摘要的过滤器,这当然是可选的。

下载“语义 Web 库”并将查询放入文件(即:query.sparql)后,您可以运行以下命令来测试您的查询:

./semwebquery -sparqlfile query.sparql -retrieveduris -maxsteps 5

所有命令参数均在语义 Web 客户端库文档中进行了解释。

您将得到以下输出:

| ?art                               | ?abstract
| <http://dbpedia.org/resource/Ezra> | "Ezra is a major .... "@en |

Successfully dereferenced URIs: 

http://www.w3.org/2002/07/owl
http://bibleontology.com/data/Ezra
http://dbpedia.org/data/Ezra.xml
http://dbpedia.org/data3/abstract.n3

为了简单起见,我省略了 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 :

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dbpedia: <http://dbpedia.org/ontology/> 

SELECT * WHERE { 
bibleontology:Ezra owl:sameAs ?art .
?art dbpedia:abstract ?abstract .
FILTER langMatches( lang(?abstract), "EN" )
} 

Explanation of the changes:

  1. Included owl and dbpedia namespaces
  2. ?art dbpedia:abstract ?abstract . you need to match the dbpedia:abstract predicate to get the abstract instead of bibleontology:abstract in order to get the abstract from dbpedia
  3. I have also included a 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:

./semwebquery -sparqlfile query.sparql -retrieveduris -maxsteps 5

All the command params are explained in the Semantic Web Client Library documentation.

You would get the following output:

| ?art                               | ?abstract
| <http://dbpedia.org/resource/Ezra> | "Ezra is a major .... "@en |

Successfully dereferenced URIs: 

http://www.w3.org/2002/07/owl
http://bibleontology.com/data/Ezra
http://dbpedia.org/data/Ezra.xml
http://dbpedia.org/data3/abstract.n3

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.

安穩 2024-10-22 03:00:58

所有其他答案都是正确的,因为您无法按原样进行查询,因为数据未合并在单个 SPARQL 端点中。如果端点之一支持 SPARQL 1.1 联合查询,那么您可以使用 SERVICE 关键字,如下所示:

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT ?art ?abstract
WHERE 
{ 
  bibleontology:Ezra owl:sameAs ?art .
  SERVICE <http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org> { ?art dbo:abstract ?abstract . }
}

您可以将上述查询提交到 bibleontology SPARQL 端点,前提是它支持 >SERVICE 关键字,它将部分查询发送到 DBPedia SPARQL 端点。

即使您的 SPARQL 端点支持 SERVICE 关键字,那么您仍然依赖两个数据集中的相关数据,即圣经本体需要有一个 owl:sameAs 来指向到 DBPedia 资源,以便 SERVICE 子句实际找到任何内容。

或者

如果您的两个端点都不支持 SERVICE 关键字,那么您可以设置本地端点或使用支持 SERVICE 关键字的命令行工具(如果您感兴趣,我会挖掘一些链接)然后发出以下命令:

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT ?art ?abstract
WHERE 
{ 
  SERVICE <http://bibleontology.com/sparql> { bibleontology:Ezra owl:sameAs ?art . }
  SERVICE <http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org> { ?art dbo:abstract ?abstract . }
}

如果您的本地工具/端点支持 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:

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT ?art ?abstract
WHERE 
{ 
  bibleontology:Ezra owl:sameAs ?art .
  SERVICE <http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org> { ?art dbo:abstract ?abstract . }
}

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 a owl:sameAs that points to a DBPedia resource in order that the SERVICE 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 the SERVICE keyword (I'll dig some links up if you're interested) and then issue the following:

PREFIX bibleontology: <http://bibleontology.com/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT ?art ?abstract
WHERE 
{ 
  SERVICE <http://bibleontology.com/sparql> { bibleontology:Ezra owl:sameAs ?art . }
  SERVICE <http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org> { ?art dbo:abstract ?abstract . }
}

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文