In a Wikidata SPARQL query such as the following, I want to be able to use a custom delimiter for the returns for ?placeOfBirthAltLabel
.
The problem is that some values under ?placeOfBirthAltLabel
contain commas
e.g. synonyms for "New York" include "New York, USA" as a single entry.
However, as the returns are comma delimited, this single entry will be parsed as two separate strings.
So in other words I need the return to be [New York, USA ; NYC ; NYC, USA ] as opposed to [New York, USA, NYC, NYC, USA]
SELECT ?item ?itemLabel ?placeOfBirthLabel ?placeOfBirthAltLabel
WHERE
{
?item wdt:P106 wd:Q10833314.
OPTIONAL { ?item wdt:P19 ?placeOfBirth }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
LIMIT 100
Thanks!
You do not need to parse alternative labels. Their values are concatenated by the label service. Just do not use the label service for alternative labels:
Try it!
If you still want to parse... The comma is hardcoded, use grouping and
GROUP_CONCAT
with custom separator instead:Try it!
Be carefull with variables projected by the label service. For example,
should work, whereas
shouldn't.