0

I'm trying to understand blank nodes in turtle correctly, and I need to know if I have understood them correctly.

Suppose we had a turtle file:

@prefix sn: <....some uri...> .
_:a sn:name "person1";
sn:email "email1@test.com" .
_:b sn:name "person2";
sn:email "email2@test.com" .
_:c sn:name "person3" .

and we have SPARQL query:

PREFIX sn: <...some uri...>
SELECT ?email WHERE {
?x sn:name "person1" .
?x sn:email ?email .
}

This would only return the email of person 1, because ?x binds to the blank node label _:a... So my question is if an undefined variable ?x can still bind to a blank node that has a label, just like it would if it was not blank... So in this example, return will be:

      email
--------------------------
<mailto:email1@test.com> |

Would that be correct? Thanks.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Daniel
  • 117
  • 4
  • 1
    I'll try and provide an answer to this in a few minutes, but I was wondering why you don't simply try it out to see what the answer is. Chuck your RDF in a triplestore and execute the query, see what you get back. – Jeen Broekstra Dec 09 '15 at 20:07
  • Also, as far as I can tell your first and second example are identical. It's not really clear what you are asking, to be honest. – Jeen Broekstra Dec 09 '15 at 20:09

1 Answers1

1

You guess correctly: in both cases (and as said I don't really see a difference between your two examples) the answer wil be only the e-mail of person 1.

A blank node is, from SPARQL's perspective, a resource like any other, and it will bind variables to a blank node in exactly the same way. So in the above example, since we know that the two statements use the same blank node as their subject (since they use the same label), they will be seen by SPARQL as being about the same subject.

One caveat: the SPARQL engine/triplestore that you use will most likely not preserve the specific blank node id a: when adding your data to a triplestore it will be replaced by some generated internal id. However, the triplestore will of course make sure that both occurrences of a in your file get replaced by the exact same generated id.

Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73
  • 1
    Thanks a lot :) right, the two datasets are "identical", but i only provided a concrete output in the second example... I did afterwards go through the truble of setting up a local jena fuseki server to test them out, and got the expected result... Sorry if my question was a bit unclear... What i was wondering is if a blank node would bind to a variable (in sparql) just like any other "un-blank" node would, which you answered perfectly in this answer. – Daniel Dec 09 '15 at 20:49