简体   繁体   English

Sparql查询到DBpedia

[英]Sparql query to DBpedia

Can we get list of places in US from DBpedia using a SPARQL query? 我们可以使用SPARQL查询从DBpedia获得美国的地点清单吗? I have tried the following query, but it (by design) only gives the English abstracts. 我已经尝试了以下查询,但是(通过设计)它仅提供英文摘要。 I want the names of places in the US. 我想要美国的地方名称。 How can I achieve this? 我该如何实现?

SELECT ?abstract
FROM NAMED <http://dbpedia.org>
WHERE { <http://dbpedia.org/resource/Lists_of_populated_places_in_the_United_States> <http://dbpedia.org/ontology/abstract> ?abstract.
FILTER langMatches( lang(?abstract), 'en') }

It's usually easiest to write some these queries iteratively, exploring the data as you go along. 通常,最简单的方法是迭代编写一些查询,并在进行过程中探索数据。 For instance, in this case, you could start with: 例如,在这种情况下,您可以从以下内容开始:

select ?place where {
  ?place a dbpedia-owl:PopulatedPlace
}
limit 100

SPARQL results SPARQL结果

That's not just places in the United States, but you can browse the results until you find one that is. 那不仅是在美国的地方,而且您可以浏览结果,直到找到了。 Then you can examine it and see how you might identify such places. 然后,您可以检查一下,看看如何识别这些地方。 In this case, you might find Furnace, West Virginia , and note that it the value dbpedia:United_States for the property dbpedia-owl:country . 在这种情况下,您可能会找到西弗吉尼亚州的Furnace,并注意到它的属性dbpedia-owl:country的值为dbpedia: United_States Thus we can refine the query: 因此,我们可以优化查询:

select ?place where {
  ?place a dbpedia-owl:PopulatedPlace ;
         dbpedia-owl:country dbpedia:United_States 
}
limit 100

SPARQL results SPARQL结果

That's looking much better, but you said you wanted the names of the places, not the actual IRIs that identify them. 看起来好多了,但是您说过,您想要的是地方的名称,而不是标识这些地方的实际IRI。 Based on your filter, it looks like you just want the English names. 根据您的过滤器,看起来您只需要英文名称。 Then we refine further: 然后,我们进一步完善:

select ?label where {
  ?place a dbpedia-owl:PopulatedPlace ;
         dbpedia-owl:country dbpedia:United_States ;
         rdfs:label ?label
  filter langMatches( lang(?label), 'en' )
}
limit 100

SPARQL results SPARQL结果

Those names are language tagged literals. 这些名称是用语言标记的文字。 If you only want the string part, you can do that in the variable projection: 如果只需要字符串部分,则可以在变量投影中执行此操作:

select (str(?label) as ?strLabel) where {
  ?place a dbpedia-owl:PopulatedPlace ;
         dbpedia-owl:country dbpedia:United_States ;
         rdfs:label ?label
  filter langMatches( lang(?label), 'en' )
}
limit 100

SPARQL results SPARQL结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM