|
We have four official languages in Switzerland so for many data we have the same label in up to four languages available. On other data there is either no language tag assigned or it is @en. I would like to filter to the preferred language of the user and if we don't find that, either fall back to English or one with no language assigned. So far I came up with this:
This works but on some labels I now get two values back which means I have to include logic in the UI to select the best match for the user. Is there a way to do the SPARQL query in a way that it stops after the first match and returns only this one? We had an interesting discussion at #swig with several ideas but it looks pretty complex so far. |
|
Likely the best thing for you to do is to include a number of optionals and then use the
Works fine, thanks. It's a bit overhead though, would be a nice extension to SPARQL to make this easier syntax wise. @ktk What would an extension look like syntactically, if you have an idea for what that would look like I would love to see it. As the alternative solution I just posted shows there are multiple ways to do this and all are somewhat ugly. Some thinks like this are just better expressed in your code rather than in SPARQL which is primarily a declarative graph pattern matching language. @rob-vesse ah you are right I was on the wrong track, I expected it to stop in the OR when the first one matches but I didn't think that the filter has to be done for each triple. So for the english one there is no german tag and thus it does not stop evaluating. I don't have any idea for syntactic sugar right now. @ktk You may want to look at @AndyS's answer at http://answers.semanticweb.com/questions/20682/preference-patterns-for-sparql-11 for another alternative approach that is somewhat nicer than this |
|
An alternative query which would also answer your question is as follows:
This one again uses |

