Skip to content

Commit

Permalink
Merge pull request #68 from trln/hotfix-0.5.10
Browse files Browse the repository at this point in the history
Fix bug where LCNAF entries are missed if there are multiple names in…
  • Loading branch information
kazymovae authored Mar 8, 2021
2 parents 31ec5a7 + cb5dc77 commit 715a7bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/spofford/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Spofford
VERSION = '0.5.9'.freeze
VERSION = '0.5.10'.freeze
end
33 changes: 17 additions & 16 deletions lib/tasks/util.rake
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,19 @@ namespace :util do

Zip::File.open("#{DEFAULT_DESTINATION}/#{DEFAULT_FILENAME}.zip") do |zip|
zip.select { |entry| entry.name == DEFAULT_FILENAME }.each do |e|
e.get_input_stream.each_with_index do |line, index|
rdf = JSON.parse(line).fetch('@graph', [])

names = personal_names(rdf) if rdf
id = names.first.fetch('@id', '')
.sub('http://id.loc.gov/authorities/names/', 'lcnaf:') if names.first
ids = has_variant_ids(names) if names
labels = variant_labels(rdf, ids)

unless (labels.nil? || labels.empty?)
REDIS.set(id, labels)
puts "#{id}:#{labels}" if index % 2500 == 0
Argot::Reader.new(e.get_input_stream).each_with_index do |rec, index|
rdf = rec.fetch('@graph', [])
names = name_entries(rdf) if rdf
names.each do |name|
id = name.fetch('@id', '')
.sub('http://id.loc.gov/authorities/names/', 'lcnaf:') if name
ids = has_variant_ids(name) if name
labels = variant_labels(rdf, ids)

unless (labels.nil? || labels.empty?)
REDIS.set(id, labels)
puts "#{id}:#{labels}" if index % 2500 == 0
end
end
end
end
Expand All @@ -101,16 +102,16 @@ namespace :util do

private

def personal_names(rdf)
def name_entries(rdf)
rdf.select { |v| v.fetch('@type', []).include?('madsrdf:Authority') &&
(v.fetch('@type', []).include?('madsrdf:PersonalName') ||
v.fetch('@type', []).include?('madsrdf:CorporateName'))}
end

def has_variant_ids(names)
return if names.nil? || names.empty?
def has_variant_ids(name)
return if name.nil? || name.empty?

variants = names&.first&.fetch('madsrdf:hasVariant', [])
variants = name&.fetch('madsrdf:hasVariant', [])
[variants]&.flatten&.map { |v| v['@id'] }
end

Expand Down

0 comments on commit 715a7bb

Please sign in to comment.