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 |
|
|
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; |
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 |
|
|
81 |
'name', |
'name', |
82 |
'classification', |
'classification', |
83 |
'topic', |
'topic', |
84 |
|
'relatedItem', |
85 |
|
'partNumber', |
86 |
], |
], |
87 |
KeyAttr => { |
KeyAttr => { |
88 |
'namePart' => 'type', |
'namePart' => 'type', |
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 |
} |
} |
231 |
if ($t =~ m/([^:]+):\s+(.+)$/) { |
if ($t =~ m/([^:]+):\s+(.+)$/) { |
232 |
$tmp->{$1} = $2; |
$tmp->{$1} = $2; |
233 |
} else { |
} else { |
234 |
die "can't parse $t"; |
print STDERR "can't parse '$t' in ",Dumper($phy_desc); |
235 |
} |
} |
236 |
} |
} |
237 |
my $data = $tmp->{pagin}; |
my $data = $tmp->{pagin}; |
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") { |
if ($journal) { |
266 |
marc_add_rep($m_cache,'430','a',$ref->{relatedItem}->{titleInfo}->{title}); |
marc_add_rep($m_cache,'999','a',$pn); |
267 |
} else { |
} else { |
268 |
die "can't parse related item type $related" if ($related); |
marc_add_rep($m_cache,'225','v',$pn); |
269 |
|
} |
270 |
|
} |
271 |
|
} elsif ($related eq "preceding") { |
272 |
|
marc_add($m_cache,'520','a',$ri->{titleInfo}->{title}); |
273 |
|
if ($ri->{identifier}) { |
274 |
|
if ($ri->{identifier}->{type} eq "issn") { |
275 |
|
marc_add($m_cache,'520','x',$ri->{identifier}->{content}); |
276 |
|
} else { |
277 |
|
die "can't store identifier type $type"; |
278 |
|
} |
279 |
|
} |
280 |
|
marc_rep($m_cache,'520'); |
281 |
|
} else { |
282 |
|
die "can't parse related item type $related" if ($related); |
283 |
|
} |
284 |
} |
} |
285 |
} |
} |
286 |
|
|
287 |
marc_add_single($m_cache,'205','a',$ref->{originInfo}->{edition}); |
marc_add_single($m_cache,'205','a',$ref->{originInfo}->{edition}); |
288 |
|
|
289 |
|
marc_add($m_cache,'210','a',$ref->{originInfo}->{place}); |
290 |
|
|
291 |
my $publisher = $ref->{originInfo}->{publisher}; |
my $publisher = $ref->{originInfo}->{publisher}; |
292 |
if ($publisher =~ m,^(.+?)\s*/\s*(.+)$,) { |
if ($publisher =~ m,^(.+?)\s*/\s*(.+)$,) { |
293 |
marc_add($m_cache,'210','a', $2); |
marc_add($m_cache,'210','a', $2); |
296 |
marc_add($m_cache,'210','c', $publisher); |
marc_add($m_cache,'210','c', $publisher); |
297 |
} |
} |
298 |
|
|
|
marc_add($m_cache,'210','a',$ref->{originInfo}->{place}); |
|
299 |
marc_add($m_cache,'210','d',$ref->{originInfo}->{dateIssued}); |
marc_add($m_cache,'210','d',$ref->{originInfo}->{dateIssued}); |
300 |
|
|
301 |
marc_single($m_cache,'210'); |
marc_single($m_cache,'210'); |
306 |
print "$nr " if ($nr % 100 == 0); |
print "$nr " if ($nr % 100 == 0); |
307 |
|
|
308 |
# dump record |
# dump record |
309 |
my $m=$marc->createrecord({leader=>"00000nam 2200000 a 4500"}); |
my $bib_level = "m"; |
310 |
|
$bib_level = "s" if ($journal); |
311 |
|
my $m=$marc->createrecord({leader=>"00000na".$bib_level." 2200000 a 4500"}); |
312 |
|
|
313 |
foreach my $fld (keys %{$m_cache->{array}}) { |
foreach my $fld (keys %{$m_cache->{array}}) { |
314 |
foreach my $arr (@{$m_cache->{array}->{$fld}}) { |
foreach my $arr (@{$m_cache->{array}->{$fld}}) { |