2

Want to extract Bob Dylan pseudonyms. His Wikidata page is https://www.wikidata.org/wiki/Q392

One way is to walk the following tree and parse value for P742 (pseudonym): https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q392&format=json

But that's a lot of work and specific to Bob Dylan; other people with pseudonyms may have a different JSON structure.

This query works for his awards:

SELECT ?item ?itemLabel ?linkTo ?linkToLabel {
  ?item wdt:P166 wd:Q37922 ;
        wdt:P910 wd:Q8064684 .
  OPTIONAL {
    ?item wdt:P166 ?linkTo ;
            wdt:P31 wd:Q5 } .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

as seen here

The weakness is it uses the combination of "topic's main category" (P910) and the target "category" (Q8064684) to specify "Bob Dylan".

For that query, I can't find the method to use his QID (Q392).

I do not want to text search, as is proposed in Group concat not working, because there is more than one Bob Dylan. And many people with pseudonyms will not have a category, so that technique cannot be generalized.

This query works for occupations and uses his QID (Q392), not the Bob Dylan category (Q8064684) from the "awards" query.

SELECT * {
  SERVICE <https://query.wikidata.org/sparql> {
    wd:Q392 wdt:P31 wd:Q5 ;
            wdt:P106 ?occupation
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "en" .
      ?occupation rdfs:label ?label
    }
  }
}

as seen here

but I cannot find the right SPARQL query to select pseudonyms (which are text) as seen here: https://www.wikidata.org/wiki/Q392

How to write a Wikidata SPARQL query that uses a person's identifier (e.g. Q392 for Bob Dylan) and can be configured (easily toggled) to select either "award received" (P166), "occupations" (P106) or "pseudonym" (P742)?

TallTed
  • 9,069
  • 2
  • 22
  • 37
Jay Gray
  • 1,706
  • 2
  • 20
  • 36
  • 1
    Another user confused by [truthy](https://www.mediawiki.org/wiki/Wikibase/Indexing/RDF_Dump_Format#Truthy_statements) statements... – UninformedUser Jan 04 '19 at 17:12
  • 3
    see the ranking of the statements, "best" is preferred: `SELECT * { SERVICE { wd:Q392 wdt:P31 wd:Q5 ; p:P742 ?statement. ?statement ps:P742 ?value . ?statement wikibase:rank ?rank . OPTIONAL { ?statement a ?best . } } }` – UninformedUser Jan 04 '19 at 17:13
  • 1
    So you can always use the query above to get all the data, not just the preferred one. Credits for the query go to StanislavKralin by the way ([source](https://stackoverflow.com/questions/47100068/some-cities-arent-instances-of-city-or-big-city-odd-behaviour-of-wikidata)) – UninformedUser Jan 04 '19 at 17:14
  • yes, i did not know how to handle statements or truthy statements. let me study your comment to make sure i understand and can put it to work - be back to you. – Jay Gray Jan 04 '19 at 17:22
  • it's not that difficult. just use the properties `p:PXXX' and `ps:PXXX' instead of 'wdt:PXXX` – UninformedUser Jan 04 '19 at 18:14
  • 1
    @AKSW please post your answer and i will accept it – Jay Gray Jan 04 '19 at 19:48

0 Answers0