Use automatically-assigned blank node with reified data

77 Views Asked by At

I'm trying to query a dataset which uses the RDF reification vocabulary, something like this:

myprefix:statement1 rdf:subject myprefix:object1 .
myprefix:statement1 rdf:predicate myprefix:isrelatedto .
myprefix:statement1 rdf:object myprefix:object2 .

myprefix:statement2 rdf:subject myprefix:object2 .
myprefix:statement2 rdf:predicate myprefix:isrelatedto .
myprefix:statement2 rdf:object myprefix:object3 .

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix myprefix: <mydomain#>
select *
from <mydomain>
where {
 [ rdf:subject ?first ; rdf:predicate myprefix:isrelatedto ; rdf:object _:1 ] .
 [ rdf:subject _:1 ; rdf:predicate myprefix:isrelatedto ; rdf:object ?second ] .
}

Result:
 __________________ __________________
| first            | second           |
|__________________|__________________|
| myprefix:object1 | myprefix:object2 |
|__________________|__________________|

Can I replace the labelled blank node _:1 with the [ ] construction somehow?

EDIT: Should explain that the reason for the question was that in the real use case I have a much more complex query that needs to get a variable number of properties like this (the query is generated dynamically). So what I'm trying to do is get rid of the labelled node so that I don't have to generate unique labels dynamically.

1

There are 1 best solutions below

0
On

[ ] works when there is at most one reference to it.

Here we have:

... rdf:object _:1

... rdf:subject _:1

so two references to the blank node as currently written.

If you can modify the rest of the query, it may be possible. Whether the intent is clearer is something you'll have to make a judgement on.

Because in the part:

[ rdf:subject _:1 ; ....]

isn't using the outer [ ] blank node for anything so it might be possible to have rdf:object/^rdf:subject as suggested in the comment.

Whether the intent is clearer is something you'll have to make a judgement on.