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) {
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);
+ }
+ }
+ }
+ }
+ }
+ }
}
}
}