繁体   English   中英

如何使用Sparql使用特定谓词提取RDF三元组

[英]How to extract RDF triples with specific predicates using sparql

我将一组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查询来做到这一点?

感谢您的帮助

这可以通过CONSTRUCT WHERE查询来完成:

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

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

一种方法是使用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 .
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM