问题描述
我想知道如何在GraphDB上执行联合搜索。例如,要在GraphDB中插入以下代码,该怎么办?想法是将下面的内容添加到我的本地GraphDB中。
#Locations of air accidents in wikidata - https://query.wikidata.org/
SELECT ?label ?coord ?place
WHERE
{
?subj wdt:P31 wd:Q744913 .
?subj wdt:P625 ?coord .
?subj rdfs:label ?label
filter (lang(?label) = "en")
}
解决方法
发布@UninformedUser的评论作为更好的可读性的答案。
SPARQL 1.1提供了here所述的SERVICE
功能。您可以使用它直接在GraphDB内部对Wikidata执行联合查询。
SELECT * WHERE {
SERVICE <https://query.wikidata.org/sparql> {
?subj wdt:P31 wd:Q744913 ;
wdt:P625 ?coord ;
rdfs:label ?label
FILTER (lang(?label) = "en")
}
}
,
要将数据插入到本地GraphDB中,请使用以下命令:
INSERT {
?subj wdt:P31 wd:Q744913 ;
wdt:P625 ?coord ;
rdfs:label ?label
} WHERE {
SERVICE <https://query.wikidata.org/sparql> {
?subj wdt:P31 wd:Q744913 ;
wdt:P625 ?coord ;
rdfs:label ?label
FILTER (lang(?label) = "en")
}
}
但是,您可能希望解开坐标并使用一些更易于理解的本体,例如:
PREFIX wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#> # see http://prefix.cc/wgs.sparql
INSERT {
?subj a :AirAccident;
wgs:lat ?lat; wgs:long ?long;
rdfs:label ?label
} WHERE {
SERVICE <https://query.wikidata.org/sparql> {
?subj wdt:P31 wd:Q744913 ;
p:P625/psv:P625 [wikibase:geoLatitude ?lat; wikibase:geoLongitude ?long];
rdfs:label ?label
FILTER (lang(?label) = "en")
}
}
有关p:P625,psv:P625,wikibase:geoLatitude
的内容,请参见https://github.com/nichtich/wdq#wikidata-ontology(如果安装了该文件,则wdq help ontology
会使用颜色编码)