Travis
Travis

Reputation: 1826

How can I search for a person who goes by a pseudonym in Wikidata SPARQL?

So I have the following wikidata SPARQL that will grab basic biographical information on a person. If I provide it a pseudonym such as (Madonna, Cher, Beyonce) it will timeout on me every time. Of course if I provide an actual name, such as "Harrison Ford" or "Tom Cruise" it works great. The problem line is this

?person rdfs:label "Madonna"@en.

Here is the entire query

SELECT ?person ?personLabel ?birthdate (GROUP_CONCAT(DISTINCT ?occupationLabel_en; separator=", ") as ?occupations) ?birthPlaceLabel 
?image (GROUP_CONCAT(DISTINCT ?spouseLabel_en; separator=", ") as ?spouses) 
?familyLabel ?familyDescription ?qid
WHERE {
  ?person wdt:P31 wd:Q5. # Select instances of humans
  ?person rdfs:label "Madonna"@en.

  OPTIONAL { ?person wdt:P569 ?birthdate. } # Retrieve birthdate
  OPTIONAL { ?person wdt:P106 ?occupation. } # Retrieve occupation
  OPTIONAL { ?person wdt:P19 ?birthPlace. } # Retrieve place of birth
  OPTIONAL { ?person wdt:P18 ?image. } # Retrieve image

  OPTIONAL {
    ?occupation rdfs:label ?occupationLabel_en.
    FILTER(LANG(?occupationLabel_en) = "en")
  }

  OPTIONAL {
    ?person wdt:P26 ?spouse.
    ?spouse rdfs:label ?spouseLabel_en.
    FILTER(LANG(?spouseLabel_en) = "en")
  }

  OPTIONAL { ?person wdt:P22 ?family. } # Retrieve family info
  BIND(STR(?person) AS ?qid) # Retrieve Wikidata QID

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?person ?personLabel ?birthdate ?birthPlaceLabel ?image ?familyLabel ?familyDescription ?qid
LIMIT 1

Here is the SPARQL Query if you want to see it in action. Of course if I change the SPARQL to search for the QID, it will work, but a user isn't going to know that.

I do know of a solution, and that would be to get the QID of the person from a SPARQL query, and then perform yet another SPARQL query on that QID, but I'm really trying to avoid that. If the solution I propose is the only way to search for a person who goes by a pseudonym, then I guess it is what it is. Let me know that.

Upvotes: 2

Views: 72

Answers (0)

Related Questions