BIND applies to each row it is evaluated over.
SELECT *
WHERE
{ VALUES ?x { 1 2 }
BIND(bnode("a") AS ?BA1)
BIND(bnode("a") AS ?BA2)
}
(extend ((?BA2 (bnode "a")))
(extend ((?BA1 (bnode "a")))
(table (vars ?x)
(row [?x 1])
(row [?x 2])
)))
so there are two solution mappings (rows), one with ?x=1 and one ?x=2
passing though two BIND/BNODE operations.
"""
If the form with a simple literal is used, every call results in
distinct blank nodes for different simple literals, and the same blank
node for calls with the same simple literal within expressions for one
solution mapping.
"""
there are two solution mappings. Two different bnodes in different rows.
-------------------
| x | BA1 | BA2 |
===================
| 1 | _:b0 | _:b0 |
| 2 | _:b1 | _:b1 |
-------------------
if you want the same bnode across two rows, put the BNODE so it
evaluates before (i.e.further down the bottom-up evaluation).
SELECT *
{
BIND(BNODE("a") AS ?BA1)
BIND(BNODE("a") AS ?BA2)
VALUES ?x { 1 2 }
}
-------------------
| BA1 | BA2 | x |
===================
| _:b0 | _:b0 | 1 |
| _:b0 | _:b0 | 2 |
-------------------
or one before, one after - and now ?BA1 and ?BA2 are different
SELECT *
{
BIND(BNODE("a") AS ?BA1)
VALUES ?x { 1 2 }
BIND(BNODE("a") AS ?BA2)
}
(extend ((?BA2 (bnode "a")))
(join
(extend ((?BA1 (bnode "a")))
(table unit))
(table (vars ?x)
(row [?x 1])
(row [?x 2])
)))
-------------------
| BA1 | x | BA2 |
===================
| _:b0 | 1 | _:b1 |
| _:b0 | 2 | _:b2 |
-------------------
- this is less clear from the spec; it is relying on solution mappings
coming out of an operation (here, join) being different solution mappings.
BNODE is the same operation as CONSTRUCT bnodes.
CONSTRUCT { _:a :p 123 ; _:a :q 456 } WHERE ...
has _:a the same for each template instantiation and different for
different instantiation (one instantiation per row from WHERE).
Andy
On 17/04/18 15:44, Adrian Gschwend wrote:
Hi,
I run a query in Stardog and Fuseki with completely different results.
The query does this (simplifyed):
--
SELECT ?datasetNotation ?propertyNotation ?b_property ?property WHERE {
?dataset a qb:DataSet ;
skos:notation ?datasetNotation ;
qb:structure/qb:component/(qb:dimension|qb:measure) ?property .
?property skos:notation ?propertyNotation .
BIND(BNODE(CONCAT(?datasetNotation, ?propertyNotation)) AS ?b_property)
}
--
Now the problem is that I get a unique ?b_property for every single row
in TDB/Fuseki, although the strings ?datasetNotation and
?propertyNotation are the same for the same ?dataset. Stardog does not
behave like this and returns the same bnode for each unique string I
pass to BNODE(), also in different rows.
In the spec I find:
https://www.w3.org/TR/sparql11-query/#func-bnode
--
The BNODE function constructs a blank node that is distinct from all
blank nodes in the dataset being queried and distinct from all blank
nodes created by calls to this constructor for other query solutions. If
the no argument form is used, every call results in a distinct blank
node. If the form with a simple literal is used, every call results in
distinct blank nodes for different simple literals, and the same blank
node for calls with the same simple literal within expressions for one
solution mapping.
--
I'm not sure how to interpret the last part. Can I expect the same bnode
for each result in a set or not? It's IMO either a bug in Stardog or
Fuseki :)
I tested in Fuseki with two BNODE assignments:
BIND(BNODE("sugus") AS ?b_property)
BIND(BNODE("sugus") AS ?b_property2)
That does return _:b0
But then again I just get one row back like this.
regards
Adrian