查询dbpedia在SPARQL中询问两个类别的出生地

时间:2012-07-06 06:28:35

标签: sparql wikipedia dbpedia

我想获得一个清单:

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

出生地是一个城市。

A人与B人之间的关系是那个人“受影响”的人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,Lat,Long,B人的诞生地,B,Lat,Long的诞生地

但这可能太多了。对不起,我是SPARQL的新手。

1 个答案:

答案 0 :(得分: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 <http://dbpedia.org/... rest of resource URI>

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

<强>更新

好的,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(此处为perma-link):

iSparql results

更新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 .
  }
}
相关问题