Bulk Changes to Items in Sets - OregonDigital/oregondigital GitHub Wiki
Bulk changes to Oregon Digital items are possible from the Rails Console. This page is to provide examples of what's been done and help inform future cleanup work.
For test runs: Comment out the save, add puts statements showing result, change 'rows' value to 10 or 1, then check those items.
Pull out list of Location values that are text strings, not URIs, for Gifford items
locations = []
ActiveFedora::SolrService.query("desc_metadata__set_sim:#{RSolr.escape("http://oregondigital.org/resource/oregondigital:gifford")}", :fl => "id", :rows => 100000).map{|x| x["id"]}.each do |pid|
item = Image.find(:pid => pid).first || Document.find(:pid => pid).first || Audio.find(:pid => pid).first || GenericAsset.find(:pid => pid).first
next if item.descMetadata.location.nil?
if item.descMetadata.location.kind_of?(String)
locations << item.descMetadata.location
puts item.descMetadata.location
else
item.descMetadata.location.each do |lo|
next if lo.nil?
# skip if URI
next if lo.to_s.start_with?("default")
next if lo.to_s.include?("http")
locations << lo
puts lo
end
end
end
locations.sort.each do |lo|
puts lo
end
Change isPartOf with old URIs to localCollectionName with correct URIs for Baseball items
ActiveFedora::SolrService.query("desc_metadata__set_sim:#{RSolr.escape("http://oregondigital.org/resource/oregondigital:osu-baseball")}", :fl => "id", :rows => 100000).map{|x| x["id"]}.each do |pid|
puts pid
bb = Image.find(:pid => pid).first || Document.find(:pid => pid).first || Audio.find(:pid => pid).first || GenericAsset.find(:pid => pid).first
next if bb.descMetadata.isPartOf.empty?
collection = bb.descMetadata.isPartOf.first.rdf_subject.to_s.gsub('http://data.library.oregonstate.edu/collection/', 'http://opaquenamespace.org/ns/localCollectionName/')
next if collection.nil?
bb.descMetadata.localCollectionName = RDF::URI(collection)
bb.descMetadata.isPartOf.clear
puts "Local Collection: #{collection}"
bb.save!
end
Add items in Set to Additional Set
Used to add items in OSU Yearbooks set to OSU Historical Publications set as well.
hp = GenericCollection.find(:pid => 'oregondigital:osu-historical-publications').first
ActiveFedora::SolrService.query("desc_metadata__set_sim:#{RSolr.escape("http://oregondigital.org/resource/oregondigital:osu-yearbooks")}", :fl => "id", :rows => 100000).map{|x| x["id"]}.each do |pid|
c1 = Image.find(:pid => pid).first || Document.find(:pid => pid).first || Audio.find(:pid => pid).first || Video.find(:pid => pid).first || GenericAsset.find(:pid => pid).first
c1.set << hp
c1.save!
end
Add localCollectionName URIs, based on values in Identifier, for Gifford items
ActiveFedora::SolrService.query("desc_metadata__set_sim:#{RSolr.escape("http://oregondigital.org/resource/oregondigital:gifford")}", :fl => "id", :rows => 100000).map{|x| x["id"]}.each do |pid|
item = Image.find(:pid => pid).first || Document.find(:pid => pid).first || Audio.find(:pid => pid).first || GenericAsset.find(:pid => pid).first
ident = item.identifier.first
case
when ident.include?("P218 SG7")
item.descMetadata.localCollectionName << RDF::URI('http://opaquenamespace.org/ns/localCollectionName/p_218-sg_7')
when ident.include?("P218 SG6")
item.descMetadata.localCollectionName << RDF::URI('http://opaquenamespace.org/ns/localCollectionName/p_218-sg_6')
when ident.include?("P218 SG5")
item.descMetadata.localCollectionName << RDF::URI('http://opaquenamespace.org/ns/localCollectionName/p_218-sg_5')
when ident.include?("P218 SG4")
item.descMetadata.localCollectionName << RDF::URI('http://opaquenamespace.org/ns/localCollectionName/p_218-sg_4')
when ident.include?("P218 SG3")
item.descMetadata.localCollectionName << RDF::URI('http://opaquenamespace.org/ns/localCollectionName/p_218-sg_3')
when ident.include?("P218 SG2")
item.descMetadata.localCollectionName << RDF::URI('http://opaquenamespace.org/ns/localCollectionName/p_218-sg_2')
when ident.include?("P218 SG1")
item.descMetadata.localCollectionName << RDF::URI('http://opaquenamespace.org/ns/localCollectionName/p_218-sg_1')
else
item.descMetadata.localCollectionName << RDF::URI('http://opaquenamespace.org/ns/localCollectionName/p_218')
end
item.save! unless item.nil?
end
Fix worktypes, change strings to URIS, for Gifford items
ActiveFedora::SolrService.query("desc_metadata__set_sim:#{RSolr.escape("http://oregondigital.org/resource/oregondigital:gifford")}", :fl => "id", :rows => 100000).map{|x| x["id"]}.each do |pid|
item = Image.find(:pid => pid).first || Document.find(:pid => pid).first || Audio.find(:pid => pid).first || GenericAsset.find(:pid => pid).first
item.descMetadata.workType.each do |wt|
# skip things that are already URIs
next if wt.to_s.start_with?("default")
case
when wt.include?("Glass negatives")
item.descMetadata.workType << RDF::URI('http://vocab.getty.edu/aat/300393160') # glass plate negatives
item.descMetadata.workType.delete(wt)
puts "http://vocab.getty.edu/aat/300393160 - glass plate negatives"
when wt.include?("Glass positives")
item.descMetadata.workType << RDF::URI('http://opaquenamespace.org/ns/workType/Glasspositives')
item.descMetadata.workType.delete(wt)
puts "http://opaquenamespace.org/ns/workType/Glasspositives"
when wt.include?("Nitrate negatives")
item.descMetadata.workType << RDF::URI('http://vocab.getty.edu/aat/300311696') # cellulose nitrate film
item.descMetadata.workType.delete(wt)
puts "http://vocab.getty.edu/aat/300311696 - cellulose nitrate film"
when wt.include?("Stereoscopic negatives")
item.descMetadata.workType << RDF::URI('http://vocab.getty.edu/aat/300127197') # stereographs
item.descMetadata.workType.delete(wt)
puts "http://vocab.getty.edu/aat/300127197 - stereographs"
end
end
item.save! unless item.nil?
end
Don't change anything, effectively reindex items in Set
ActiveFedora::SolrService.query("desc_metadata__set_sim:#{RSolr.escape("http://oregondigital.org/resource/oregondigital:gifford")}", :fl => "id", :rows => 100000).map{|x| x["id"]}.each do |pid|
item = Image.find(:pid => pid).first || Document.find(:pid => pid).first || Audio.find(:pid => pid).first || GenericAsset.find(:pid => pid).first
puts pid
item.save! unless item.nil?
end