Created
August 6, 2013 17:04
-
-
Save no-reply/6166417 to your computer and use it in GitHub Desktop.
Some ugly Ruby for stuffing processed ContentDM metadata into bags.
This file contains 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 '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