I have a list of three elements like this:
<Employee#1> <hasOrderedTasks> [ a rdf:List ; rdf:first <FirstTask> ;
rdf:rest [ rdf:first <SecondTask> ;
rdf:rest [ rdf:first <ThirdTask> ;
rdf:rest rdf:nil ] ] ] .
My question is: how to I return the list (with its structure) using a CONSTRUCT type query?
Note that the list may have a variable number of elements, and the query would need to generalise to that.
I could use something like:
CONSTRUCT {
?employee <hasOrderedTasks> ?list .
?list <hasElement> ?element
}
WHERE {
?employee <hasOrderedTasks> ?list .
?list rdf:rest*/rdf:first ?element .
}
However this would destroy the order of my list. I could of course use some aggregation in a subquery to compute the index of elements in the list, but even that would not recreate my list as is. Is there perhaps some other function that can help me? Or is this just not possible in SPARQL?