I've written a query without using group_concat and get 9 rows returned, one row for each occupation that Einstein held.
When I add group_concat on the occupation column, that column is null. I don't understand what I'm doing wrong here. What I expect to see is 1 row with all 9 occupations in the occupations column.
Here is the simple query.
SELECT ?item ?itemLabel ?genderLabel (GROUP_CONCAT(?occupationLabel) AS ?occupations)
WHERE {
?item wdt:P31 wd:Q5.
?item ?label "Albert Einstein"@en.
?item wdt:P21 ?gender .
?item wdt:P106 ?occupation .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?item ?itemLabel ?genderLabel
EDIT:
Here is the code that is producing the duplicate values.
SELECT ?item ?itemLabel ?genderLabel (GROUP_CONCAT(?occupationLabel) AS ?occupations)
WHERE {
?item wdt:P31 wd:Q5.
?item ?label "Albert Einstein"@en.
?item wdt:P21 ?gender .
OPTIONAL {
?item wdt:P106 ?occupation .
?occupation rdfs:label ?occupationLabel
FILTER(LANGMATCHES(LANG(?occupationLabel), 'en'))
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?item ?itemLabel ?genderLabel
Running this query gives me the following:
professor professor physicist physicist inventor educationalist educationist university teacher academic science writer non-fiction writer philosopher of science theoretical physicist
professor and physicist are duplicated
2nd EDIT
Also worth noting is that when I modify the query to not use rdfs:label
, I get the right concated result in the occupation column (I've added the parentheses and the labels to the URL):
http://www.wikidata.org/entity/Q121594 (professor)
http://www.wikidata.org/entity/Q169470 (physicist)
http://www.wikidata.org/entity/Q205375 (inventor)
http://www.wikidata.org/entity/Q1231865 (educationalist)
http://www.wikidata.org/entity/Q1622272 (university teacher)
http://www.wikidata.org/entity/Q3745071 (science writer)
http://www.wikidata.org/entity/Q15980158 (non-fiction writer)
http://www.wikidata.org/entity/Q16389557 (philosopher of science)
http://www.wikidata.org/entity/Q19350898(theoretical physicist)
So, I guess my question now is, is it possible to get one label per ID?