2

Note: This question is different from SPARQL query to retrieve countries population from DBpedia. This question is about population density as understood by DBPedia itself.

How can I retrieve country population density from DBPedia?

I have tried the following, but Virtuoso endpoint returns an empty result set:

PREFIX p: <http://dbpedia.org/property/>
SELECT DISTINCT ?name ?populationDensity
WHERE {
    ?country a dbpedia-owl:Country . 
    ?country rdfs:label ?name . 
    ?country p:populationDensity ?populationDensity . }
Community
  • 1
  • 1
Veronica
  • 280
  • 2
  • 12

1 Answers1

3

Your current query returns an empty table because there is no ?country that fulfills your query that has the rdf:type dbpedia-owl:Country (represented by 'a'). Check that with this query.

To find the list of rdf:type's that the set of data that does use your populationDensity you could use this query. Following that lead you can just check all properties for Portugal and find that it does have populationDensity, but not the one you used.

This works:

PREFIX dbpedia-ont-PP: <http://dbpedia.org/ontology/PopulatedPlace/>
SELECT DISTINCT ?country ?populationDensity
WHERE {
    ?country a dbpedia-owl:Country .
    ?country dbpedia-ont-PP:populationDensity ?populationDensity . 
}
Spork
  • 1,631
  • 1
  • 21
  • 37
  • Just a note: we'd usually use the dbpedia-owl: prefix for properties beginning with `http://dbpedia.org/ontology/`. Unfortunately, in this case, there's another `/` in the IRI, so we'd have to write `dbpedia-owl:PopulatedPlace/populationDensity` which isn't legal (it would be ambiguous with the property path notation). The options are either to use another prefix (as done here), or to write the IRI out in full. – Joshua Taylor Sep 12 '14 at 14:36
  • Yeah I always defined another prefix when I ran into that... pretty terrible design that this type of workaround is necessary, to be honest. – Spork Sep 12 '14 at 15:27
  • 1
    there's some discussion of it around [this question](http://stackoverflow.com/q/25547212/1281433). – Joshua Taylor Sep 12 '14 at 16:00