I tried the following query on WDQS:
SELECT ?item ?itemLabel ?string ?StringLabel ?iri ?iriLabel
WHERE {
VALUES ?item { wd:Q1339 }
BIND( STR(?item) AS ?string ).
BIND( IRI(?string) AS ?iri ).
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
And the result has ?string
and ?iri
value. However, if I place an extra pair of braces in the query expression
SELECT ?item ?itemLabel ?string ?StringLabel ?iri ?iriLabel
WHERE {
VALUES ?item { wd:Q1339 }
{
BIND( STR(?item) AS ?string ).
BIND( IRI(?string) AS ?iri ).
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
}
?string
and ?iri
in the result are empty, looking as if ?item
is missing in the first BIND expression. Why is the result different?
SPARQL's "bottom-up evaluation" is often better understood by its other label, i.e., "inside-out evaluation". That is, nesting is evaluated from the innermost to the outermost.
If you flip the nesting, you'll see the results you expected --
SELECT ?item ?itemLabel ?string ?StringLabel ?iri ?iriLabel
WHERE
{
BIND( STR(?item) AS ?string ).
BIND( IRI(?string) AS ?iri ).
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
{
VALUES ?item { wd:Q1339 }
}
}