Search code examples
sparqldbpedia

SPARQL: selecting people by country


I am trying to select all people born in a specific country (e.g. Portugal) from DBPedia.

I could use this query:

         SELECT DISTINCT ?person   
         WHERE {
            ?person dbpedia-owl:birthPlace dbpedia:Portugal.
          }

But the problem is that not all people have dbpedia:Portugal as birthPlace. About 30% of people have just a town name as birthPlace, e.g.

       dbpedia:Lisbon

I could add all Portugal cities in a FILTER clause but it's a big list.

May be it's possible to infer Portugal from Lisbon in the SPARQL query somehow?

(to not to add all Portugal cities in FILTER to get ALL persons)


Solution

  • If we assume all the cities in a specific country are defined as part of that country in dbpedia, you could have a query that first looks for the people that have dbpedia:Portugal as a country and then cities within dbpedia:Portugal.

    SELECT DISTINCT ?person
    WHERE {
        ?person a dbpedia-owl:Person.
    Optional{
        ?person dbpedia-owl:birthPlace ?country.
    }
    Optional{
        ?person dbpedia-owl:birthPlace ?place.
        ?place dbpedia-owl:country ?country
    }
    filter(?country= dbpedia:Portugal)
    }
    

    The query that you have written identifies 1723 distinct URIs, and this finds 2563 URIs.