C96
C96

Reputation: 529

SPARQL: Understanding what value gets assigned to variable

Hi I am new to SPARQL and I would like to understand better some things regarding variable assigments. Lets say I have the below:

SELECT ?z WHERE
{
    ?x n:type 'Type_1' .
    ?x n:belongs ?r .
    ?r n:belongs ?z .
    ?y n:type 'Type_1' .
    ?y n:belongs ?r_2 .
    ?r_2 n:belongs ?z . FILTER(?x != ?y)
}

In the above example query ?r and ?r_2 from my understanding have different values stored inside .Does the same applies for both variables ?z, or because both have the same name also have the same value stored inside?. An explanation would be appreciated. Cheers!

Upvotes: 0

Views: 143

Answers (1)

Charles
Charles

Reputation: 186

You can think of SPARQL as a template. It is a declarative language where you explicitly put in the things you know, and you put in variables for the things you don't. The query executes, and puts the values of the things you don't yet know, into the response, against the variable names. A variable called 'x' is the same variable throughout the query. It's response value is 'bound' to the parameter 'x'.

There is a SPARQL tutorial which I wrote in the open source graph-notebook project found here: https://github.com/aws/graph-notebook

After you run the notebook, navigate to 06-LANGUAGE-TUTORIALS Although it was originally built for Amazon Neptune, it is open source and will work with any SPARQL 1.1 endpoint.

Upvotes: 1

Related Questions