1

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?

logi-kal
  • 7,107
  • 6
  • 31
  • 43
CXuesong
  • 552
  • 5
  • 12
  • 2
    *"Informally speaking, bottom-up evaluation means that subqueries and nested groups are (logically) evaluated first."* From https://wiki.blazegraph.com/wiki/index.php/SPARQL_Bottom_Up_Semantics – Stanislav Kralin Aug 29 '19 at 17:32

1 Answers1

2

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 }
    }
  }
TallTed
  • 9,069
  • 2
  • 22
  • 37