如何使用sparql提取具有特定谓词的RDF三元组

问题描述 投票:1回答:2

我将一组RDF三元组上传到本地Virtuoso端点。

在所有这些三元组中,我只想提取那些主题至少包含谓词http://www.w3.org/2000/01/rdf-schema#labelhttp://www.w3.org/2000/01/rdf-schema#comment的人。

例如,从这些三元组中:

<http://dbpedia.org/resource/AccessibleComputing> <http://www.w3.org/2000/01/rdf-schema#label> "AccessibleComputing"@en .
<http://dbpedia.org/resource/AfghanistanGeography> <http://www.w3.org/2000/01/rdf-schema#label> "AfghanistanGeography"@en .
<http://dbpedia.org/resource/AfghanistanGeography> <http://www.w3.org/2000/01/rdf-schema#comment> " ... " .
<http://dbpedia.org/resource/Austroasiatic_languages> <http://www.w3.org/2000/01/rdf-schema#comment> " ... " .
<http://dbpedia.org/resource/AccessibleComputing> <http://dbpedia.org/ontology/wikiPageWikiLink> <http://dbpedia.org/resource/Computer_accessibility> .
<http://dbpedia.org/resource/AfghanistanGeography> <http://dbpedia.org/ontology/wikiPageWikiLink> <http://dbpedia.org/resource/Afghanistan_Geography> .

我想得到:

<http://dbpedia.org/resource/AfghanistanGeography> <http://www.w3.org/2000/01/rdf-schema#label> "AfghanistanGeography"@en .
<http://dbpedia.org/resource/AfghanistanGeography> <http://www.w3.org/2000/01/rdf-schema#comment> " ... " .
<http://dbpedia.org/resource/AfghanistanGeography> <http://dbpedia.org/ontology/wikiPageWikiLink> <http://dbpedia.org/resource/Afghanistan_Geography> .

是否可以使用一个(或多个)SPARQL查询执行此操作?

谢谢你的帮忙

sparql rdf virtuoso triplestore
2个回答
4
投票

这可以使用CONSTRUCT WHERE查询来完成:

CONSTRUCT WHERE {
    ?s rdfs:label ?label.
    ?s rdfs:comment ?comment.
    ?s ?p ?o
}

这是CONSTRUCT的简化形式,当CONSTRUCT {}部分和WHERE {}部分相同时可以使用。


2
投票

一种方法是使用DESCRIBE,例如:

DESCRIBE ?s 
WHERE {
  ?s rdfs:label ?label .
  ?s rdfs:comment ?comment .
}

或者用CONSTRUCT

CONSTRUCT { ?subject ?predicate ?object} 
WHERE {
  ?subject ?predicate ?object .
  FILTER EXISTS {
     ?subject rdfs:label ?label .
     ?subject rdfs:comment ?comment .
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.