Re: SPARQL-friendly alternative to rdf:Lists?

+1 Thanks for sharing!

As a side remark, I asked myself whether in implementations that *order* blank node ids representing list items in an ascending manner, the following considerably simpler would work as well, but the current SPARQL standard doesn't at all enforce this to work (and in fact it didn't in the implementation I tested it):
 
 prefix : <http://example.org#>
 prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

 select DISTINCT ?e ?node
 where {
   _:ls :list ?head .
   ?head rdf:rest* ?node .
   ?node rdf:first ?e .
 }
 order by ?node

So, what I am saying is that *if* we could assume that

 (i) it was best practice that in RDF graphs and stores importing/loading 
     those graphs bnode identifiers representing list items would be 
     ordered in an ascending manner, 

 (ii) ORDER BY on bnode identifiers was supported (which is *not* specified in the spec, 
      for good reasons, I assume, it's weird to impose an oder, 
      given the existential semantics of bnodes)  

such a simpler version would work… but I totally admit its a contrived version 
(too many woulds and coulds, and not compatible with existing implementations to enforce this,
though would likely scale better than the counting version).

just thinking out loud,
Axel

On 14 Oct 2013, at 19:23, David Booth <david@dbooth.org> wrote:

> Interesting trick!  I wouldn't want to use it in practice (for performance reasons), but it is quite a creative use of SPARQL.  Thanks for pointing it out.
> 
> David
> 
> On 10/14/2013 11:00 AM, Antoine Zimmermann wrote:
>> I suggest that you look at this answer by Joshua Taylor in Stackoverflow:
>> 
>> stackoverflow.com/questions/17523804/is-it-possible-to-get-the-position-of-an-element-in-an-rdf-collection-in-sparql/17530689#17530689
>> 
>> 
>> 
>> It shows a pure SPARQL 1.1 query that returns all the elements of a list
>> ordered by their position in the list. Very nice trick.
>> However, it also shows that using this trick will blow up the execution
>> time when the number of elements increase, and a customised programmatic
>> solution is far more efficient in general.
>> 
>> 
>> 
>> AZ.
>> 
>> 
>> 
>> 
>> 
>> Le 11/10/2013 16:02, David Booth a écrit :
>>> rdf:Lists are notoriously difficult to use in SPARQL if one wishes to
>>> retain the *order* of the items in the list.  James Leigh and David Wood
>>> made a nice proposal a few years ago to address this problem directly at
>>> the RDF level,
>>> http://www.w3.org/2009/12/rdf-ws/papers/ws14
>>> but for whatever reasons, that work was not included in the charter of
>>> the current RDF working group.  As a result people often use some other
>>> means of representing ordered lists in RDF, such as by [item, index]
>>> pairs.
>>> 
>>> For those who use an alternate way to represent an *ordered* list of
>>> items in RDF (instead of rdf:List), I am wondering:
>>> 
>>> 1. What *ordered* list representation do you prefer, and why?
>>> 
>>> 2. Have there been any efforts toward standardizing alternative
>>> *ordered* list representations in RDF?  E.g., has anyone written up a
>>> spec on how they prefer to do it?
>>> 
>>> Thanks,
>>> David
>>> 
>>> 
>> 
> 

Received on Monday, 14 October 2013 19:33:18 UTC