ruby-rdf / sparql-client

SPARQL client for Ruby.
http://rubygems.org/gems/sparql-client
The Unlicense
112 stars 58 forks source link

SPARQL Example Query fails in Ruby-RDF/sparql-client #51

Closed mowenwert closed 10 years ago

mowenwert commented 10 years ago

Code:

gem 'sparql-client', '~> 1.1.2' require 'sparql/client'

sparql = SPARQL::Client.new("http://dbpedia.org/sparql")

result = sparql.ask.whether([:s, :p, :o]).true?

Error: /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/reader.rb:410:in fail_subject': ERROR [line 1] Expected subject (found: "{ \"head\": { \"link\": [] }, \"boolean\": true}") (RDF::ReaderError) from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/ntriples/reader.rb:210:inblock in read_triple' from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/ntriples/reader.rb:204:in loop' from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/ntriples/reader.rb:204:inread_triple' from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/reader.rb:391:in read_statement' from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/reader.rb:308:inblock in each_statement' from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/reader.rb:308:in loop' from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/reader.rb:308:ineach_statement' from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/util/aliasing.rb:46:in block in alias_method' from /home/USER/.rvm/gems/ruby-2.1.2/gems/rdf-1.1.4.2/lib/rdf/mixin/countable.rb:12:inempty?' from /home/USER/.rvm/gems/ruby-2.1.2/gems/sparql-client-1.1.2/lib/sparql/client/query.rb:268:in true?' from /home/USER/tutorial_workspace/sentiment_dev/sparql_query.rb:6:in

'

gkellogg commented 10 years ago

As it happens, DBpedia is returning a a JSON body, but the content-type is text/plain, which is parsed as N-Triples. In particular, the body returned is the following:

{  "head": { "link": [] }, "boolean": true}

The rest of the returned headers are:

{"date":["Tue, 29 Jul 2014 15:51:53 GMT"],"content-type":["text/plain"],"content-length":["43"],"connection":["keep-alive"],"server":["Virtuoso/07.10.3211 (Linux) i686-generic-linux-glibc212-64  VDB"],"accept-ranges":["bytes"]}

Note that the request is sent with Accept including various RDF formats, in addition to application/sparql-results+json and +xml; for some reason DBPedia isn't setting the content-type correctly.

gkellogg commented 10 years ago

commit 21ac68c8 on feature branch specific-accept attempts to address this by passing either RDF content types or SPARQL Results content types depending on the operation. Unfortunately, for SPARQL Update controls, it's not really clear what form expected results take. We use the following:

Those using RDF content types:

Those using SPARQL Results content types:

It would be great of watchers of this issue could validate this logic; it may not be a good idea at all, but I've seen similar issues on Dyrda, and now DBpedia.

cc/ @bendiken @moustaki

moustaki commented 10 years ago

Would it be worth pushing that upstream? (The content-type definitely looks wrong on the DBpedia side)

gkellogg commented 10 years ago

I was looking for some more validation on the SPARQL Results content types, but if the consensus is to ship it, that's fine with me; we can always address later, if there are some endpoints that make different assumptions.

I'll put this on my queue.