Skip to content

Instantly share code, notes, and snippets.

@timhodson
Created December 7, 2011 16:22
Show Gist options
  • Save timhodson/1443435 to your computer and use it in GitHub Desktop.
Save timhodson/1443435 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'kasabi'
#Demonstration api key
APIKEY = "YOUR_API_KEY"
dataset = Kasabi::Dataset.new("http://kasabi.com/dataset/nasa", :apikey => APIKEY )
#SPARQL query to find name of spacecraft launched on 16th July 1969, as JSON"
QUERY = <<-EOL
PREFIX space: <http://purl.org/net/schemas/space/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE {
?launch space:launched "1969-07-16"^^xsd:date.
?spacecraft space:launch ?launch;
foaf:name ?name.
}
EOL
response = dataset.sparql_endpoint_client.select(QUERY)
json = JSON.parse( response.content )
#Results are in SPARQL JSON Results Format
json["results"]["bindings"].each do |binding|
puts binding["name"]["value"]
end
#OUTPUT
#
# Apollo 11 Command and Service Module (CSM)
# Apollo 11 SIVB
# Apollo 11 Lunar Module / EASEP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment