SPARQL: selecting people by country

1.7k views Asked by At

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)

3

There are 3 answers

4
Artemis On BEST ANSWER

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.

0
GML-VS On

Full results may be achieved by this http://answers.semanticweb.com/questions/22450/sparql-selecting-people-by-country - 2730 persons

   PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
   PREFIX dbpedia: <http://dbpedia.org/resource/>

   SELECT ?person
    WHERE
      {   
             {?person a <http://dbpedia.org/ontology/Person>;
              <http://dbpedia.org/ontology/birthPlace> ?place.
              ?place <http://dbpedia.org/ontology/country> ?birthCountry.
              ?birthCountry a <http://dbpedia.org/ontology/Country>.
              FILTER (?birthCountry = dbpedia:Portugal).
              }
          UNION
              { ?person a <http://dbpedia.org/ontology/Person>;
              <http://dbpedia.org/ontology/birthPlace> ?birthCountry.
               ?birthCountry a <http://dbpedia.org/ontology/Country>.
              FILTER (?birthCountry = dbpedia:Portugal).
              }
          }
      GROUP BY ?person
      ORDER BY ?person
6
Joshua Taylor On

Artemis' answer works, but it's very verbose for what's a pretty simple query. It can be simplified to:

select distinct ?person where {
  ?person a dbpedia-owl:Person ;
          dbpedia-owl:birthPlace/dbpedia-owl:country? dbpedia:Portugal
}

SPARQL results (2449)