/[webpac]/trunk2/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 /trunk2/tools/mods2unimarc.pl

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

trunk/tools/mods2unimarc.pl revision 327 by dpavlin, Sat May 15 18:54:41 2004 UTC trunk2/tools/mods2unimarc.pl revision 337 by dpavlin, Thu Jun 10 19:22:40 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 55  my $nr = 0; Line 53  my $nr = 0;
53  my $marc = MARC->new;  my $marc = MARC->new;
54    
55  my $ENCODING = 'ISO-8859-2';  my $ENCODING = 'ISO-8859-2';
56    $ENCODING = 'windows-1250';
57    
58  my $twig=XML::Twig->new(  my $twig=XML::Twig->new(
59          twig_roots => { 'mods' => \&mods },          twig_roots => { 'mods' => \&mods },
# Line 63  my $twig=XML::Twig->new( Line 62  my $twig=XML::Twig->new(
62    
63  my $utf2iso = Text::Iconv->new("UTF8", $ENCODING);  my $utf2iso = Text::Iconv->new("UTF8", $ENCODING);
64    
65  print "$xml_file: ";  foreach my $xml_file (@ARGV) {
66  $twig->parsefile($xml_file);          print "$xml_file: ";
67  $twig->purge;          $twig->parsefile($xml_file);
68  print "$nr\nSaving MARC file...\n";          $twig->purge;
69            print "$nr\n";
70    }
71    
72    print "Saving MARC file...\n";
73    
74  $marc->output({file=>"> $marc_file",'format'=>"usmarc"});  $marc->output({file=>"> $marc_file",'format'=>"usmarc"});
75    
# Line 79  sub mods { Line 82  sub mods {
82                          'name',                          'name',
83                          'classification',                          'classification',
84                          'topic',                          'topic',
85                            'relatedItem',
86                            'partNumber',
87                  ],                  ],
88                  KeyAttr => {                  KeyAttr => {
89                          'namePart' => 'type',                          'namePart' => 'type',
# Line 213  sub mods { Line 218  sub mods {
218                          marc_add_rep($m_cache,'010','a',$ref->{identifier}->{content});                          marc_add_rep($m_cache,'010','a',$ref->{identifier}->{content});
219                  } elsif ($type eq "issn") {                  } elsif ($type eq "issn") {
220                          marc_add_rep($m_cache,'011','a',$ref->{identifier}->{content});                          marc_add_rep($m_cache,'011','a',$ref->{identifier}->{content});
221                    } elsif ($type eq "uri") {
222                            marc_add_rep($m_cache,'856','u',$ref->{identifier}->{content});
223                  } else {                  } else {
224                          die "unknown identifier type $type";                          die "unknown identifier type $type";
225                  }                  }
# Line 225  sub mods { Line 232  sub mods {
232                          if ($t =~ m/([^:]+):\s+(.+)$/) {                          if ($t =~ m/([^:]+):\s+(.+)$/) {
233                                  $tmp->{$1} = $2;                                  $tmp->{$1} = $2;
234                          } else {                          } else {
235                                  die "can't parse $t";                                  print STDERR "can't parse '$t' in ",Dumper($phy_desc);
236                          }                          }
237                  }                  }
238                  my $data = $tmp->{pagin};                  my $data = $tmp->{pagin};
# Line 238  sub mods { Line 245  sub mods {
245          }          }
246          marc_rep($m_cache,'215');          marc_rep($m_cache,'215');
247    
248          marc_add_single($m_cache,'001',undef,$ref->{recordInfo}->{recordIdentifier});          my $mfn = $ref->{recordInfo}->{recordIdentifier};
249            $mfn =~ s/[^0-9]//g;
250            marc_add_single($m_cache,'001',undef,$mfn);
251    
252          marc_add($m_cache,'200','a',$ref->{titleInfo}->{title});          marc_add($m_cache,'200','a',$ref->{titleInfo}->{title});
253          marc_add($m_cache,'200','e',$ref->{titleInfo}->{subTitle});          marc_add($m_cache,'200','e',$ref->{titleInfo}->{subTitle});
# Line 250  sub mods { Line 259  sub mods {
259                  }                  }
260          }          }
261    
262          my $related = $ref->{relatedItem}->{type};          foreach my $ri (@{$ref->{relatedItem}}) {
263          if ($related) {                  my $related = $ri->{type};
264                  if ($related eq "series") {                  if ($related) {
265                          marc_add($m_cache,'225','a',$ref->{relatedItem}->{titleInfo}->{title});                          if ($related eq "series") {
266                          marc_add($m_cache,'999','a',$ref->{relatedItem}->{titleInfo}->{partNumber});                                  marc_add_rep($m_cache,'225','a',$ri->{titleInfo}->{title});
267                          marc_rep($m_cache,'225','999');                                  foreach my $pn (@{$ri->{titleInfo}->{partNumber}}) {
268                  } elsif ($related eq "preceding") {                                          if ($journal) {
269                          marc_add_rep($m_cache,'430','a',$ref->{relatedItem}->{titleInfo}->{title});                                                  marc_add_rep($m_cache,'999','a',$pn);
270                  } else {                                          } else {
271                          die "can't parse related item type $related" if ($related);                                                  marc_add_rep($m_cache,'225','v',$pn);
272                                            }
273                                    }
274                            } elsif ($related eq "preceding") {
275                                    marc_add($m_cache,'520','a',$ri->{titleInfo}->{title});
276                                    if ($ri->{identifier}) {
277                                            if ($ri->{identifier}->{type} eq "issn") {
278                                                    marc_add($m_cache,'520','x',$ri->{identifier}->{content});
279                                            } else {
280                                                    die "can't store identifier type $type";
281                                            }
282                                    }
283                                    marc_rep($m_cache,'520');
284                            } else {
285                                    die "can't parse related item type $related" if ($related);
286                            }
287                  }                  }
288          }          }
289    
290          marc_add_single($m_cache,'205','a',$ref->{originInfo}->{edition});          marc_add_single($m_cache,'205','a',$ref->{originInfo}->{edition});
291    
292            marc_add($m_cache,'210','a',$ref->{originInfo}->{place});
293    
294          my $publisher = $ref->{originInfo}->{publisher};          my $publisher = $ref->{originInfo}->{publisher};
295          if ($publisher =~ m,^(.+?)\s*/\s*(.+)$,) {          if ($publisher =~ m,^(.+?)\s*/\s*(.+)$,) {
296                  marc_add($m_cache,'210','a', $2);                  marc_add($m_cache,'210','a', $2);
# Line 273  sub mods { Line 299  sub mods {
299                  marc_add($m_cache,'210','c', $publisher);                  marc_add($m_cache,'210','c', $publisher);
300          }          }
301    
         marc_add($m_cache,'210','a',$ref->{originInfo}->{place});  
302          marc_add($m_cache,'210','d',$ref->{originInfo}->{dateIssued});          marc_add($m_cache,'210','d',$ref->{originInfo}->{dateIssued});
303    
304          marc_single($m_cache,'210');          marc_single($m_cache,'210');
# Line 284  sub mods { Line 309  sub mods {
309          print "$nr " if ($nr % 100 == 0);          print "$nr " if ($nr % 100 == 0);
310    
311          # dump record          # dump record
312          my $m=$marc->createrecord({leader=>"00000nam  2200000 a 4500"});          my $bib_level = "m";
313            $bib_level = "s" if ($journal);
314            my $m=$marc->createrecord({leader=>"00000na".$bib_level."  2200000 a 4500"});
315    
316          foreach my $fld (keys %{$m_cache->{array}}) {          foreach my $fld (keys %{$m_cache->{array}}) {
317                  foreach my $arr (@{$m_cache->{array}->{$fld}}) {                  foreach my $arr (@{$m_cache->{array}->{$fld}}) {

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

  ViewVC Help
Powered by ViewVC 1.1.26