Skip to content

Instantly share code, notes, and snippets.

@tommorris
Created October 13, 2012 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommorris/3885372 to your computer and use it in GitHub Desktop.
Save tommorris/3885372 to your computer and use it in GitHub Desktop.
require "rdf"
require "rdf/n3"
require "rdf/ntriples"
graph = RDF::Graph.load("/Users/tom/Downloads/uk.n3")
graph.each_subject do |station|
station_graph = RDF::Graph.load(station.to_s.sub("resource", "data").gsub(/$/, ".ntriples"))
query = RDF::Query.new({
:station => {
RDF::FOAF.name => :name,
}
})
query.execute(station_graph).each do |solution|
graph << [station, RDF::FOAF.name, solution.name]
end
end
RDF::Writer.open("/Users/tom/Downloads/uk_parsed.n3") do |writer|
graph.each_statement do |statement|
writer << statement
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment