0

I want to retrieve from DBpedia all the states and territories in India as well as all the cities contained in them. I have a long query that does a UNION and returns the territories but not any states or cities. For brevity, I'm just including the part of the query that should return states and cities and I'm not including any prefixes:

SELECT ?state ?stateLabel ?city ?cityLabel
WHERE {{?state rdf:type dbo:State ;
            rdfs:label ?stateLabel ;
            dbo:country dbr:India.
     FILTER (lang(?stateLabel) = "en")}
   OPTIONAL {?city rdf:type dbo:City ;
           rdfs:label ?cityLabel ;
           dbo:isPartOf ?state .
     FILTER (lang(?cityLabel) = "en")}}

This query returns no results when I execute it (with the prefixes) at: https://dbpedia.org/sparql/ The part of the query that works looks identical to the state query except it matches for dbo:AdministrativeRegion rather than for dbo:State. It seems to return all the Indian territories (but none of the cities in them).

In addition I could use some pointers on where to find good documentation about the DBpedia ontology for similar queries. All of the documentation I've found either explains things I already know (e.g., what Linked Data is) or that I don't care about (e.g., how DBpedia scrapes data from Wikipedia).

  • Your query looks correct and should return all states and cities in India. However, you might want to try modifying the query slightly by adding the optional clause for cities outside of the curly braces for states. – Noor Fahad Apr 20 '23 at 04:30
  • 1
    there is no `dboState` class assigned to any India state. I'd not use DBpedia to be honest, the geographical data quality is rather cumbersome, incomplete and most often even impossible to handle. With Wikidata you would get all the current 28 states more easily: `select ?s ?sLabel { ?s p:P31 ?stmt . ?stmt ps:P31 wd:Q12443800 . ?s wdt:P17 wd:Q668 . FILTER NOT EXISTS {?stmt pq:P582 ?end} FILTER NOT EXISTS {?s wdt:P1366|wdt:P576 ?some} SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }` – UninformedUser Apr 20 '23 at 09:06
  • is it mandatory to use DBpedia? – UninformedUser Apr 20 '23 at 09:06
  • Thanks. It's not at all mandatory to use DBpedia. I'm very familiar with SPARQL but this is the first time I've tried using Linked Data and DBpedia is what I've heard the most about so I tried using it. I had a feeling there was some issue with the states. Someone else suggested I use Geonames which I just started working with yesterday. I really appreciate the Wikidata example. I will use it or Geonames. – Michael DeBellis Apr 21 '23 at 14:03

0 Answers0