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 |
} |
} |
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 |
|
|
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}}) { |