'z' => '8' # Other
);
+# Maps 6XX subfield $2 values to their equivalent authority leader/11 value.
+# These occur when the indicator 2 == 7 ("Source specified in subfield $2")
+my %BIB_SF2_TO_AUTH = (
+ lcsh => 'a',
+ mesh => 'c',
+ nal => 'd',
+ rvm => 'v'
+);
+
my $start_time = localtime();
if($input_file) {
# indicator 2 (thesaurus) value, returns the ID of the first
# authority record in the set that matches the thesaurus.
sub find_matching_auth_for_thesaurus {
- my ($e, $cfield_ind2, $auth_ids) = @_;
+ my ($e, $bib_field, $auth_ids) = @_;
+
+ my $cfield_ind2 = $bib_field->indicator(2) || '';
+
+ if ($cfield_ind2 eq '7') {
+ # subject thesaurus code is embedded in the bib field subfield 2
+
+ my $thesaurus = $bib_field->subfield('2') || '';
+ announce("Found local thesaurus value $thesaurus");
+
+ $cfield_ind2 = $BIB_SF2_TO_AUTH{$thesaurus} || '';
+
+ if ($cfield_ind2) {
+ announce("Mapped local thesaurus '$thesaurus' to '$cfield_ind2'");
+ } else {
+ announce("No mapping found for local thesaurus '$thesaurus'");
+ return undef;
+ }
+ }
my $auth_leaders = $e->json_query({
select => {afr => ['record', 'value']},
}
next if !$match_tag;
- announce("Searching for matches (auth tag=$match_tag): ".
+ announce("Searching for matches (auth tag=$match_tag): \n\t".
Dumper(\@searches));
my @tags = ($match_tag);
# Find the best authority record to use for linking.
my $auth_id;
- my $stop_looking = 0;
- if ($bib_field->tag() ge 650 and $bib_field->tag() le 659) {
- # If the controlled bib field has an indicator 2 value
- # indicating the thesarus, use the first authority
- # record in the set with the same thesaurus.
+ if ($bib_field->tag() =~ /^65[015]/) {
+ # Using the indicator-2 value from the controlled bib
+ # field, find the first authority in the list of matches
+ # that uses the same thesaurus. If no such authority
+ # is found, no matching occurs.
# TODO: perhaps this step should be part of the
- # validateion API search call above.
+ # validation API search call above.
- my $cfield_ind2 = $bib_field->indicator(2);
-
- if (defined $cfield_ind2) {
-
- $auth_id = find_matching_auth_for_thesaurus(
- $e, $cfield_ind2, $validates) || '';
-
- announce("Thesaurus match for ind2=$cfield_ind2 returned $auth_id");
+ $auth_id = find_matching_auth_for_thesaurus(
+ $e, $bib_field, $validates) || '';
- # If we don't find a matching authority record using
- # the same thesuarus, we have nothing to link to.
- $stop_looking = 1;
- }
- }
-
- # No best record found above. Use the first in the list.
- $auth_id = $validates->[0] unless $auth_id or $stop_looking;
+ } else {
+ # For all other controlled fields, use the first
+ # authority record in the result set.
+ $auth_id = $validates->[0];
+ }
# Don't exit here just because we have no $auth_id. The
# bib field could have been changed above in the cleanup /
# delete phase.
if ($auth_id) {
- # Add the control number agency info from the matching
- # authority record to the controlled bib field.
+ # Add the auth ID and control number agency info from the
+ # matching authority record to the controlled bib field.
my $auth_003 = $e->json_query({
select => {afr => ['value']},