96 lines
3.0 KiB
Perl
Executable File
96 lines
3.0 KiB
Perl
Executable File
#!/usr/bin/perl -w
|
|
|
|
use MARC::Crosswalk::DublinCore;
|
|
use MARC::File::USMARC;
|
|
use utf8;
|
|
binmode(STDOUT, ":utf8");
|
|
|
|
$/ = chr(29); # MARC record separator
|
|
|
|
print qq|<collection>\n|;
|
|
|
|
while (my $blob = <>) { # suck in one MARC record at a time
|
|
|
|
print qq|<dublin_core>\n|;
|
|
|
|
# convert the MARC to DC
|
|
my $marc = MARC::Record->new_from_usmarc( $blob );
|
|
my $crosswalk = MARC::Crosswalk::DublinCore->new( qualified => 0 );
|
|
my $dc = $crosswalk->as_dublincore( $marc );
|
|
|
|
# output the DC as XML
|
|
for( $dc->elements ) {
|
|
my $element = lc($_->name);
|
|
my $qualifier = lc($_->qualifier);
|
|
my $scheme = lc($_->scheme);
|
|
my $content = $_->content;
|
|
|
|
##print $_->content;
|
|
|
|
#print qq|$element\n|;
|
|
#print qq|$qualifier\n|;
|
|
#print qq|$scheme\n|;
|
|
#print qq|$content\n|;
|
|
|
|
# escape reserved characters
|
|
$content =~ s/&/&/gs;
|
|
$content =~ s/</</gs;
|
|
$content =~ s/>/>/gs;
|
|
|
|
# munge attributes for DSpace compatibility
|
|
if ($element eq 'creator') {
|
|
$element = 'contributor';
|
|
$qualifier = 'author';
|
|
$content =~ s/[0-9]//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;
|
|
}
|
|
}
|
|
|
|
# if ($ARGV[0]) {
|
|
# printf qq| <dcvalue element="dspace"|, $element;
|
|
# printf qq| qualifier="entity"|, $qualifier if $qualifier;
|
|
# printf qq| qualifier="%s"|, $scheme if $scheme and !$qualifier;
|
|
# printf qq|>%s</dcvalue>\n|, $content;
|
|
# }
|
|
|
|
print qq|</dublin_core>\n|;
|
|
}
|
|
|
|
print qq|</collection>\n|;
|
|
|
|
exit;
|