Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
using sparql_client and hirb
$ ruby sparql_client_example.rb
+--------------------------------------------------------------------+-------------------------------------------------+-------------------------------------+
| s | p | o |
+--------------------------------------------------------------------+-------------------------------------------------+-------------------------------------+
| http://dbpedia.org/resource/Elizabeth_Peabody__Teacher | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Bonython_Hall | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Zemfira | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Myles_Keogh | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/St._Agnes_High_School_%28Queens%29 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Nikolai_Tolstoy | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Nashorn | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Mr_Kneebone | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Mount_Maroon | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Norman_Brearley | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Associated_Grammar_Schools_of_Victoria | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Maryborough_Airport_%28Queensland%29 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/1973_Australian_Grand_Prix | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Enrico_Mattei__Public_administrator | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Delkash | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Carlo_Tresca | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Poppy_Montgomery | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Billy_Blanks | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Elizabeth_Taylor | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Hue_Montgomery | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Chester_Schaeffer | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Emanuel_Parzen | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Charles_H._Moore | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Emperor_Kazan | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Cheltzie_Lee | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Emperor_Seiwa | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Chew_Valley_School | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Tom_Pauling | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Barry_Pepper | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Barbara_Luna | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Enumclaw_High_School | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Elizabeth_Ann_Seton | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Christina_Onassis | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Clere_School | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Peugeot_306 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Bill_Gothard | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Aurelio_Vidmar | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Charles_Van_Doren | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Nancy_Phelan | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Charles_Rivington | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Chandra_Levy | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Billy_Cotton | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Billy_Joe_Shaver | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Toni_Scanlan | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Capital_University | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Brian_Mandelbaum | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Ei%C5%BEens_Laube | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Skull-Face_and_Others | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Elbridge_Gerry | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
| http://dbpedia.org/resource/Brian_Austin_Green | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing |
+--------------------------------------------------------------------+-------------------------------------------------+-------------------------------------+
50 rows in set
require 'rubygems'
require 'sparql/client' # gem install sparql-client
require 'hirb' # gem install hirb
endpoint = 'http://dbpedia.org/sparql'
client = SPARQL::Client.new(endpoint)
data = client.query('SELECT DISTINCT * WHERE {?s ?p ?o} LIMIT 50')
# Or for more programmatic access
#data = client.select.distinct.where([:s, :p, :o]).limit(50)
# Print results in a nicely formatted table
Hirb.enable
puts Hirb::Helpers::Table.render data.map(&:to_hash), :fields => [:s, :p, :o]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment