1. Title 1
Some text 1.
2. Title 2
2.1. Title 2.1
Some text under title 2.1.
2.2. Title 2.2
Some text under title 2.2.
Titles can be arbitrary and not necessarily contain numbering. Depth is arbitrary.
How to get back all elements still ordered in one query? Does Stardog have any functions that can help with this task?
My question based on the fact that relational databases can retrieve such structure in one query using nested set.
Desired output:
|-----------+----------------------------+---------|
| Title | Content | Depth |
|-----------+----------------------------+---------|
| Title 1 | Some text under title 1. | 0 |
| Title 2 | | 0 |
| Title 2.1 | Some text under title 2.1. | 1 |
| Title 2.2 | Some text under title 2.2. | 1 |
|-----------+----------------------------+---------|
that is, Lisp-style lists (you can even use the standard RDF lists though they don’t play well with SPARQL).
But getting all children in the topological order in one SPARQL query would be difficult. I can’t immediately think of an efficient single query solution. Stardog supports the so-called path queries so you can get paths to all children in one query but then the client would have to sort them according to the depth. Paths will be retrieved in the breadth-first order. We’re planning to add ORDER BY to path queries but it’s not there yet.
+1 on Pavel’s suggestion of :next or :hasNext . Then with an owl:inverseOf :hasPrevious and the reasoner on, you can easily traverse both directions, which I’ve found surprisingly useful.