Created
December 7, 2011 16:12
-
-
Save timhodson/1443381 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'kasabi' | |
require 'json' | |
#change to your API key | |
APIKEY = "YOUR_API_KEY" | |
dataset = Kasabi::Dataset.new("http://kasabi.com/dataset/nasa", :apikey => APIKEY ) | |
#Search for "Apollo", limiting to 5 results | |
results = dataset.search_api_client.search("apollo", { :max => 5 }) | |
#Dump the JSON response to the console | |
puts JSON.pretty_generate(results) require 'rubygems' | |
require 'kasabi' | |
require 'json' | |
require 'rdf' | |
require 'rdf/json' | |
#Demonstration api key | |
APIKEY = "YOUR_API_KEY" | |
dataset = Kasabi::Dataset.new("http://kasabi.com/dataset/nasa", :apikey => APIKEY ) | |
#URI for a resource in this dataset | |
uri = "http://data.kasabi.com/dataset/nasa/spacecraft/1968-025A" | |
#Lookup a URI, returns an RDF graph | |
graph = dataset.lookup_api_client.lookup( uri ) | |
#Output the name (foaf:name properties) of this resource | |
puts graph.first_literal( [ uri , RDF::FOAF.name ] ) | |
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 | |
require 'sinatra' | |
require 'kasabi' | |
get '/' do | |
dataset = Kasabi::Dataset.new("http://data.kasabi.com/dataset/nasa", :apikey => ENV["KASABI_API_KEY"]) | |
@query = params[:query] || "apollo" | |
@results = dataset.search_api_client.search(@query) | |
template =<<-EOL | |
<html> | |
<head> | |
<title>Kasabi</title> | |
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css"> | |
</head> | |
<body> | |
<div class="container"> | |
<h1>Search Results: <%= @query %></h1> | |
<p>Results of searching the NASA dataset for <%= @query %></p> | |
<table> | |
<tr><th>URI</th><th>Title</th><th>Rank</th></tr> | |
<% @results["results"].each do |hit| %> | |
<tr> | |
<td><%= hit["uri"] %></td> | |
<td><%= hit["title"] %></td> | |
<td><%= hit["score"] %></td> | |
</tr> | |
<% end %> | |
</table> | |
</div> | |
</body> | |
</html> | |
EOL | |
erb template | |
end require "rubygems" | |
require "bundler" | |
Bundler.require | |
require "./app" | |
run Sinatra::Application | |
source :rubyforge | |
gem 'rack' | |
gem 'sinatra' | |
gem 'kasabi' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment