In this graph, each member of the collection, such as
s:Amy
, is the object of an rdf:first
property whose
subject is a resource (a blank node in this example) that
represents a list.
This list resource is linked to the rest of the list by an
rdf:rest
property. The end of the list is indicated by
the rdf:rest
property having as its object the resource
rdf:nil
(the resource rdf:nil
represents the empty
list, and is defined as being of type rdf:List
).
The RDF/N3 for this example looks like
The SPARQL query to be answered looks like
PREFIX list: <http://www.w3.org/2000/10/swap/list#>
PREFIX : <http://example.org/students/vocab#>
CONSTRUCT
{ ?S :follows ?C }
WHERE
{ ?C :students ?L. ?S list:in ?L }
The predicate list:in is true iff the object is a list and the subject is in that list. One way to test the list:in relationship is via ruleset [RPO-RULES] that are loaded with the RDF dataset in inference engines such as [CWM] and [EULER]. That way the command line cwm students.n3 rpo-rules.n3 -think -sparql=students.rq returns the RDF/N3 graph
@prefix : <http://example.org/students/vocab#> .
<http://example.org/students/Amy>
:follows <http://example.org/courses/6.001> .
<http://example.org/students/Johann>
:follows <http://example.org/courses/6.001> .
<http://example.org/students/Mohamed>
:follows <http://example.org/courses/6.001> .
Traversing trees
The tree to be to be queried is