Skip to content

Instantly share code, notes, and snippets.

@bhuga
Created February 1, 2011 18:33
Show Gist options
  • Save bhuga/806334 to your computer and use it in GitHub Desktop.
Save bhuga/806334 to your computer and use it in GitHub Desktop.
Updates to SPARQL client to allow parsing with other tools, if so wished.
require 'sparql/client'
require 'rest_client'
sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
# existing functionality:
p sparql.query("select distinct ?Concept where {[] a ?Concept}").inspect
# now equivalent to:
response = RestClient.post 'http://dbpedia.org/sparql', { :query => "select distinct ?Concept where {[] a ?Concept}" }, :content_type => 'application/x-www-form-urlencoded', :accept => 'application/sparql-results+json'
p SPARQL::Client.parse_json_bindings(response)
# also now equivalent to:
response = sparql.response("select distinct ?Concept where {[] a ?Concept}", SPARQL::Client::ACCEPT_JSON )
puts responset.body
p SPARQL::Client.parse_json_bindings(response.body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment