Aldo Bucchi wrote:
> Hi,
> 
> This is a BIG feature request, but it is something that I use daily
> via generators and I think we should bring it down into SPARQL itself
> as it accounts for a very common usecase.
> Of course I could try to write and push this into the next SPARQL
> recommendation, but then it would eventually circle back to you guys
> to see if you can implement it... So I guess the other way around
> makes more sense ;)
> 
> The basic idea:
> 
> * There is a way to declare a global list of languages alongside a
> query of arbitrary complexity
> * These will be implicitly used to discern which literals to return
> * The filtering is a bit more complex than a mere filter() as the list
> imposes an "order of preference" amongst languages
> 
> So a sample query may look like this:
> 
> sparql
> define lang "en-US,en,de,*"
> select ?label where { ?something rdfs:label ?label }
> 
> Implicitly, the literals ( in this case ?label ) will be matched
> against the languages defined in the pragma and the match with the
> highest preference will be returned ( if any ).
> 
> This is analog to having an ordered set of UNION'ed clauses ( not easy
> to accomplish as the order of evaluation is not deterministic ) or
> several optionals with the following tests:
> 
> filter( langmatches( lang(?label), 'en-US' ) )
> filter( langmatches( lang(?label), 'en' ) )
> filter( langmatches( lang(?label), 'de' ) )
> filter( langmatches( lang(?label), 'fr' ) )
> filter( langmatches( lang(?label), null ) )
> filter( 1=1 )
> 
> The latter ( 1=1 ) is the star (*) which matches "any" language. Even Zwagili 
> ;)
> The keyword "none" will match literals with no lang tag ( plain literals ).
> 
> Even for this trivial case we can see the advantage of using such
> facility. Imagine what happens when there is more than one literal in
> the query ( which is usually the case ).
> 
> What do you guys think?
> 
> Thanks!
> A
> 

Hi Aldo / Ivan,

I was just reading the notes on langMatches (specifically the second
language-range argument ) in the SPARQL w3c recommendation [1] -
together with rfc4647 "Matching of Language Tags" [2] - and from what I
can tell it appears the intended usage of the language-range argument of
langMatches should very much be along the lines of the HTTP
Accept-Language header [3]

This would allow the following syntax:
 FILTER langMatches( lang(?label), "en-US,en,de,*" )

Noted that this doesn't seem to be supported in virtuoso, and if it were
would probably solve your issue.

The only other functionality realm I can see one may want is when you
want to return labels from multiple selected langauges (say the german
and english labels for an item) - in this case virtuoso does support the
IN syntax which allows you to do the following filter:
 FILTER ( lang(?label) IN( "en","de" ) )
thus solving that one already.

ps: somebody would obviously have to check that my understanding of
rfc4647 is correct!

[1] http://www.w3.org/TR/rdf-sparql-query/#func-langMatches
[2] http://www.ietf.org/rfc/rfc4647.txt [section 2.3]
[3] http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4

Regards,

Nathan



Reply via email to