dbpedia SPARQL query to get certain value's for a given city

落花浮王杯 提交于 2019-12-06 03:48:05

This query is working

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 :

  • No country code for Thailand : you can use rdfs:label "Thailand"@en instead.
  • rdf:type of Bangkok is not schema:City but dbpedia-owl:Settlement

Here is a working query for Bangkok

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' )
}

I guess you want something like this:

SELECT * WHERE {
  ?x rdfs:label "New York City"@en.
  ?x dbpedia-owl:populationTotal ?pop.
  ?x dbpedia-owl:abstract ?abstract.
}

To get only the English abstract, add a FILTER:

SELECT * WHERE {
  ?x rdfs:label "New York City"@en.
  ?x dbpedia-owl:populationTotal ?pop.
  ?x dbpedia-owl:abstract ?abstract.
  FILTER (LANG(?abstract) = 'en')
}

“New York” is the state and it doesn't have a populationTotal figure attached. “New York City” is the city.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!