1

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.

Cartmo
  • 73
  • 6
  • 2
    not sure why, but I gues you can do `select * from where { [ rdf:subject ?first ; rdf:predicate myprefix:isrelatedto ; rdf:object/^rdf:subject [ rdf:predicate myprefix:isrelatedto ; rdf:object ?second ] ] . }` - though I didn't check if the result is the same and why you'd need it as long as your query works as expected. – UninformedUser Apr 09 '20 at 07:59
  • 2
    Slightly more symmetric: `{ [] ^rdf:subject [rdf:predicate :isRelatedTo; rdf:object ?st] ; ^rdf:object [rdf:predicate :isRelatedTo; rdf:subject ?nd] }` – Stanislav Kralin Apr 09 '20 at 10:49
  • Thanks. The reverse property path is what solved it for me. The solution I have gone with is: `[ rdf:subject [ ^rdf:object/rdf:subject ?first ; ^rdf:object/rdf:predicate :isrelatedto ] ; rdf:predicate :isrelatedto ; rdf:object ?second ]` - this version enables me to use two different predicates for the two relationships. – Cartmo Apr 09 '20 at 14:19

1 Answers1

1

[ ] 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.

AndyS
  • 16,345
  • 17
  • 21