如何使用SPARQL从triples中提取rdf:about或rdf:ID属性?

Pio*_*ach 2 java rdf semantic-web rdfs triplestore

这在开始时似乎是一件小事,但到目前为止,我还没有设法使用SPARQL获取给定资源的唯一标识符.我的意思是,例如,rdf:Description rdf:about="http://..."然后一些属性识别此资源,我想要做的是首先找到这个非常资源,然后检索给定一些URI的所有三元组.

我通过在一个WHERE子句中编写语句来尝试天真的方法,例如:

?x rdf:about ?y and ?x rdfs:about ?y
Run Code Online (Sandbox Code Playgroud)

我希望我是准确的.

use*_*512 7

你犯了一个经典错误:将RDF(这是SPARQL查询的内容)与其序列化(一个)混淆,即RDF/XML.rdf:about(和rdf:ID,rdf:Description,rdf:resource)是RDF/XML,的方式RDF被记录下来的一部分.您可以使用RDF验证器来查看RDF/XML的RDF三元组.

在你的情况下,让我们开始:

<?xml version="1.0"?>
<rdf:RDF 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:dc="http://purl.org/dc/terms/">
  <rdf:Description rdf:about="http://www.example.org/">
    <dc:title>Example for Donal Fellows</dc:title> 
  </rdf:Description>
</rdf:RDF>
Run Code Online (Sandbox Code Playgroud)

将其插入验证器,您将获得:

Number      Subject                      Predicate                        Object
1           http://www.example.org/      http://purl.org/dc/terms/title   "Example for Donal Fellows"
Run Code Online (Sandbox Code Playgroud)

(你也可以要求图片表示)

请注意,rdf:about该值不存在:其值提供三元组的主题.

如何查询以查找与之关联的属性http://www.example.org?像这样:

select * {
    <http://www.example.org/> ?predicate ?object
}
Run Code Online (Sandbox Code Playgroud)

你会得到:

?predicate                        ?object
<http://purl.org/dc/terms/title>  "Example for Donal Fellows"
Run Code Online (Sandbox Code Playgroud)

你会注意到,?v在我们想要查找值的地方,查询是与variables()的三重匹配.我们还可以问什么样的断言链接http://www.example.org/"Example for..."通过询问:

select * {
    <http://www.example.org/> ?predicate "Example for Donal Fellows"
}
Run Code Online (Sandbox Code Playgroud)

这种模式匹配是SPARQL的核心.

RDF/XML是一个棘手的野兽,你可能会发现它更易于使用的N-Triples,这是非常冗长,但明显的,或乌龟,这就好比的N-Triples有大量的速记和缩写.rdf社区通常首选龟.

PS rdfs:about在任何地方都不存在.