Trouble getting country and D.O.B. in Wikidata SPARQL

131 Views Asked by At

I'm trying to write a SPARQL query to get the country of birth/citizenship (whichever is available) and date of birth of musical artists/members of bands. I've got a query which works fairly well, however fails in some cases because of pages with something extra added on to their name for disambiguation, eg. "(singer)" or "(musician)". Is there a more efficient and reliable way to solve this than what I've already tried?

This is my current solution, however it means that (on the second line) I have to manually write in all the possibilities (and I'm sure I'm missing some still). The query is constructed in JavaScript, so the fewer repetitions of the variable word (in this example "Queen"), the better.

SELECT ?page ?birth ?locLabel WHERE{
  {VALUES ?page {"Queen"@en "Queen (band)"@en "Queen (singer)"@en "Queen (rapper)"@en}.
  ?sitelink schema:name ?page;
            schema:isPartOf <https://en.wikipedia.org/>;
            schema:about ?item.
  OPTIONAL{?item wdt:P27 ?loc. hint:Prior hint:rangeSafe true.}
  OPTIONAL{?item wdt:P495 ?loc. hint:Prior hint:rangeSafe true.}
  OPTIONAL{?item wdt:P569 ?birth. hint:Prior hint:rangeSafe true.}
  OPTIONAL{?item wdt:P527 [wdt:P569 ?birth]. hint:Prior hint:rangeSafe true.}}
  SERVICE wikibase:label{bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".}
}

EDIT: Based on the comment below I've tried this:

SELECT ?item ?itemLabel ?birth ?locLabel WHERE {
  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:endpoint "www.wikidata.org";
                    wikibase:api "EntitySearch";
                    mwapi:search "Alan Walker";
                    mwapi:language "en".
    ?item wikibase:apiOutputItem mwapi:item. }
  FILTER(EXISTS {?item wdt:P31/wdt:P279? wd:Q215380 .} || EXISTS {?item wdt:P106/wdt:P279? wd:Q639669 .})
  OPTIONAL{?item wdt:P27 ?loc. hint:Prior hint:rangeSafe true.}
  OPTIONAL{?item wdt:P495 ?loc. hint:Prior hint:rangeSafe true.}
  OPTIONAL{?item wdt:P569 ?birth. hint:Prior hint:rangeSafe true.}
  OPTIONAL{?item wdt:P527 [wdt:P569 ?birth]. hint:Prior hint:rangeSafe true.}
  SERVICE wikibase:label{bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".}
}

However, there's two problems with this method:

  • It seems to be finding incorrect results (eg. when searching for "Alan Walker" it also returns "Alan Tyson")
  • I can't work out how to search for multiple people/groups simultaneously (essential for my use case so that I'm not making loads of API calls!)
0

There are 0 best solutions below