[redland-dev] Example from the specification failing

Tom Beers tom at westslope.org
Mon Aug 13 10:51:16 EDT 2018


I am not a SPARQL expert by any means, so apologies if what seems like a 
bug turns out to be misuse on my part.


Using rdfproc 1.0.17 for Debian Stretch I run the following (the second 
query from https://www.w3.org/TR/rdf-sparql-query/#alternatives ):

```
rdfproc --contexts --new test add "_:a" 
"http://purl.org/dc/elements/1.0/title" "SPARQL Query Language Tutorial"
rdfproc --contexts test add "_:a" 
"http://purl.org/dc/elements/1.0/creator" "Alice"

rdfproc --contexts test add "_:b" 
"http://purl.org/dc/elements/1.1/title" "SPARQL Protocol Tutorial"
rdfproc --contexts test add "_:b" 
"http://purl.org/dc/elements/1.1/creator" "Bob"

rdfproc --contexts test add "_:c" 
"http://purl.org/dc/elements/1.0/title" "SPARQL"
rdfproc --contexts test add "_:c" 
"http://purl.org/dc/elements/1.1/title" "SPARQL (updated)"

rdfproc --contexts test query sparql - "SELECT ?x ?y WHERE  { { ?book 
<http://purl.org/dc/elements/1.0/title> ?x } UNION { ?book 
<http://purl.org/dc/elements/1.1/title> ?y } }"
```

This gives:

```
result: [, x="SPARQL Query Language Tutorial"]
result: [, x="SPARQL"]
result: []
result: []
```

Notice the lack of `y` bindings.


I have tried these examples with a version compiled from the GitHub 
sources and got the same results. I also tried this with the C library, 
and it seems to be `librdf_query_results_get_binding_value` that is 
failing, although I'm not sure.


Also, FWIW, here's the experiment that made me notice this in the first 
place:

```
rdfproc --contexts --new test add s:1 o:readBy i:1 c:1
rdfproc --contexts test add s:1 o:writtenBy i:1 c:2
rdfproc --contexts test add s:3 o:writtenBy i:1 c:3
rdfproc --contexts test add s:3 o:readBy i:1 c:4
rdfproc --contexts test add s:3 o:removedBy i:1 c:5

rdfproc --contexts test query sparql - "SELECT * WHERE { FILTER(?subject 
IN (<s:1>, <s:2>, <s:3>))   { GRAPH ?read_context { ?subject <o:readBy> 
?read_object } } UNION  { GRAPH ?write_context { ?subject <o:writtenBy> 
?write_object } } }"
```

Executing the above returns:

```
result: [, subject=<s:1>, read_context=<c:1>, read_object=<i:1>, 
write_context=<c:1>]
result: [, subject=<s:3>, read_context=<c:4>, read_object=<i:1>, 
write_context=<c:1>]
result: [, subject=<s:1>, read_context=<c:5>]
result: [, subject=<s:3>, read_context=<c:5>]
```

Notice `write_context` is wrong in the first two, `read_context` is 
wrong in the second two (`<c:5>` is showing up despite not being asked 
for), `write_object` is missing from the first two, and `read_object` is 
missing from the second two.


I'd like to finish this though with a huge thanks for librdf and co, 
they've been a great help.


More information about the redland-dev mailing list