-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revise subject field mappings (#1291)
* Revise subject field mappings * Fix subject mapping value * Add specs * Add reused method to extraction tools
- Loading branch information
Showing
9 changed files
with
328 additions
and
24 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
require 'traject/extraction_tools' | ||
extend ExtractionTools | ||
|
||
module ExtractGenre | ||
def extract_genre | ||
lambda do |record, accumulator| | ||
tags = ['655a'] | ||
|
||
tags.each do |tag| | ||
record.fields(tag.to_i.to_s).find_all do |field| | ||
next unless valid_genre_field?(field) | ||
value = marc21.trim_punctuation(extract_value(tag, field)) | ||
accumulator << value unless value.nil? || accumulator.include?(value) | ||
end | ||
end | ||
accumulator | ||
end | ||
end | ||
|
||
def valid_genre_field?(field) | ||
(['0', '2'].include? field.indicator2) || valid_genre_source?(field) | ||
end | ||
|
||
def valid_genre_source?(field) | ||
valid_sources = ['lcgft', 'homoit', 'aat', 'rbbin', 'rbgenr', 'rbpap', 'rbpri', 'rbprov', 'rbpub'] | ||
field.indicator2 == '7' && field.subfields.any? do |subfield| | ||
subfield.code == '2' && valid_sources.include?(subfield.value) | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
require 'traject/extraction_tools' | ||
extend ExtractionTools | ||
|
||
module ExtractSubject | ||
def extract_subject | ||
lambda do |record, accumulator| | ||
tags = ['600abcdq', '610ab', '611adc', '630aa', '650aa', '653aa', '654a'] | ||
|
||
tags.each do |tag| | ||
record.fields(tag.to_i.to_s).find_all do |field| | ||
next unless valid_subject_field?(field) | ||
value = marc21.trim_punctuation(extract_value(tag, field)) | ||
accumulator << value unless value.nil? || accumulator.include?(value) | ||
end | ||
end | ||
accumulator | ||
end | ||
end | ||
|
||
def valid_subject_field?(field) | ||
(['0', '2'].include? field.indicator2) || valid_subject_source?(field) | ||
end | ||
|
||
def valid_subject_source?(field) | ||
valid_sources = ['lcgft', 'homoit', 'aat', 'rbbin', 'rbgenr', 'rbpap', 'rbpri', 'rbprov', 'rbpub'] | ||
field.indicator2 == '7' && field.subfields.any? do |subfield| | ||
subfield.code == '2' && valid_sources.include?(subfield.value) | ||
end | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
require 'traject/extraction_tools' | ||
extend ExtractionTools | ||
|
||
module ExtractSubjectEra | ||
def extract_subject_era | ||
lambda do |record, accumulator| | ||
tags = ['650y', '651y', '654y', '655y'] | ||
|
||
tags.each do |tag| | ||
record.fields(tag.to_i.to_s).find_all do |field| | ||
next unless valid_subject_era_field?(field) | ||
value = marc21.trim_punctuation(extract_value(tag, field)) | ||
accumulator << value unless value.nil? || accumulator.include?(value) | ||
end | ||
end | ||
accumulator | ||
end | ||
end | ||
|
||
def valid_subject_era_field?(field) | ||
(['0', '2'].include? field.indicator2) || valid_subject_era_source?(field) | ||
end | ||
|
||
def valid_subject_era_source?(field) | ||
valid_sources = ['lcgft', 'homoit', 'aat', 'rbbin', 'rbgenr', 'rbpap', 'rbpri', 'rbprov', 'rbpub'] | ||
field.indicator2 == '7' && field.subfields.any? do |subfield| | ||
subfield.code == '2' && valid_sources.include?(subfield.value) | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
require 'traject/extraction_tools' | ||
extend ExtractionTools | ||
|
||
module ExtractSubjectGeo | ||
def extract_subject_geo | ||
lambda do |record, accumulator| | ||
tags = ['651a', '650z'] | ||
|
||
tags.each do |tag| | ||
record.fields(tag.to_i.to_s).find_all do |field| | ||
next unless valid_subject_geo_field?(field) | ||
value = marc21.trim_punctuation(extract_value(tag, field)) | ||
accumulator << value unless value.nil? || accumulator.include?(value) | ||
end | ||
end | ||
accumulator | ||
end | ||
end | ||
|
||
def valid_subject_geo_field?(field) | ||
(['0', '2'].include? field.indicator2) || valid_subject_geo_source?(field) | ||
end | ||
|
||
def valid_subject_geo_source?(field) | ||
valid_sources = ['lcgft', 'homoit', 'aat', 'rbbin', 'rbgenr', 'rbpap', 'rbpri', 'rbprov', 'rbpub'] | ||
field.indicator2 == '7' && field.subfields.any? do |subfield| | ||
subfield.code == '2' && valid_sources.include?(subfield.value) | ||
end | ||
end | ||
end |
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
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
Oops, something went wrong.