Skip to content

Instantly share code, notes, and snippets.

@artob
Created October 22, 2010 23:09
Show Gist options
  • Save artob/641535 to your computer and use it in GitHub Desktop.
Save artob/641535 to your computer and use it in GitHub Desktop.
RDF.rb 0.3.0 BGP query example
#!/usr/bin/env ruby1.9
require 'rdf'
require 'rdf/ntriples'
RDF::Repository.load('http://rdf.rubyforge.org/doap.nt') do |rdf|
bgp = RDF::Query.new do
self << [:person, RDF.type, RDF::FOAF.Person]
self << [:person, RDF::FOAF.name, :name]
self << [:person, RDF::FOAF.mbox, :email]
end
bgp.execute(rdf).each do |solution|
p solution.to_hash
end
end
#=> {:person => #<RDF::URI(http://ar.to/#self)>,
#=> :name => #<RDF::Literal("Arto Bendiken")>
#=> :email => #<RDF::URI(mailto:[email protected])>}
#=> {:person => #<RDF::URI(http://bhuga.net/#ben)>,
#=> :name => #<RDF::Literal("Ben Lavender")>
#=> :email => #<RDF::URI(mailto:[email protected])>}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment