I would like to generate an RDF collection (i.e. rdf:first
/rdf:rest
linked list) using a SPARQL construct query, putting all grouped bindings for a variable into one collection.
So for the data
@prefix ex: <https://example.com/ns#> .
ex:example1 a ex:Example ;
ex:name "Example1" ;
ex:even false .
ex:example2 a ex:Example ;
ex:name "Example2" ;
ex:even true .
ex:example3 a ex:Example ;
ex:name "Example3" ;
ex:even false .
ex:example4 a ex:Example ;
ex:name "Example4" ;
ex:even true .
ex:example5 a ex:Example ;
ex:name "Example5" ;
ex:even false .
if the SELECT query
PREFIX ex: <https://example.com/ns#>
select (group_concat(?name) as ?names) where {
?a ex:even ?even;
ex:name ?name
} group by ?even
yields
names
Example1 Example3 Example5
Example2 Example4
what would a corresponding CONSTRUCT
query look like that contains the bindings for ?names
as an rdf collection, ie something like
( "Example1" "Example3" "Example5" )
( "Example2" "Example4")
(Assuming TTL interpretation of the above)
Background: I would like to generate SHACL shapes using SHACL-AF SPARQLRules, and one thing I am struggling with is to generate sh:in (...)
where the list is generated as an aggregate over multiple solutions of the query.