Re: Easier SPARQL queries of ordered lists? (Simple List Conventions)

Hi Sébastien,

On 04/16/2015 03:08 AM, Sebastien Ferre wrote:
> Hi David,
>
> I overlooked the fact that your proposal uses plain standard
> SPARQL, but this is at the cost of changing the representation
> of lists, and not only queries.

Yes.

> I think your convention is as
> simple and concise as possible given the standard, but I would
> much prefer a few reasonable SPARQL extensions (easy to specify
> and implement) rather than pushing everybody to change the
> RDF representation of lists.

Yes, I would much prefer that standard RDF and SPARQL be enhanced to 
provide better support for lists, but that is likely at least several 
years away.  David Wood and James Leigh proposed such an enhancement to 
RDF in 2009 at the "RDF Next Steps" workshop:
http://www.w3.org/2009/12/rdf-ws/papers/ws14
Unfortunately it was not included in the working group charter when the 
RDF standard was updated to version 1.1 in 2011-2014, and AFAIK no new 
RDF working group is on the horizon.

I'm not pushing people to change their RDF list representations.  The 
intent is just to offer some conventions for those who *choose* to 
represent their list data in a more SPARQL-friendly way, to document 
those conventions and to limit the diversity of ways that the problem is 
solved.

> Also, your convention uses 2 blanks
> and 5 triples per element instead of 1 blank and 2 triples for
> RDF lists.

Yes, this is a convenience trade-off.  Thanks for mentioning it.  I've 
noted that in the document:
http://goo.gl/8PNuAG#heading=h.fy5b2tp8tlzm

>
> In terms of data structure, when items are associated to indices,
> we rather call them arrays than lists. Lists are typically
> recursive data structures that are usually processed by recursive
> functions, ignoring the index position of items. Maybe using the
> word 'array' instead of 'list' in your convention would help to
> make it visible, and to avoid confusion with RDF lists ? Just a
> suggestion.

Good point.  I'll think about that.  I guess I've been biased by habit 
in dealing with rdf:Lists and the Ordered List Ontology.

Thanks!
David Booth

>
> Best,
> Sébastien
>
> On 04/16/2015 07:02 AM, David Booth wrote:
>> Hi Sebastien,
>>
>> The Jena ARQ library actually provides a SPARQL extension, implemented
>> as a "magic property", that gives exposes the ordering of elements in an
>> rdf:List so that they can be returned from a SPARQL query in order.
>> There is an example in the Simple List Conventions document:
>> http://goo.gl/8PNuAG#heading=h.f03x3eaqzz3a
>> It would be nice if a capability like that -- or some other improved
>> support for lists -- were a part of standard SPARQL, but it is not.
>> That's why I've written up the Simple List Conventions.
>>
>> FYI, I have added an example that compares the Simple List Conventions
>> with the Ordered List Ontology (OLO):
>> http://goo.gl/8PNuAG#heading=h.ei3lksj4vzki
>>
>> Thanks,
>> David Booth
>>
>> On 04/14/2015 09:59 AM, Sebastien Ferre wrote:
>>> Hi,
>>>
>>> On 04/14/2015 11:07 AM, David Booth wrote:
>>>> rdf:Lists are a pain for SPARQL queries, because it's hard to retain
>>>> the
>>>> list ordering when querying, even if it is possible[1].  To work around
>>>> this problem, some list ontologies have been created[2][3], but I find
>>>> them overly verbose for routine use.  The Jena ARQ library also has a
>>>> feature that helps[4], but it is not standard SPARQL.
>>>
>>> I can only agree with the need for better query notations for lists
>>> and collections, and in fact more generally for any RDF structure based
>>> on blank nodes.
>>>
>>>> I'd like to propose a simpler convention that encodes each item as a
>>>> (value index) pair, and a simple vocabulary to go with it.  For
>>>> example,
>>>> instead of writing this:
>>>>
>>>>    PREFIX : <http://example/>
>>>>    :jane :likes (
>>>>          "bananas"
>>>>          "apples"
>>>>          "oranges"
>>>>          ) .
>>>>
>>>> each item would have an explicit index, like this:
>>>>
>>>>    PREFIX : <http://example/>
>>>>    :jane :likes
>>>>          ( "bananas" 0 ) ,
>>>>          ( "apples"  1 ) ,
>>>>          ( "oranges" 2 ) .
>>>>
>>>> which can be easily queried like this, retaining order:
>>>>
>>>>    SELECT DISTINCT ?item {
>>>>      :jane :likes ( ?item ?index ) .
>>>>    } ORDER BY ?index
>>>
>>>
>>> The first thing that pops to my mind is that you could use
>>> containers to get the same result with standard notations,
>>> only assuming a function to get the index of the rdf:_n
>>> properties.
>>>
>>> # description
>>> :jane :likes
>>>       [ rdf:_1 "bananas" ;
>>>         rdf:_2 "apples" ;
>>>         rdf:_3 "oranges" ] .
>>>
>>> # query
>>>
>>> SELECT DISTINCT ?item WHERE {
>>>     :jane :likes [ ?rdf_n ?item ] .
>>> } ORDER BY (index(?rdf_n))
>>>
>>>
>>> However, the annoying thing with your notation and mine is that
>>> indices have to be given explicitly, which is both tedious and
>>> unreliable, especially when deleting and inserting elements in
>>> lists. Ideally, the indices should come for free.
>>>
>>> Why not imagine a "list element pattern" as an extension of SPARQL,
>>> like the following with the obvious meaning ?
>>>
>>>     ?item in ?list at ?index .  (or any syntactic alternative)
>>
>>
>>>
>>> It would be a kind of implicit triple pattern
>>> relating a list, an item of the list, and its position in the list.
>>> On your example:
>>>
>>> SELECT DISTINCT ?item WHERE {
>>>     :jane :likes ?list .
>>>     ?item in ?list at ?index
>>> } ORDER BY ?index
>>>
>>>
>>> My two cents,
>>>
>>> Sébastien Ferré
>>>
>>>
>>>
>>>> References
>>>> 1. Standard SPARQL query of rdf:List that retains list order:
>>>> http://stackoverflow.com/questions/17523804/is-it-possible-to-get-the-position-of-an-element-in-an-rdf-collection-in-sparql/17530689#17530689
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> 2. Ordered List Ontology:
>>>> http://smiy.sourceforge.net/olo/spec/orderedlistontology.html
>>>>
>>>> 3. Collections Ontology:
>>>> http://www.essepuntato.it/lode/owlapi/http://purl.org/co/
>>>>
>>>> 4. Jena ARQ list:index example:
>>>> http://stackoverflow.com/questions/17523804/is-it-possible-to-get-the-position-of-an-element-in-an-rdf-collection-in-sparql/17528290#17528290
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>
>
>
>
>

Received on Friday, 17 April 2015 02:04:50 UTC