Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subject heading remdiation other fields #117

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions umich_catalog_indexing/lib/common/subjects/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ def to_remediated
match = _matching_deprecated_field

sfields = @field.subfields.filter_map.with_index do |sf, index|
unless match["normalized"]["450"][sf.code]
unless match["normalized"]["4xx"][sf.code]
&.include?(normalized_sfs[index]["value"])
MARC::Subfield.new(sf.code, sf.value)
end
end

remediated_field = MARC::DataField.new(@field.tag, @field.indicator1, "7", *sfields)
match["given"]["150"].keys.each do |code|
match["given"]["150"][code].each do |value|
match["given"]["1xx"].keys.each do |code|
match["given"]["1xx"][code].each do |value|
remediated_field.append(MARC::Subfield.new(code, value))
end
end
Expand All @@ -63,9 +63,9 @@ def to_remediated
# generated because there were already remediated fields
def to_deprecated
match = _matching_remediated_field
match["given"]["450"].map do |f|
match["given"]["4xx"].map do |f|
sfields = @field.subfields.filter_map.with_index do |sf, index|
unless match["normalized"]["150"][sf.code]
unless match["normalized"]["1xx"][sf.code]
&.include?(normalized_sfs[index]["value"])
MARC::Subfield.new(sf.code, sf.value)
end
Expand All @@ -85,11 +85,11 @@ def to_deprecated
def _matching_deprecated_field
@_matching_deprecated_field ||= begin
@mapping.each_with_index do |this_to_that, index|
# Find the matching index of the 450 array where all of the
# Find the matching index of the 4xx array where all of the
# deprecated subfields are found in the bib record subject field
dep_match_index = this_to_that["450"].index.with_index do |deprecated_subfields, dep_index|
dep_match_index = this_to_that["4xx"].index.with_index do |deprecated_subfields, dep_index|
deprecated_subfields.keys.all? do |code|
@normalized_mapping[index]["450"][dep_index][code].all? do |dep_sf_value|
@normalized_mapping[index]["4xx"][dep_index][code].all? do |dep_sf_value|
_sf_in_field?(code: code, sf_value: dep_sf_value)
end
end
Expand All @@ -98,12 +98,12 @@ def _matching_deprecated_field
unless dep_match_index.nil?
return {
"given" => {
"150" => this_to_that["150"],
"450" => @mapping[index]["450"][dep_match_index]
"1xx" => this_to_that["1xx"],
"4xx" => @mapping[index]["4xx"][dep_match_index]
},
"normalized" => {
"150" => @normalized_mapping[index]["150"],
"450" => @normalized_mapping[index]["450"][dep_match_index]
"1xx" => @normalized_mapping[index]["1xx"],
"4xx" => @normalized_mapping[index]["4xx"][dep_match_index]
}
}
end
Expand All @@ -119,8 +119,8 @@ def _matching_remediated_field
@_matching_remediated_field ||= begin
# find the index in mapping where the field from the bib record contains all of the values
index = @mapping.index.with_index do |this_to_that, i|
this_to_that["150"].keys.all? do |code|
@normalized_mapping[i]["150"][code].all? do |dep_sf_value|
this_to_that["1xx"].keys.all? do |code|
@normalized_mapping[i]["1xx"][code].all? do |dep_sf_value|
_sf_in_field?(code: code, sf_value: dep_sf_value)
end
end
Expand Down
14 changes: 7 additions & 7 deletions umich_catalog_indexing/lib/common/subjects/remediation_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ def initialize(mapping = JSON.parse(File.read(File.join(S.translation_map_dir, "
def _create_normalized_mapping
@mapping.map do |heading|
new_heading = {}
heading["150"].keys.each do |code|
new_heading[code] = heading["150"][code].map do |value|
heading["1xx"].keys.each do |code|
new_heading[code] = heading["1xx"][code].map do |value|
normalize_sf(value)
end
end

dep_headings = heading["450"].map.with_index do |_, index|
dep_headings = heading["4xx"].map.with_index do |_, index|
dep_heading = {}
heading["450"][index].keys.each do |code|
dep_heading[code] = heading["450"][index][code].map do |value|
heading["4xx"][index].keys.each do |code|
dep_heading[code] = heading["4xx"][index][code].map do |value|
normalize_sf(value)
end
end
dep_heading
end
{
"150" => new_heading,
"450" => dep_headings
"1xx" => new_heading,
"4xx" => dep_headings
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def to_a
end

class Authority
AUTHORIZED_TERM_FIELDS = ["100", "110", "111", "130", "150", "151", "155"]
VARIANT_TERM_FIELDS = ["400", "410", "411", "430", "450", "451", "455"]
SUBFIELDS = ["a", "v", "x", "y", "z"]
# @param authority_record_id [String] authority record id
# @return [Job::TranslationMapGenerator::SubjecHeadingRemediation::Set::Authority] an Authority object
Expand All @@ -70,7 +72,7 @@ def initialize(data)
# code.
def remediated_term
out_hash = Hash.new { |h, key| h[key] = [] }
@record.fields("150").first.subfields.each do |sf|
AUTHORIZED_TERM_FIELDS.filter_map { |f| @record.fields(f)&.first }.first.subfields.each do |sf|
out_hash[sf.code].push(sf.value) if SUBFIELDS.include?(sf.code)
end
out_hash
Expand All @@ -80,7 +82,7 @@ def remediated_term
# deprecated terms. The keys of the hash are the subfield code, the
# value is an array of terms for the code.
def deprecated_terms
@record.fields("450").map do |field|
VARIANT_TERM_FIELDS.filter_map { |f| @record.fields(f) unless @record.fields.empty? }.flatten.map do |field|
out_hash = Hash.new { |h, key| h[key] = [] }
field.subfields.each do |sf|
out_hash[sf.code].push(sf.value) if SUBFIELDS.include?(sf.code)
Expand Down
16 changes: 8 additions & 8 deletions umich_catalog_indexing/spec/common/subject/field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
@field = remediated_field
@mapping = [
{
"150" => {
"1xx" => {
"a" => ["A"],
"x" => ["X1", "X2"],
"v" => ["V1", "V2"],
"y" => ["Y1", "Y2"],
"z" => ["Z1", "Z2"]
},
"450" => [
"4xx" => [
{
"a" => ["deprecated A"],
"x" => ["deprecated X1", "deprecated X2"],
Expand Down Expand Up @@ -71,13 +71,13 @@ def _normalize_sf(str)
expect(subject.remediable?).to eq(true)
end
it "is false when any subfield doesn't match deprecated field" do
@mapping[0]["450"][0]["v"][1] = "something other deprecated v"
@mapping[0]["4xx"][0]["v"][1] = "something other deprecated v"
expect(subject.remediable?).to eq(false)
end
it "is true when the second mapping entity has the matching deprecated field" do
@mapping.insert(0, {
"150" => {"a" => ["blah"]},
"450" => [{"a" => ["whatever"]}]
"1xx" => {"a" => ["blah"]},
"4xx" => [{"a" => ["whatever"]}]
})
@field = deprecated_field
expect(subject.remediable?).to eq(true)
Expand Down Expand Up @@ -111,7 +111,7 @@ def _normalize_sf(str)
expect(subject.already_remediated?).to eq(true)
end
it "returns false when it is missing a subfield" do
@mapping[0]["150"]["v"][1] = "something other than v"
@mapping[0]["1xx"]["v"][1] = "something other than v"
expect(subject.already_remediated?).to eq(false)
end
it "returns true when the matching field has an extra field" do
Expand All @@ -120,8 +120,8 @@ def _normalize_sf(str)
end
it "is true when the second mapping entity has the matching remediated field" do
@mapping.insert(0, {
"150" => {"a" => ["blah"]},
"450" => [{"a" => ["whatever"]}]
"1xx" => {"a" => ["blah"]},
"4xx" => [{"a" => ["whatever"]}]
})
expect(subject.already_remediated?).to eq(true)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"mms_id": 98188860307506380,
"record_format": "marc21_authority",
"title": "Mexico, Gulf of, Watershed",
"created_by": "Ex Libris",
"created_date": "2025-02-25Z",
"last_modified_by": "rednaal",
"last_modified_date": "2025-02-25Z",
"originating_system": "LIBRARY_OF_CONGRESS",
"originating_system_id": "98188860307506381",
"cataloging_level": {
"value": "00",
"desc": "Default Level"
},
"vocabulary": {
"value": "MIUSH",
"desc": "miush"
},
"anies": [
"<record><leader>00729nz a2200169n 4500</leader><controlfield tag=\"005\">20171103133952.0</controlfield><controlfield tag=\"008\">170906|| anannbabn |a ana </controlfield><controlfield tag=\"001\">98188860307506381</controlfield><datafield ind1=\" \" ind2=\" \" tag=\"010\"><subfield code=\"a\">sh2017004336</subfield></datafield><datafield ind1=\" \" ind2=\" \" tag=\"035\"><subfield code=\"a\">(DLC)sh2017004336</subfield></datafield><datafield ind1=\" \" ind2=\" \" tag=\"040\"><subfield code=\"a\">DLC</subfield><subfield code=\"b\">eng</subfield><subfield code=\"c\">DLC</subfield><subfield code=\"d\">MiU</subfield></datafield><datafield ind1=\" \" ind2=\" \" tag=\"151\"><subfield code=\"a\">Mexico, Gulf of, Watershed</subfield></datafield><datafield ind1=\" \" ind2=\" \" tag=\"455\"><subfield code=\"a\">Test Test Test</subfield></datafield><datafield ind1=\" \" ind2=\" \" tag=\"451\"><subfield code=\"a\">America, Gulf of, Watershed</subfield></datafield><datafield ind1=\" \" ind2=\" \" tag=\"550\"><subfield code=\"w\">g</subfield><subfield code=\"a\">Watersheds</subfield><subfield code=\"z\">Mexico</subfield></datafield><datafield ind1=\" \" ind2=\" \" tag=\"550\"><subfield code=\"w\">g</subfield><subfield code=\"a\">Watersheds</subfield><subfield code=\"z\">United States</subfield></datafield><datafield ind1=\" \" ind2=\" \" tag=\"670\"><subfield code=\"a\">Work cat.: 2017386748: El proceso de producción cafetalero en la región vertiente del Golfo de México, septiembre 2016:</subfield><subfield code=\"b\">t.p. ([cataloger's translation] The process of coffee production in the watershed of the Gulf of Mexico)</subfield></datafield><datafield ind1=\" \" ind2=\" \" tag=\"670\"><subfield code=\"a\">U.S. Fish &amp; Wildlife Service WWW site, viewed Sept. 6, 2017</subfield><subfield code=\"b\">(Gulf of Mexico Watershed)</subfield></datafield><datafield ind1=\" \" ind2=\"0\" tag=\"781\"><subfield code=\"z\">Mexico, Gulf of, Watershed</subfield></datafield><datafield ind1=\" \" ind2=\" \" tag=\"690\"><subfield code=\"a\">sla-lab created local heading based on DEIA Catalog Working Group resolution to keep the term preferred by library community 2025-02-25</subfield></datafield><datafield ind1=\" \" ind2=\" \" tag=\"035\"><subfield code=\"a\">(LIBRARY_OF_CONGRESS)988457839400041</subfield></datafield></record>"
],
"link": "https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/authorities/98188860307506381"
}
Loading
Loading