GraphDB-联合查询

问题描述

我想知道如何在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会使用颜色编码)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...