Hello Aldo, I guess that I can introduce three things:
1. an HTTP-style langmatches (with q=NNN preferences ignored), still boolean to match the semantics of spec; 2. an HTTP-style bif:langmatches (with q=NNN preferences kept in mind) that will return a value of most accurately matching q, this function can be used in ORDER BY clause to return more advisable values first. 3. An bif:best-lang aggregate that will work like MAX but return the value with biggest reached q; so select ?s (bif:best-lang (?abstract, "en-US,en,de,*")) as ?bestabstract from <http://dbpedia.org> where { ?s rdfs:label "Novosibirsk" , <http://dbpedia.org/property/abstract> ?abstract } will return most preferable abstract out of dozen available. To keep queries shorter, a define sql:lang can be introduced, maybe with an additional "AUTO" value to borrow preferences from the string reported by the browser. Nevertheless the filtering of languages will not be fully transparent, the query should contain bif:langmatches or bif:best-lang to keep intentions clear for both author and the server-side cache of compiled queries. Comments are welcome. The feature is surely not for version 6 release but I see no reason to miss it in, say, 6.1. Best Regards, Ivan Mikhailov OpenLink Software http://virtuoso.openlinksw.com On Sun, 2010-01-24 at 12:18 -0300, 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 >
