- From: Vladimir Alexiev via GitHub <noreply@w3.org>
- Date: Thu, 16 Apr 2026 12:51:40 +0000
- To: public-shacl@w3.org
VladimirAlexiev has just created a new issue for https://github.com/w3c/data-shapes:
== language preferencing in node expressions ==
Given a multilingual (langString) property, how can a node expression get one or several values depending on language preferences?
- https://github.com/w3c/data-shapes/issues/855: split from here
>> class with `rdfs:label "pylon"@en, "tragwerk"@de` -> URL `ex:Tragwerk` in a German-based ontology.
>> This is an actual case from Swissgrid. Labels are trilingual but their engineering has standardized on German localnames.
> @HolgerKnublauch: this example with labels in multiple languages wouldn't quite work because it's unclear how to pass those multiple labels into a node expression.
related to
- HTTP Accept-Language,
- SPARQL `langMatches`,
- SHACL `sh:inLanguage`,
- SHEX `@` features
Links to prior art or discussions:
sparq-dev issues
- https://github.com/w3c/sparql-dev/issues/13, with lots of prior art and implementation ideas
- https://github.com/w3c/sparql-dev/issues/17
The best way to do this in current SPARQL is with this trick: the first OPTIONAL that matches, binds the variable, so the rest cannot succeed.
For a list of places, get the first of their names in preference order `bg,de,en,fr,ru,ANY`:
```sparql
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
select * {
values ?x {wd:Q472 wd:Q407198 wd:Q45625 wd:Q129632 wd:Q287380 wd:Q47187}
OPTIONAL { ?x rdfs:label ?xLabel . FILTER (lang(?xLabel) = 'bg') }
OPTIONAL { ?x rdfs:label ?xLabel . FILTER (lang(?xLabel) = 'de') }
OPTIONAL { ?x rdfs:label ?xLabel . FILTER (lang(?xLabel) = 'en') }
OPTIONAL { ?x rdfs:label ?xLabel . FILTER (lang(?xLabel) = 'fr') }
OPTIONAL { ?x rdfs:label ?xLabel . FILTER (lang(?xLabel) = 'ru') }
OPTIONAL { ?x rdfs:label ?xLabel }
}
```
---
Syntactic variants. I'm not suggesting SHACL should adopt them, but just showing the range of possible needs.
ShEx features:
- LanguageStem spec: http://shex.io/shex-semantics/index.html#values
- primer example: http://shex.io/shex-primer/#sec-iri-range
- semantic tests: https://github.com/shexSpec/shexTest/blob/master/validation/manifest.ttl#L10348-L11490
Graphwise Semantic Objects (SOML): borrows features from the above, and features exact matching, prefix matching, exclusions.
- [queries.html#language-preference-for-langstring-properties](https://platform.ontotext.com/semantic-objects/5.0/soml/queries.html#language-preference-for-langstring-properties)
- [tutorials/graphql-query.html#graphql-query-tutorial-filtering-literal-values](https://platform.ontotext.com/semantic-objects/5.0/tutorials/graphql-query.html#graphql-query-tutorial-filtering-literal-values)
- [tutorials/graphql-query.html#langstring-ordering](https://platform.ontotext.com/semantic-objects/5.0/tutorials/graphql-query.html#langstring-ordering)
By default SOML gets one label (but see the last example). eg
- `en,en~`: pure English, then any English dialect
- `en~,-en-US`: any English, as long as it's not Trump's language (Orange Man in a White House-ish)
- `NONE,en`: first no lang, then English
- `BROWSER,en~,~,ANY`: first user's `Accept-Language` prefs, then any English, then any non-empty lang, then any lang whatsoever
- `ALL:en~,fr~`: all English or French labels, or their dialects
Please view or discuss this issue at https://github.com/w3c/data-shapes/issues/859 using your GitHub account
--
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Thursday, 16 April 2026 12:51:40 UTC