--- trunk/tools/mods2unimarc.pl 2004/05/15 18:54:41 327 +++ trunk/tools/mods2unimarc.pl 2004/05/16 22:12:02 330 @@ -6,7 +6,7 @@ =head1 SYNOPSIS -mods2marc.pl mods.xml export.marc +mods2marc.pl export.marc mods.xml [mods2.xml ... ] =head1 DESCRIPTION @@ -44,10 +44,8 @@ use Data::Dumper; -my $xml_file = "/data/tehnika/fer/all.xml"; -$xml_file = "/data/tehnika/fer/modsFER_1.xml"; -$xml_file = "/data/tehnika/fer/mods-small.xml"; -my $marc_file = "fer.marc"; +my $marc_file = shift @ARGV || die "$0: need MARC export file"; +die "$0: need at least one MODS XML file" if (! @ARGV); $|=1; my $nr = 0; @@ -63,10 +61,14 @@ my $utf2iso = Text::Iconv->new("UTF8", $ENCODING); -print "$xml_file: "; -$twig->parsefile($xml_file); -$twig->purge; -print "$nr\nSaving MARC file...\n"; +foreach my $xml_file (@ARGV) { + print "$xml_file: "; + $twig->parsefile($xml_file); + $twig->purge; + print "$nr\n"; +} + +print "Saving MARC file...\n"; $marc->output({file=>"> $marc_file",'format'=>"usmarc"}); @@ -79,6 +81,8 @@ 'name', 'classification', 'topic', + 'relatedItem', + 'partNumber', ], KeyAttr => { 'namePart' => 'type', @@ -213,6 +217,8 @@ marc_add_rep($m_cache,'010','a',$ref->{identifier}->{content}); } elsif ($type eq "issn") { marc_add_rep($m_cache,'011','a',$ref->{identifier}->{content}); + } elsif ($type eq "uri") { + marc_add_rep($m_cache,'856','u',$ref->{identifier}->{content}); } else { die "unknown identifier type $type"; } @@ -225,7 +231,7 @@ if ($t =~ m/([^:]+):\s+(.+)$/) { $tmp->{$1} = $2; } else { - die "can't parse $t"; + print STDERR "can't parse '$t' in ",Dumper($phy_desc); } } my $data = $tmp->{pagin}; @@ -250,21 +256,38 @@ } } - my $related = $ref->{relatedItem}->{type}; - if ($related) { - if ($related eq "series") { - marc_add($m_cache,'225','a',$ref->{relatedItem}->{titleInfo}->{title}); - marc_add($m_cache,'999','a',$ref->{relatedItem}->{titleInfo}->{partNumber}); - marc_rep($m_cache,'225','999'); - } elsif ($related eq "preceding") { - marc_add_rep($m_cache,'430','a',$ref->{relatedItem}->{titleInfo}->{title}); - } else { - die "can't parse related item type $related" if ($related); + foreach my $ri (@{$ref->{relatedItem}}) { + my $related = $ri->{type}; + if ($related) { + if ($related eq "series") { + marc_add_rep($m_cache,'225','a',$ri->{titleInfo}->{title}); + foreach my $pn (@{$ri->{titleInfo}->{partNumber}}) { + if ($journal) { + marc_add_rep($m_cache,'999','a',$pn); + } else { + marc_add_rep($m_cache,'225','v',$pn); + } + } + } elsif ($related eq "preceding") { + marc_add($m_cache,'520','a',$ri->{titleInfo}->{title}); + if ($ri->{identifier}) { + if ($ri->{identifier}->{type} eq "issn") { + marc_add($m_cache,'520','x',$ri->{identifier}->{content}); + } else { + die "can't store identifier type $type"; + } + } + marc_rep($m_cache,'520'); + } else { + die "can't parse related item type $related" if ($related); + } } } marc_add_single($m_cache,'205','a',$ref->{originInfo}->{edition}); + marc_add($m_cache,'210','a',$ref->{originInfo}->{place}); + my $publisher = $ref->{originInfo}->{publisher}; if ($publisher =~ m,^(.+?)\s*/\s*(.+)$,) { marc_add($m_cache,'210','a', $2); @@ -273,7 +296,6 @@ marc_add($m_cache,'210','c', $publisher); } - marc_add($m_cache,'210','a',$ref->{originInfo}->{place}); marc_add($m_cache,'210','d',$ref->{originInfo}->{dateIssued}); marc_single($m_cache,'210'); @@ -284,7 +306,9 @@ print "$nr " if ($nr % 100 == 0); # dump record - my $m=$marc->createrecord({leader=>"00000nam 2200000 a 4500"}); + my $bib_level = "m"; + $bib_level = "s" if ($journal); + my $m=$marc->createrecord({leader=>"00000na".$bib_level." 2200000 a 4500"}); foreach my $fld (keys %{$m_cache->{array}}) { foreach my $arr (@{$m_cache->{array}->{$fld}}) {