This note is a summary of cwm/euler implementation experience w.r.t. accessing RDF collections and traversing trees.

Accessing RDF collections

The RDF collection to be queried is "The students in course 6.001 are Amy, Mohamed, and Johann" and is represented using the graph shown in
An RDF Collection (list structure)

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

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://example.org/students/vocab#> .

:students rdfs:range rdf:List.

<http://example.org/courses/6.001>     :students  (
    <http://example.org/students/Amy>
    <http://example.org/students/Mohamed>
    <http://example.org/students/Johann>  ) .

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

plants

The RDF/N3 for this example looks like

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://example.org/plants/vocab#> .

:Tree rdfs:subClassOf :Plant.
:Vegetable rdfs:subClassOf :Plant.
:Oak rdfs:subClassOf :Tree.
:Walnut rdfs:subClassOf :Tree.
:Pear rdfs:subClassOf :Tree.
:Salad rdfs:subClassOf :Vegetable.
:Potato rdfs:subClassOf :Vegetable.
:FrenchOak rdfs:subClassOf :Oak.
:AmericanOak rdfs:subClassOf :Oak.

To only get the "branch" of classes that are subclasses of Tree the SPARQL query to be answered looks like

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://example.org/plants/vocab#>

CONSTRUCT
  { ?C rdfs:subClassOf :Tree }

WHERE
  { ?C rdfs:subClassOf :Tree }

The command line euler plants.n3 rpo-rules.n3 -think -query plants.rq returns the RDF/N3 graph

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix : <http://example.org/plants/vocab#>.

:Oak rdfs:subClassOf :Tree.
:Walnut rdfs:subClassOf :Tree.
:Pear rdfs:subClassOf :Tree.
:FrenchOak rdfs:subClassOf :Tree.
:AmericanOak rdfs:subClassOf :Tree.