Skip to content

BIND not working as expected in SPARQL #580

Closed
@pchampin

Description

@pchampin

Ok, consider the following data:

@prefix s: <http://schema.org/> .
@prefix x: <http://example.org/> .

x:john a s:Person ; s:name "John" .
x:jane a s:Person ; s:name "Jane" ; s:knows x:john.
x:ecorp a s:Organization ; s:name "Evil Corp" ; s:employee x:jane . 

and the following query:

PREFIX s: <http://schema.org/>
PREFIX x: <http://example.org/>

#CONSTRUCT { ?s ?p ?o }
SELECT ?s ?p ?o ?x # for debugging
WHERE {
  ?x a s:Person .
  { ?x ?p ?o . BIND (?x as ?s) } UNION
  { ?s ?p ?x . BIND (?x as ?o) }
}

The goal of the query is to extract all incoming and outgoing arcs of every s:Person in the data
(and ultimately to construct a graph with those, but I use SELECT for debugging).

As I understand, the result should be

?s ?p ?o ?x
x:john rdf:type s:Person x:john
x:john s:name "John" x:john
x:jane s:knows x:john x:john
x:jane rdf:type s:Person x:jane
x:jane s:name "Jane" x:jane
x:jane s:knows x:john x:jane
x:ecorp s:employee x:jane x:jane

At least, this is what I get with Corese and Virtuoso.

But instead I get

?s ?p ?o ?x
rdf:type s:Person x:john
s:name "John" x:john
x:jane s:knows x:john
rdf:type s:Person x:jane
s:name "Jane" x:jane
s:knows x:john x:jane
x:ecorp s:employee x:jane

so the BIND (in this configuration) does not seem to work.

NB: the UNION is not the cause of the problem. I have the same problem without any UNION.

Metadata

Metadata

Assignees

Labels

SPARQLbugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions