Is it possible to guarantee that the results of a transitive query in SPARQL come back in the order in which they were walked?
So, given some simple data:
<http://example.com/step0> ex:contains <http://example.com/step1>
<http://example.com/step1> ex:contains <http://example.com/step2>
<http://example.com/step2> ex:contains <http://example.com/step3>
(in practice the relation could repeat many more times)
Query (using sparql 1.1):
SELECT ?parent
WHERE {
?parent ex:contains* <http://example.com/step3>
}
Such that you would always get back [step0, step1, step2]. When trying this in jena I get consistent but randomly ordered results.
Alternatively, it would be fine if I could get back both the parent and child in the transitive walk so that I could re-order it outside, but I don't know how to both bind ?parent ex:contains* <http://example.com/step3>
and get back the objects of the intermediate relations without writing a very slow nested query with filtering.