使用SPARQL提取属性值

时间:2016-04-29 10:36:55

标签: sparql rdf

我想使用SPARQL来获取具有以下资源的主题rdf:valuehttp://purl.org/dc/terms/LCSH

<dcterms:subject>
    <rdf:Description rdf:nodeID="N4192a7fb1dd6438c94649f7afd192f09">
        <rdf:value>United States. Declaration of Independence</rdf:value>
        <dcam:memberOf rdf:resource="http://purl.org/dc/terms/LCSH"/>
    </rdf:Description>
</dcterms:subject>
<dcterms:subject>
    <rdf:Description rdf:nodeID="N887b24b564624253b374ee7c95f0ed51">
       <rdf:value>United States -- History -- Revolution, 1775-1783 -- Sources</rdf:value>
       <dcam:memberOf rdf:resource="http://purl.org/dc/terms/LCSH"/>
    </rdf:Description>
</dcterms:subject>
<dcterms:subject>
    <rdf:Description rdf:nodeID="N1b3ed5adb91b4b0c8aa1215180fdfa96">
       <rdf:value>JK</rdf:value>
       <dcam:memberOf rdf:resource="http://purl.org/dc/terms/LCC"/>
    </rdf:Description>
</dcterms:subject>
<dcterms:subject>
   <rdf:Description rdf:nodeID="Nc5deb6e74cc6462fbeeb8c1871983f09">
      <dcam:memberOf rdf:resource="http://purl.org/dc/terms/LCC"/>
      <rdf:value>KF</rdf:value>
   </rdf:Description>
</dcterms:subject>

有没有办法提取rdf:resource并用它来过滤主题?

1 个答案:

答案 0 :(得分:2)

rdf / xml代码段不完整,所以我们无法写出完美的查询,但您会想要这样的内容:

select ?value {
  ?x dcterms:subject ?subject .
  ?subject rdf:value ?value .
  ?subject dcam:memberOf  <http://purl.org/dc/terms/LCSH> .
}

如果你想缩短一点,你可以这样做:

select ?value {
  ?x dcterms:subject [
      rdf:value ?value ;
      dcam:memberOf  <http://purl.org/dc/terms/LCSH> ]
}

如果您真的只关心具有rdf:value属性并且是LCSH成员的事物,那么您可以完全跳过第一个三元组:

select ?value {
  ?x rdf:value ?value ;
      dcam:memberOf  <http://purl.org/dc/terms/LCSH> 
}