1

The following code queries DBpedia for places within a bounded geographic area and returns the name, lat, and long of the place. I'd also like the query to return the category of the place--e.g., park, restaurant, museum, etc.

The following code works fine.

        sparql = SPARQLWrapper("http://dbpedia.org/sparql")
        sparql.setQuery("""
        PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
        PREFIX dbo: <http://dbpedia.org/ontology/>
        PREFIX category: <http://dbpedia.org/resource/Category:>
        SELECT * WHERE {
        ?s a dbo:Place .
        ?s geo:lat ?lat .
        ?s geo:long ?long .

I tried to add the following code to get categories for places, but this doesn't work:

        ?s category:cat ?cat .

What should I add/change? Thanks.

1 Answers1

3

You can get the category of a place (assuming you mean the type) by finding the type (rdfs:type) or the subject (dcterms:subject) of a resource. In DBPedia the first relates to the DBPedia and Yago ontologies and the second is a SKOS hierarchy in DBPedia. Here is an example query:

 PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
 PREFIX dbo: <http://dbpedia.org/ontology/>
 PREFIX dcterms: <http://purl.org/dc/terms/>
        SELECT * WHERE {
        ?s a dbo:Place .
        ?s geo:lat ?lat .
        ?s geo:long ?long .
        ?s a ?type . 
        ?s dcterms:subject ?sub
} 

Note that you will get multiple types and subjects for each place.

ip.
  • 3,306
  • 6
  • 32
  • 42
  • Thanks. I actually came up with the same solution about an hour ago and when I came here to post it, I found your answer. –  Dec 02 '11 at 09:29