From: Galen Charlton Date: Mon, 15 Mar 2010 16:34:57 +0000 (+0000) Subject: fix retrieval of correct column headers and data from non-holdings tags X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=commitdiff_plain;h=f066013ab0a65299aaddf1466c438585e95ee2bf fix retrieval of correct column headers and data from non-holdings tags This work was sponsored by the Indiana State Library. --- diff --git a/Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm b/Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm index b98a7ff..77a96dc 100644 --- a/Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm +++ b/Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm @@ -94,6 +94,22 @@ sub parse_record { for my $f (@fields) { process_field($f, $crec) } + # fill in blank values if needed + for my $mappedtag ( @{ $sfmap->tags }) { + unless (exists $crec->{tmap}{$mappedtag}) { + push @{ $crec->{tags} }, {}; + for my $mappedsub ( @{ $sfmap->subfields($mappedtag) } ) { + my $fieldname = $sfmap->field($mappedtag, $mappedsub); + my $mods = $sfmap->mods($fieldname); + next if $mods->{multi}; + $crec->{tags}[-1]{uni}{$mappedsub} = ''; + $crec->{tags}[-1]{multi} = undef; + $crec->{tags}[-1]{tag} = $mappedtag; + } + push @{ $crec->{tmap}{$mappedtag} }, $#{ $crec->{tags} }; + } + } + # cleanup memory and increment pointer $record->purge; $reccount++; @@ -137,10 +153,6 @@ sub process_field { $crec->{tags}[-1]{uni}{$mappedsub} = '' unless defined $crec->{tags}[-1]{uni}{$mappedsub}; } - for my $mappedtag ( @{ $sfmap->tags }) { - $crec->{tmap}{$mappedtag} = undef - unless defined $crec->{tmap}{$mappedtag}; - } } } diff --git a/extract_holdings b/extract_holdings index d39aac9..fb44929 100755 --- a/extract_holdings +++ b/extract_holdings @@ -91,19 +91,19 @@ sub extract_holdings { $limit = $#{ $rec->{tmap}{$othertag} }; } foreach my $idx (0..$limit) { - for my $sub ( sort keys %{$rec->{tags}[$idx]{uni}} ) { - if ($m->first_only($rec->{tags}[$idx]{tag}, $sub)) { - push @out, ($k == 1) ? $rec->{tags}[$idx]{uni}{$sub} : ''; + my $tag_idx = $rec->{tmap}{$othertag}[$idx]; + for my $sub ( sort keys %{$rec->{tags}[$tag_idx]{uni}} ) { + if ($m->first_only($rec->{tags}[$tag_idx]{tag}, $sub)) { + push @out, ($k == 1) ? $rec->{tags}[$tag_idx]{uni}{$sub} : ''; } else { - push @out, $rec->{tags}[$idx]{uni}{$sub}; + push @out, $rec->{tags}[$tag_idx]{uni}{$sub}; } - print HOLDINGS "l_", $m->name($rec->{tags}[$idx]{tag}, $sub), ", " - unless $j; + print HOLDINGS "l_", $m->name($rec->{tags}[$tag_idx]{tag}, $sub), ", " unless $j; } next unless exists($multis->{$othertag}); for my $sub ( sort keys %{$multis->{$othertag}} ) { - next if $m->first_only($rec->{tags}[$idx]{tag}, $sub) and ($k > 1); - for my $value ( @{$rec->{tags}[$idx]{multi}{$sub}} ) { + next if $m->first_only($rec->{tags}[$tag_idx]{tag}, $sub) and ($k > 1); + for my $value ( @{$rec->{tags}[$tag_idx]{multi}{$sub}} ) { my $fh = $MULTIFILE{"$othertag$sub"}; print $fh join("\t", $rec->{egid}, $j, $value), "\n"; }