dbpedia SPARQL查询以获取给定城市的某些值 [英] dbpedia SPARQL query to get certain value's for a given city
问题描述
我确定我想做的事很简单,但似乎无法正确查询。我在数据集中有诸如城市名称之类的值的记录。 纽约及其相应的国家/地区代码,例如美国。我还可以访问完整的国家名称和国家/地区ISO代码。
I am sure what I want to do is very easy, yet I cannot seem to get the query right. I have records in dataset which have values such as city name e.g. 'New York' and it's corresponding country code e.g 'US'. I also have access to the full country name and country ISO codes.
我想通过使用where子句获取dbpedia上这些城市的人口和抽象值。例如:
I would like to get the population and abstract value's for these cities off dbpedia, by using a where clause such as:
Get population where name = "New York" and isoCountryCode = "US"
我一直在寻求帮助,但无济于事。
I've searched for help on this to no avail.
@rohk在此查询中对我有所帮助,该查询不适用于所有位置:
so far I have been kindly helped by @rohk with this query, which does not fully work for all locations:
SELECT DISTINCT ?city ?abstract ?pop
WHERE {
?city rdf:type schema:City ;
rdfs:label ?label ;
dbpedia-owl:abstract ?abstract ;
dbpedia-owl:country ?country ;
dbpedia-owl:populationTotal ?pop .
?country dbpprop:countryCode "USA"@en .
FILTER ( lang(?abstract) = 'en' and regex(?label, "New York City"))
}
以上内容适用于纽约,但是当我将其更改为:
The above works for New York, however when I change it to:
SELECT DISTINCT ?city ?abstract ?pop
WHERE {
?city rdf:type schema:City ;
rdfs:label ?label ;
dbpedia-owl:abstract ?abstract ;
dbpedia-owl:country ?country ;
dbpedia-owl:populationTotal ?pop .
?country dbpprop:countryCode "THA"@en .
FILTER ( lang(?abstract) = 'en' and regex(?label, "Bangkok"))
}
它不会返回泰国曼谷的结果。
It returns no results for Bangkok, Thailand.
我似乎无法正确获得SPARQL查询,我敢肯定我的查询很傻。如果有上师可以为我提供帮助,我将不胜感激。谢谢!
I just cant seem to get the SPARQL query correct, I'm sure I am being silly with my query. If any guru's could provide me with help I'd appreciate it. Thanks!
推荐答案
此查询正在运行
SELECT DISTINCT *
WHERE {
?city rdf:type schema:City ;
rdfs:label ?label ;
dbpedia-owl:abstract ?abstract ;
dbpedia-owl:country ?country ;
dbpprop:website ?website ;
dbpedia-owl:populationTotal ?pop .
?country dbpprop:countryCode "USA"@en .
FILTER ( lang(?abstract) = 'en' and regex(?label, "New York City"))
}
编辑:对于曼谷来说,有两个问题:
EDIT : For Bangkok, there are 2 problems :
- 泰国没有国家/地区代码:您可以使用
rdfs:label Thailand @en
代替。 -
rdf:type $ c曼谷的$ c>不是
schema:City
,而是dbpedia-owl:Settlement
- No country code for Thailand : you can use
rdfs:label "Thailand"@en
instead. rdf:type
of Bangkok is notschema:City
butdbpedia-owl:Settlement
以下是曼谷的有效查询
SELECT DISTINCT *
WHERE {
?city rdf:type dbpedia-owl:Settlement ;
rdfs:label "Bangkok"@en ;
dbpedia-owl:abstract ?abstract ;
dbpedia-owl:populationTotal ?pop ;
dbpedia-owl:country ?country ;
dbpprop:website ?website .
?country rdfs:label "Thailand"@en .
FILTER ( lang(?abstract) = 'en' )
}
这篇关于dbpedia SPARQL查询以获取给定城市的某些值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!