I have a list of names (hundreds of them) that are already transformed to Q-numbers in wikidata using python. For each Q-number (person) I want to get some basic information such as place_of_birth, nationality, etc.
SELECT DISTINCT ?name ?nameLabel ?genderLabel ?placeofbirth ?nationality (year(?birthdate) as ?birthyear) (year(?deathdate) as ?deathyear)
WHERE
{
?name wdt:P106/wdt:P279* wd:Q1028181 # painter
FILTER (?name IN (wd:Q2674488)) # James Seymour
OPTIONAL { ?name wdt:P569 ?birthdate. }
OPTIONAL { ?name wdt:P27 ?nationality. }
OPTIONAL { ?name wdt:P21 ?gender. }
OPTIONAL { ?name wdt:P19 ?placeofbirth. }
OPTIONAL { ?name wdt:P570 ?deathyear. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
Using SPARQL, I can search two or three people at a time by adding Q-numbers into "FILTER", but how can I loop through all Q-numbers in a python list? Thanks a lot!