From b7f698b097aef9f35477c23fdc28670f5c23110a Mon Sep 17 00:00:00 2001 From: Nick Duncan Date: Wed, 7 Oct 2015 17:31:43 -0400 Subject: [PATCH] KMAIN-1897 Fix Authority Linking Script Authority Linking Script Now Recognizes Matches From Bib 65X to Auth 008/11 Signed-off-by: Nick Duncan --- KCLS/linking/authority_control_fields.pl | 66 ++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/KCLS/linking/authority_control_fields.pl b/KCLS/linking/authority_control_fields.pl index d264ade03b..176cb95265 100755 --- a/KCLS/linking/authority_control_fields.pl +++ b/KCLS/linking/authority_control_fields.pl @@ -618,7 +618,9 @@ foreach my $rec_id (@records) { print STDERR "Search for matching authority failed; record # $rec_id\n"; next if (!$changed); } - + + my $num_records = scalar(@$validates); + # Only add linking if one or more was found, but we may have changed # the record already if in --refresh mode. if (scalar(@$validates) > 0) { @@ -628,21 +630,55 @@ foreach my $rec_id (@records) { foreach my $auth_zero (@$validates) { $bib_field->delete_subfield(code => '0', match => qr/\)$auth_zero$/); } - - # Okay, we have a matching authority control; time to - # add the magical subfield 0. Use the first returned auth - # record as a match. - my $auth_id = @$validates[0]; - my $auth_rec = $e->retrieve_authority_record_entry($auth_id); - my $auth_marc = MARC::Record->new_from_xml($auth_rec->marc()); - if ($auth_marc->field('003')) { - my $cni = $auth_marc->field('003')->data(); - $bib_field->add_subfields('0' => "($cni)$auth_id"); - $changed = 1; - } else { - print "Authority # $auth_id missing field '003'\n"; - next if (!$changed); + for(my $i = 0; $i < $num_records; $i++) + { + # Okay, we have a matching authority control; time to + # add the magical subfield 0. Use the first returned auth + # record as a match. + my $auth_id = @$validates[$i]; + my $auth_rec = $e->retrieve_authority_record_entry($auth_id); + my $auth_marc = MARC::Record->new_from_xml($auth_rec->marc()); + + my %Auth2BibIndicatorTwo = ( + 'a' => '0', # Library of Congress Subject Headings (ADULT) + 'b' => '1', # Library of Congress Subject Headings (JUVENILE) + 'c' => '2', # Medical Subject Headings + 'd' => '3', # National Agricultural Library Subject Authority File + 'n' => '4', # Source not specified + 'k' => '5', # Canadian Subject Headings + 'v' => '6', # Répertoire de vedettes-matière + 'n' => '7', # Source specified in subfield $2 + 'z' => '8' # Other + ); + + my @marc_fieldz = $marc->fields(); + my $Auth_Indic = substr($auth_marc->field('008')->data(), 10, 1); + while ((my $key, my $value) = each (%Auth2BibIndicatorTwo)) + { + if($Auth_Indic eq $key) + { + foreach my $auth_field (@marc_fieldz) + { + if($auth_field->tag() ge 650 && $auth_field->tag() le 659) # 650-659 + { + #print "Trying To Match Against: " . $Auth2BibIndicatorTwo{$key} . "\n"; + if($auth_field->indicator(2) eq $Auth2BibIndicatorTwo{$key}) + { + #print "Found Match Between Bib Record(" . $rec_id . ") and Auth Record(" . $auth_marc->field('901')->subfield('c') . ")\n"; + if ($auth_marc->field('003')) { + my $cni = $auth_marc->field('003')->data(); + $bib_field->add_subfields('0' => "($cni)$auth_id"); + $changed = 1; + } else { + print "Authority # $auth_id missing field '003'\n"; + next if (!$changed); + } + } + } + } + } + } } } } -- 2.11.0