Re: SPARQL-friendly alternative to rdf:Lists?

On Fri, Oct 11, 2013 at 7:02 AM, David Booth <david@dbooth.org> wrote:

> 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<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.
>

There's no meaningful difference between a linked list and a capped,
position-numbered map.

I assume that the [item, index] pairs look something like:

_:collection item [ position 0; value "0" ], [ position 1; value "1" ], [
position 2; value "2" ], [ position 3; item nil ] .

Unfortunately it's hard to use an [item, index] system, you need at least
three properties for an item plus some way to uniquely identify which
collection the item belongs to, otherwise you can't differentiate between a
literal "nil" value and one indicating the actual end of the collection
(note the last item uses an "item" property instead of "value"). This is
exactly why we have the linked list rdf:List.

I'd suggest that if we have to invent a new system of storing a capped
ordered collection, then our current tools aren't descriptive enough to be
working with data in general. Converting between maps and linked lists
should be one of the top things we'd have figured out, you'd think.

That is, I don't think the problem is that RDF defined capped Collections
poorly, it's that SPARQL handles linked lists poorly. I saw a suggestion
for a new RDF type just for ordered lists, but this would still require
special functions in SPARQL. While we're defining new SPARQL functions, why
not make one to operate on generic linked lists?

Another way to define the [item, index] pairs goes something like:

_:collection item [ position 0; next 1; value "0" ], [ position 1; next 2;
value "1" ], [ position 2; next nil; value "2" ] .

This is essentially the current rdf:List setup, except with an additional
"position" property. (Also somewhere in there should be a way of mapping an
item to a particular collection.) How about a SPARQL function that adds two
columns, one for the URI/bnode of the Collection, and another for the
offset. A third column would return the URI/Bnode of the collection item
(such that for the first item, this value would be the same as the
Collection URI, and the offset would be 0). This third column is what would
be used for editing individual items and inserting or deleting items from
the linked list, without needing to re-number all the items in the map.

A query would be something to the effect of:

SELECT ?start ?item LIST_OFFSET(?start, ?item) ?author {
  ?document _:authors ?start .
  ?start rdf:rest* ?item .
  ?item rdf:first ?author .
}

I don't know about OWL, but you'd think it should support linked lists too.

Austin Wright.

Received on Monday, 14 October 2013 14:40:37 UTC