I've come across several occasions where I've wanted to use blank nodes in a CONSTRUCT
query, but I've needed to get the same blank node for all (or several) query solutions.
Let's say that we have in our dataset a list of authors and books they have written:
@prefix : <http://example.org#> .
:stephen_king a :Author ;
:firstName "Stephen" ;
:authorOf "The Shining", "Cujo".
:stephen_hawking a :Author ;
:firstName "Stephen" ;
:authorOf "A Brief History of Time" .
:virginia_wolf a :Author ;
:firstName "Virginia" ;
:authorOf "Mrs Dalloway" .
For example, let's say I'd like to bind all books written authors with the first name Stephen
to a single blank node:
PREFIX : <http://example.org#>
CONSTRUCT {
[ :containsBook ?book ]
}
WHERE {
?book ^:authorOf/:firstName "Stephen" .
}
Would return something like:
[ :containsBook "The Shining" ] .
[ :containsBook "A Brief History of Time" ] .
[ :containsBook "Cujo" ] .
but the desired outcome was:
[ :containsBook "The Shining" ;
:containsBook "A Brief History of Time" ;
:containsBook "Cujo" ] .
Any ideas on how to achieve this?