Search code examples
sparqldbpedia

Finding corresponding State for POIs using skos:broader


I am trying to collect POIs per State in the United States. The original query was

select distinct ?s ?state 
where { 
?s a dbpedia-owl:Place; dcterms:subject/skos:broader{,9} ?state . 
?state skos:broader  category:Buildings_and_structures_in_the_United_States_by_state . 
filter contains(str(?state),'_in_') . 
filter(!contains(str(?state),'United_States')) 
 }

The filter portion was to find the US states(shown below) such that, at the end we know each POI belongs to what state.

enter image description here

The approach did not work as I got multiple states for one POI. As an example if I run the following query to find the US State for Pentagon

select distinct ?state 
where { 
dbpedia:The_Pentagon dcterms:subject/skos:broader{,9} ?state . 
?state skos:broader  category:Buildings_and_structures_in_the_United_States_by_state . 
filter contains(str(?state),'_in_') . 
filter(!contains(str(?state),'United_States'))  
}

It would result Pentagon being in all states. I know this is due skos:broader{,9} but how do I know, the optimum level to set it for. Is there a better approach?


Solution

  • I am not sure what exactly you are trying to achieve with your queries, I can't get my head around them. But based on your description, I think you just need places of interest alongside the states they are in. If that is the case, I have written the following query.

    SELECT distinct ?POI ?state WHERE {
        ?POI a dbpedia-owl:Place.
        ?POI dbpedia-owl:location ?location.
        ?location dbpedia-owl:country ?country.
        ?location dbpprop:state ?state.
        filter(?country =dbpedia:United_States)
    }
    

    If you want, you can even go further and describe the place as a building, but I don't think POIs are necessarily buildings. But if you want to name them as buildings, then:

    SELECT distinct ?POI ?state WHERE {
        ?POI a dbpedia-owl:Place.
        ?POI a dbpedia-owl:Building.
        ?POI dbpedia-owl:location ?location.
        ?location dbpedia-owl:country ?country.
        ?location dbpprop:state ?state.
        filter(?country =dbpedia:United_States)
    }
    

    To show the use case, you can filter the ?POI for Pentagon:

    SELECT distinct ?POI ?state WHERE {
        ?POI a dbpedia-owl:Place.
        ?POI a dbpedia-owl:Building.
        ?POI dbpedia-owl:location ?location.
        ?location dbpedia-owl:country ?country.
        ?location dbpprop:state ?state.
        filter(?country =dbpedia:United_States)
        filter(?POI=dbpedia:The_Pentagon)
    }