koha-to-dspace/marc2dc.pl

89 lines
2.6 KiB
Perl
Executable File

#!/usr/bin/perl -w
use MARC::Crosswalk::DublinCore;
use MARC::File::USMARC;
use utf8;
binmode(STDOUT, ":utf8");
$/ = chr(29);
print qq|<collection>\n|;
while (my $blob = <>) {
my $marc = MARC::Record->new_from_usmarc( $blob );
my $crosswalk = MARC::Crosswalk::DublinCore->new( qualified => 0 );
my $dc = $crosswalk->as_dublincore( $marc );
my $has_content = 0;
for( $dc->elements ) {
if (!$has_content) {
$has_content = 1;
print qq|<dublin_core>\n|;
}
my $element = lc($_->name);
my $qualifier = lc($_->qualifier);
my $scheme = lc($_->scheme);
my $content = $_->content;
$content =~ s/&/&amp;/gs;
$content =~ s/</&lt;/gs;
$content =~ s/>/&gt;/gs;
if ($element eq 'creator') {
$element = 'contributor';
$qualifier = 'author';
$content =~ s/[0-9]//g;
$content =~ s/comp\.//g;
$content =~ s/col\.//g;
$content =~ s/dir\.//g;
$content =~ s/pról\.//g;
$content =~ s/coord\.//g;
$content =~ s/ed\.//g;
$content =~ s/^\s+|\s+$//g;
}
if ($element eq 'format') {
$element = 'description';
$qualifier = '';
}
if ($element eq 'language') {
$qualifier = 'iso';
}
if ($element eq 'type') {
$element = 'type';
$qualifier = '';
}
if ($element eq 'subject') {
$content =~ s/[0-9]//g;
$content =~ s/^\s+|\s+$//g;
}
if ($element eq 'title') {
$content =~ s/\[[^][]*\]//g;
$content =~ s/^\s+|\s+$//g;
}
if ($element eq 'identifier') {
$element = 'relation';
$qualifier = 'uri';
}
printf qq| <dcvalue element="%s"|, $element;
printf qq| qualifier="%s"|, $qualifier if $qualifier;
printf qq| qualifier="%s"|, $scheme if $scheme and !$qualifier;
if ($element eq 'title' || $element eq 'description') {
#if ($element eq 'title' || $element eq 'description' || $element eq 'subject') {
printf qq| language="es_AR">%s</dcvalue>\n|, $content;
} else {
printf qq|>%s</dcvalue>\n|, $content;
}
}
print qq|</dublin_core>\n| if $has_content;
}
print qq|</collection>\n|;
exit;