[英]How to extract RDF triples with specific predicates using sparql
I uploaded a set of RDF triples onto a local Virtuoso endpoint. 我将一组RDF三元组上传到本地Virtuoso端点。
Of all these triples, I would like to extract only those whose subjects have at least the predicates http://www.w3.org/2000/01/rdf-schema#label and http://www.w3.org/2000/01/rdf-schema#comment . 在所有这些三元组中,我只想提取那些主题至少具有谓词http://www.w3.org/2000/01/rdf-schema#label和http://www.w3.org/2000的主题/ 01 / rdf-schema#comment 。
For example, from these triples: 例如,从这些三元组中:
<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> .
I would like to get: 我想得到:
<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> .
Is it possible to do this with one (or more) SPARQL query? 是否可以使用一个(或多个)SPARQL查询来做到这一点?
Thank you for helping 感谢您的帮助
This can be done with a CONSTRUCT WHERE
query: 这可以通过
CONSTRUCT WHERE
查询来完成:
CONSTRUCT WHERE {
?s rdfs:label ?label.
?s rdfs:comment ?comment.
?s ?p ?o
}
This is a simplified form of CONSTRUCT
that can be used when the CONSTRUCT {}
part and the WHERE {}
part are identical. 这是
CONSTRUCT
的简化形式,可以在CONSTRUCT {}
部分和WHERE {}
部分相同时使用。
One way is to use DESCRIBE
, eg: 一种方法是使用
DESCRIBE
,例如:
DESCRIBE ?s
WHERE {
?s rdfs:label ?label .
?s rdfs:comment ?comment .
}
or alternatively with CONSTRUCT
: 或者使用
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.