I have this SPARQL code that is meant to work on Wikidata:
SELECT
?game
(group_concat(distinct ?gameLabel ; separator = ", ") AS ?gameLabels)
(group_concat(distinct ?genreLabel ; separator = ", ") AS ?genreLabels)
WHERE {
?game wdt:P31 wd:Q7889;
wdt:P136 wd:Q744038.
OPTIONAL {?game wdt:P136 ?genre}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
?game rdfs:label ?gameLabel.
?genre rdfs:label ?genreLabel.
}
}
GROUP BY $game
ORDER BY ASC (?gameLabels)
You can test the code here:
Suppose that ?genreLabel
is always lower case by default. How do I capitalize the first letter of each returned value? Thanks.
That's the point where things are getting complicated with the magic label SERVICE of Wikidata because you can't use them in BIND parts - or least I don't know how:
The idea is as follows:
SUBSTR(?gL, 1, 1)
UCASE(SUBSTR(?gL, 1, 1))
SUBSTR(?gL, 2))
CONCAT(UCASE(SUBSTR(?gL, 1, 1)), SUBSTR(?gL, 2))
Note, at some point, it might be easier to do String modification and styling on the client side...