Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to use Turtle-like syntax for language filtering #17

Open
tfrancart opened this issue Apr 3, 2019 · 8 comments
Open

Ability to use Turtle-like syntax for language filtering #17

tfrancart opened this issue Apr 3, 2019 · 8 comments
Labels
query Extends the Query spec

Comments

@tfrancart
Copy link

Why ?

Currently if I want to filter a literal based on its language, I need to write:

?x skos:prefLabel ?pref .
FILTER(langMatches(lang(?pref), "fr"))

or, if I am lazy (which happens often) :

?x skos:prefLabel ?pref .
FILTER(lang(?pref) = "fr")

This is tedious for a common use-case.

How could it look like ?

I'd like to be able to use Turtle-like syntax for language filtering:

?x skos:prefLabel ?pref@fr .

Considerations for backward-compatibility

This would make the @ character a special character in variable names.

@tfrancart
Copy link
Author

Could be related to #13

@VladimirAlexiev
Copy link
Contributor

Previous work

Wikidata has a special service that returns a single label and/or description per result entity, using a list of languages, with fallback:

select ?x ?xLabel ?xDescription {
  ?x foo bar.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr,en,it". }
}

If my user lang is bg then it will look for label & descr in bg,fr,en,it in that order; if none found then it will return ?xLabel=Qnnnn


@tfrancart

  • do you want a language fallback? Eg for my Canadian clients a fallback list like 'fr-CA,fr' would be very useful
  • does this need to be put in OPTIONAL? If there's no prefLabel in fr, should it skip that result?

@cygri
Copy link

cygri commented Apr 3, 2019

In SPARQL 1.1, variable names may not contain @, so the @en syntax would not make any SPARQL 1.1 queries invalid.

One could imagine ?x@en for exact match, and ?x@~en for the langMatches logic.

Something like ?x@en,fr would be problematic as the comma could be parsed as the beginning of a comma-separated list of objects.

@tfrancart
Copy link
Author

I think my initial point was really really a point of pure syntactic sugar, to mimic Turtle syntax and have a easier learning curve for SPARQL beginners to whom we have teached Turtle already. So:

do you want a language fallback? Eg for my Canadian clients a fallback list like 'fr-CA,fr' would be very useful

I want the same behavior as langMatches()

does this need to be put in OPTIONAL? If there's no prefLabel in fr, should it skip that result?

It should skip that result if there is no prefLabel in fr. I wan the same behavior as when using a FILTER with langMatches().

One could imagine ?x@en for exact match, and ?x@~en for the langMatches logic.

I like that idea.

@VladimirAlexiev
Copy link
Contributor

langMatches() is not a fallback: ?x@~fr will return all labels in fr, fr-CA, fr-FR etc.

A fallback would pick one value. This is what SERVICE wikibase:label does, and what #13 asks for. To do that with the current proposal would need something like:

optional {?x skos:prefLabel ?label_fr_CA@fr-CA}
optional {?x skos:prefLabel ?label_fr@fr}
bind(coalesce(?label_fr_CA,?label_fr) as ?label)

with the inefficiency that all wanted languages are fetched, not just the first one matching.

@jindrichmynarz
Copy link

In case preference order in language tags is desired, would a similar syntax as in the Accept-Language HTTP header do?

@joernhees
Copy link

this is definitely intertwined with #13

a practial remark though: langMatches(lang(?l), "en") is (currently) a lot slower than lang(?l) = "en" in many implementations :-/

@tfrancart
Copy link
Author

@VladimirAlexiev

A fallback would pick one value. This is what SERVICE wikibase:label does, and what #13 asks for.

I did not ask for a fallback mechanism; this is, as you wrote, what #13 asks for, and this is a difference with this issue. The 2 issues are related, but not the same (but it could turn out they are solved by some simultaneously). Again, this issue here is really syntactic : I want the same syntax than Turtle for language filtering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
query Extends the Query spec
Projects
None yet
Development

No branches or pull requests

6 participants