Skip to content

Instantly share code, notes, and snippets.

@no-reply
Created August 6, 2013 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 no-reply/6166417 to your computer and use it in GitHub Desktop.
Save no-reply/6166417 to your computer and use it in GitHub Desktop.
Some ugly Ruby for stuffing processed ContentDM metadata into bags.
require 'rdf'
require 'rdf/ntriples'
require 'bagit'
graph = RDF::Graph.load('braceros.nt')
graph.each_subject do |subject|
bag = BagIt::Bag.new(File.basename(subject))
RDF::Writer.open("descMetadata.nt", :format => :ntriples) do |writer|
query = RDF::Query.new do
pattern [subject, :pred, :obj]
end
query.execute(graph).each do |solution|
writer << RDF::Repository.new do |r|
r << RDF::Statement.new({:subject => subject, :predicate => solution[:pred], :object => solution[:obj]})
end
end
end
bag.add_tag_file('descMetadata.nt', 'descMetadata.nt')
bag.add_tag_file('hybag.yml', 'hybag.yml')
query = RDF::Query.new do
pattern [subject, RDF::URI('http://tom.oregonstate.edu/full'), :full]
end
fname = query.execute(graph).first[:full].to_s.split('\\')[-1].gsub(/^1_/, '')
begin
bag.add_file('content.tif', File.join('..', 'braceros-tiffs', query.execute(graph).first[:full].to_s.split('\\')[-1].gsub(/^1_/, '')))
rescue
end
bag.tagmanifest!
bag.manifest!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment