3

I am having an issue when concatenating in SPARQL using the Wikidata Query Service. https://query.wikidata.org/

What I want to do is retrieve all persons with a GTAA ID (?q wdt:P1741 ?GTAA_ID.) and specifically persons who have an occupation listed in Wikidata. (?q wdt:P106 ?occupation.) Furthermore, I want these occupations to be concatenated into a single row, separated by ", ".

What I am getting as of now is the name of the person in the first column, and in the second column their occupations. However, these occupations are listed as URLs to the corresponding Wikidata page. What I want is for these URLs to be displayed as Labels (the text corresponding to the Wikidata Page)

This is the code I have so far:

SELECT 
  ?qLabel 
  (group_concat(DISTINCT ?occupation;separator=", ") as ?occupations ) 
WHERE
  {
    ?q wdt:P1741 ?GTAA_ID.
    ?q wdt:P106 ?occupation.
    SERVICE wikibase:label { bd:serviceParam wikibase:language "
    [AUTO_LANGUAGE]". }
  }

  GROUP BY ?qLabel

So instead of returning for example:

Ludwig van Beethoven | http://www.wikidata.org/entity/Q36834

I would like it to return:

Ludwig van Beethoven | composer

logi-kal
  • 7,107
  • 6
  • 31
  • 43
John
  • 61
  • 3
  • 3
    Was already asked and answered here [yesterday](https://stackoverflow.com/questions/48855767/group-concat-not-working). It looks like it's some university exercise...`SELECT ?qLabel (group_concat(DISTINCT ?occupationLabel;separator=", ") as ?occupations ) WHERE { ?q wdt:P1741 ?GTAA_ID. ?q wdt:P106 ?occupation. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". ?q rdfs:label ?qLabel . ?occupation rdfs:label ?occupationLabel . } } GROUP BY ?q ?qLabel` – UninformedUser Feb 20 '18 at 10:18
  • Possible duplicate of [Group concat not working](https://stackoverflow.com/questions/48855767/group-concat-not-working) – chrisis Feb 20 '18 at 12:58

0 Answers0