如何在sparql查询中获取资源的值,该资源是另一个资源的属性

时间:2014-04-01 15:21:04

标签: sparql dbpedia spotlight-dbpedia sparqlwrapper

如何从此查询中获取首都城市的值名称而不是URI

SELECT ?capital 
WHERE { <http://dbpedia.org/resource/Germany><http://dbpedia.org/ontology/capital> ?capital}

在上面的查询中,我得到了德国首都的URI .ie   http://dbpedia.org/resource/berlin 怎么能得到只有柏林而不是它的URI

1 个答案:

答案 0 :(得分:3)

您想要的值实际上是RDFS标签属性的值。如果您使用的是public DBpedia SPARQL endpoint,那么您可以使用如下查询:

select ?label where {
  dbpedia:Germany dbpedia-owl:capital/rdfs:label ?label .
  filter langMatches(lang(?label),"en")
}

属性路径dbpedia-owl:capital/rdfs:label意味着您将获得德国首都,然后获得该标签。 filter表达式允许您仅选择资源的英文标签。当然,您可以删除此过滤器,但是您将获得多个结果,因为该资源具有不同语言的标签。