ruby-rdf / sparql

Ruby SPARQL library
http://rubygems.org/gems/sparql
The Unlicense
88 stars 14 forks source link

JSON binding #2

Closed mikaa123 closed 12 years ago

mikaa123 commented 12 years ago

Hi, Congratulation on the library, it's amazingly useful.

I'm not sure if this is the right place to report my issue, since it concerns the JSON ouput. Specifically, the bindings of the requested variables in the JSON.

Here's the example:

server.rb

require 'sinatra'
require 'sinatra/sparql'
require 'linkeddata'

dataset = RDF::Graph.new do |graph|
  graph << [RDF::Node.new, RDF::DC.title, "Hello, world!"]
  graph << [RDF::Node.new, RDF::DC.title, "Foo bar"]
end

get '/sparql' do
  SPARQL.execute( request[:query], dataset )
end

$ ruby server.rb

Now when I query it,

curl http://localhost:4567/sparql --data-urlencode "query=SELECT ?x ?y ?z WHERE { ?x ?y ?z } LIMIT 10"  -G

I get:

{"head":
          {"vars":["x","y","z"]},
          "results":{
                      "bindings": [
                              {"x":{"type":"bnode","value":"g26035760"}},
                              {"y":{"type":"uri","value":"http://purl.org/dc/terms/title"}},
                              {"z":{"type":"literal","value":"Hello, world!"}},
                              {"x":{"type":"bnode","value":"g26106100"}},
                              {"y":{"type":"uri","value":"http://purl.org/dc/terms/title"}},
                              {"z":{"type":"literal","value":"Foo bar"}}]}}

So this results in 6 different solutions with each one bound variable, instead of 2 solutions with 3 bound variables.

There is no problem when requesting sparql-results+xml.

gkellogg commented 12 years ago

I've verified the issue and created a test case. I'll update shortly.

Thanks for the report! I'm glad it's useful to you!

gkellogg commented 12 years ago

Fixed in afff7cbc29fcd602714118bc4ba3f08410befb38

mikaa123 commented 12 years ago

Thanks!