3

我正在尝试获取以下列表:

A人,A的出生地,B人,B的出生地

出生地是一座城市。

A 人和 B 人之间的关系是 A 人“影响”了 B 人。到目前为止,我的代码如下:

SELECT ?person ?birthplace ?influenced ?birthplace2
WHERE {
?person a <http://dbpedia.org/ontology/Person> .
?person dbpedia2:placeOfBirth ?birthplace .
?person <http://dbpedia.org/ontology/influenced> ?influenced.
?person dbpedia2:placeOfBirth ?birthplace2 .
?influenced a <http://dbpedia.org/ontology/Person>.
?country rdf:type dbpedia-owl:Country .
FILTER (str(?birthplace2) = str(?country))
FILTER (str(?birthplace) = str(?country))
}

目前我正在做国家,因为那是唯一有效的事情。

目前,这只是给了我两个具有相同出生地的列。它没有显示受影响者的出生地。

理想情况下,我还想要每个出生城市的纬度和经度,例如:

A人,A的出生地,纬度,经度,B人,B的出生地,纬度,经度

但这可能问得太多了。抱歉,我是 SPARQL 的新手。

4

1 回答 1

3

在您的查询中,您有:

?person dbpedia2:placeOfBirth ?birthplace .
?person <http://dbpedia.org/ontology/influenced> ?influenced.
?person dbpedia2:placeOfBirth ?birthplace2 .

这表示它?person出生于?birthplace?birthplace2。我想你的意思是:

?person dbpedia2:placeOfBirth ?birthplace .
?person <http://dbpedia.org/ontology/influenced> ?influenced.
?influenced dbpedia2:placeOfBirth ?birthplace2 .

至于获取每个城市的经纬度,目前 dbpedia 已关闭,因此我无法查看城市资源以了解它们如何映射到地理坐标。但是,一旦 dbpedia 备份,您可以执行 SPARQL describe 查询:

describe <http://dbpedia.org/... rest of resource URI>

看看你会得到什么。这将告诉您需要使用哪些谓词来提取该位置。请注意,如果缺少纬度/经度信息,您将不会在结果中看到该城市,除非您将选择位置的查询模式部分放在 SPARQLoptional子句中。

更新

好的,DbPedia 现在已备份。我相信这就是你想要的:

PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpedia: <http://dbpedia.org/resource/>

SELECT DISTINCT ?person1 ?birthplace1 ?person2 ?birthplace2 
                ?lat1 ?long1 ?lat2 ?long2
WHERE 
{
  ?person1 a dbpedia-owl:Person ;
           dbpedia-owl:birthPlace ?birthplace1 ;
           dbpedia-owl:influenced ?person2 .
  ?person2 dbpedia-owl:birthPlace ?birthplace2 .

  optional {
    ?birthplace1 geo:lat ?lat1 .
    ?birthplace1 geo:long ?long1 .

    ?birthplace2 geo:lat ?lat2 .
    ?birthplace2 geo:long ?long2 .
  }
}

更新 2

该查询在dbpedia/iSparql中对我有用(这是一个永久链接):

iSparql 结果

更新 3

仅限于城市:

PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpedia: <http://dbpedia.org/resource/>

SELECT DISTINCT ?person1 ?birthplace1 ?person2 ?birthplace2 
                ?lat1 ?long1 ?lat2 ?long2
WHERE 
{
  ?person1 a dbpedia-owl:Person ;
           dbpedia-owl:birthPlace ?birthplace1 ;
           dbpedia-owl:influenced ?person2 .
  ?person2 dbpedia-owl:birthPlace ?birthplace2 .

  ?birthplace1 a dbpedia-owl:City .
  ?birthplace2 a dbpedia-owl:City .

  optional {
    ?birthplace1 geo:lat ?lat1 .
    ?birthplace1 geo:long ?long1 .

    ?birthplace2 geo:lat ?lat2 .
    ?birthplace2 geo:long ?long2 .
  }
}
于 2012-07-06T20:32:58.560 回答