/[webpac]/trunk/tools/mods2unimarc.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/tools/mods2unimarc.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 327 by dpavlin, Sat May 15 18:54:41 2004 UTC revision 328 by dpavlin, Sat May 15 19:52:01 2004 UTC
# Line 6  mods2marc.pl - convert MODS XML back to Line 6  mods2marc.pl - convert MODS XML back to
6    
7  =head1 SYNOPSIS  =head1 SYNOPSIS
8    
9  mods2marc.pl mods.xml export.marc  mods2marc.pl export.marc mods.xml [mods2.xml ... ]
10    
11  =head1 DESCRIPTION  =head1 DESCRIPTION
12    
# Line 44  use Text::Iconv; Line 44  use Text::Iconv;
44    
45  use Data::Dumper;  use Data::Dumper;
46    
47  my $xml_file = "/data/tehnika/fer/all.xml";  my $marc_file = shift @ARGV || die "$0: need MARC export file";
48  $xml_file = "/data/tehnika/fer/modsFER_1.xml";  die "$0: need at least one MODS XML file" if (! @ARGV);
 $xml_file = "/data/tehnika/fer/mods-small.xml";  
 my $marc_file = "fer.marc";  
49    
50  $|=1;  $|=1;
51  my $nr = 0;  my $nr = 0;
# Line 63  my $twig=XML::Twig->new( Line 61  my $twig=XML::Twig->new(
61    
62  my $utf2iso = Text::Iconv->new("UTF8", $ENCODING);  my $utf2iso = Text::Iconv->new("UTF8", $ENCODING);
63    
64  print "$xml_file: ";  foreach my $xml_file (@ARGV) {
65  $twig->parsefile($xml_file);          print "$xml_file: ";
66  $twig->purge;          $twig->parsefile($xml_file);
67  print "$nr\nSaving MARC file...\n";          $twig->purge;
68            print "$nr\n";
69    }
70    
71    print "Saving MARC file...\n";
72    
73  $marc->output({file=>"> $marc_file",'format'=>"usmarc"});  $marc->output({file=>"> $marc_file",'format'=>"usmarc"});
74    
# Line 79  sub mods { Line 81  sub mods {
81                          'name',                          'name',
82                          'classification',                          'classification',
83                          'topic',                          'topic',
84                            'relatedItem',
85                            'partNumber',
86                  ],                  ],
87                  KeyAttr => {                  KeyAttr => {
88                          'namePart' => 'type',                          'namePart' => 'type',
# Line 213  sub mods { Line 217  sub mods {
217                          marc_add_rep($m_cache,'010','a',$ref->{identifier}->{content});                          marc_add_rep($m_cache,'010','a',$ref->{identifier}->{content});
218                  } elsif ($type eq "issn") {                  } elsif ($type eq "issn") {
219                          marc_add_rep($m_cache,'011','a',$ref->{identifier}->{content});                          marc_add_rep($m_cache,'011','a',$ref->{identifier}->{content});
220                    } elsif ($type eq "uri") {
221                            marc_add_rep($m_cache,'856','u',$ref->{identifier}->{content});
222                  } else {                  } else {
223                          die "unknown identifier type $type";                          die "unknown identifier type $type";
224                  }                  }
# Line 250  sub mods { Line 256  sub mods {
256                  }                  }
257          }          }
258    
259          my $related = $ref->{relatedItem}->{type};          foreach my $ri (@{$ref->{relatedItem}}) {
260          if ($related) {                  my $related = $ri->{type};
261                  if ($related eq "series") {                  if ($related) {
262                          marc_add($m_cache,'225','a',$ref->{relatedItem}->{titleInfo}->{title});                          if ($related eq "series") {
263                          marc_add($m_cache,'999','a',$ref->{relatedItem}->{titleInfo}->{partNumber});                                  marc_add_rep($m_cache,'225','a',$ri->{titleInfo}->{title});
264                          marc_rep($m_cache,'225','999');                                  foreach my $pn (@{$ri->{titleInfo}->{partNumber}}) {
265                  } elsif ($related eq "preceding") {                                          marc_add_rep($m_cache,'999','a',$pn);
266                          marc_add_rep($m_cache,'430','a',$ref->{relatedItem}->{titleInfo}->{title});                                  }
267                  } else {                          } elsif ($related eq "preceding") {
268                          die "can't parse related item type $related" if ($related);                                  marc_add_rep($m_cache,'430','a',$ri->{titleInfo}->{title});
269                            } else {
270                                    die "can't parse related item type $related" if ($related);
271                            }
272                  }                  }
273          }          }
274    
# Line 284  sub mods { Line 293  sub mods {
293          print "$nr " if ($nr % 100 == 0);          print "$nr " if ($nr % 100 == 0);
294    
295          # dump record          # dump record
296          my $m=$marc->createrecord({leader=>"00000nam  2200000 a 4500"});          my $bib_level = "m";
297            $bib_level = "s" if ($journal);
298            my $m=$marc->createrecord({leader=>"00000na".$bib_level."  2200000 a 4500"});
299    
300          foreach my $fld (keys %{$m_cache->{array}}) {          foreach my $fld (keys %{$m_cache->{array}}) {
301                  foreach my $arr (@{$m_cache->{array}->{$fld}}) {                  foreach my $arr (@{$m_cache->{array}->{$fld}}) {

Legend:
Removed from v.327  
changed lines
  Added in v.328

  ViewVC Help
Powered by ViewVC 1.1.26