[greenstone-devel] Re: patch for qualified dublin core export to DSpace

From Stephen De Gabrielle
DateTue, 20 Feb 2007 10:33:34 +0930
Subject [greenstone-devel] Re: patch for qualified dublin core export to DSpace
In-Reply-To (595b9ab20702152024x5241384fye011ea2e3513f2aa-mail-gmail-com)
Sorry, that was wrong; this is correct.

---

foreach my $data (@{$section_ptr->{'metadata'}}) {
my $escaped_value = &docprint::escape_text($data->[1]);
if ($data->[0]=~ m/^dc./) {
$data->[0] =~ tr/[A-Z]/[a-z]/;
my $pttemp = $data->[0] ;
print STDOUT " $pttemp x1 $pttemp ";
my $dc_element = $pttemp;
my $dc_qualifier = $pttemp;

$pttemp =~ m/^dc.b(w+).*.*/ ;
$dc_element = $1;
print STDOUT " $pttemp-x2:"$pttemp" ";
$pttemp =~ m/^dc.bw+.*(w*)$/ ;
$dc_qualifier = $1 ;

if ($dc_qualifier eq "") {
$dc_qualifier = "none"; # qualifier to default to "none" }
}
print STDOUT "element:"$dc_element" Qualifier:"$dc_qualifier" "; #

if (!defined $explicit_dc->{$dc_element}) {
$explicit_dc->{$dc_element} = [];
}
push(@{$explicit_dc->{$dc_element}},$escaped_value);

if (defined $version && ($version eq "oai_dc")) {
$all_text .= " <dc:$dc_element>$escaped_value</dc:$dc_element> ";
}
else {
# qualifier???
$all_text .= ' <dcvalue element="'. $dc_element.'" qualifier="'.
$dc_qualifier.'">'. $escaped_value. "</dcvalue> ";
}

}
elsif (($data->[0] =~ m/^ex./) || ($data->[0] !~ m/./)) {
$data->[0] =~ m/^(ex.)?(.*)/;
my $ex_element = $2;
my $lc_ex_element = lc($ex_element);

if (defined $dc_set->{$ex_element}) {
if (!defined $explicit_ex->{$lc_ex_element}) {
$explicit_ex->{$lc_ex_element} = [];
}
push(@{$explicit_ex->{$lc_ex_element}},$escaped_value);
}
}
}

----

On 2/16/07, Stephen De Gabrielle <spdegabrielle@gmail.com> wrote:
> Hi,
>
> I just did a little patch to 'sub get_dc_metadata' in BasPlugout.pm
> so the DSpace export works for qualified dublin core;
>
> DSpace expects
> <dublin_core>
> <dcvalue element="title" qualifier="none">A Tale of Two Cities</dcvalue>
> <dcvalue element="date" qualifier="issued">1990</dcvalue></dublin_core>
> <dcvalue element="title" qualifier="alternate" language="fr"
> ">J'aime les Printemps</dcvalue>
> </dublin_core>
> (from http://dspace.org/technology/system-docs/application.html#itemimporter )
>
> The following change to the beginning of 'sub get_dc_metadata' does the trick;
>
>
> # returns an XML representation of the dublin core metadata
> # if dc meta is not found, try ex mete
> sub get_dc_metadata {
> my $self = shift(@_);
> my ($doc_obj, $section, $version) = @_;
>
> # build up string of dublin core metadata
> $section="" unless defined $section;
>
> my $section_ptr = $doc_obj->_lookup_section($section);
> return "" unless defined $section_ptr;
>
>
> my $explicit_dc = {};
> my $explicit_ex = {};
>
> my $all_text="";
> foreach my $data (@{$section_ptr->{'metadata'}}){
> my $escaped_value = &docprint::escape_text($data->[1]);
> if ($data->[0]=~ m/^dc./) {
> $data->[0] =~ tr/[A-Z]/[a-z]/;
> my $pttemp = $data->[0] ;
> print STDOUT " $pttemp $pttemp ";
> my $dc_element = $pttemp;
> my $dc_qualifier = $pttemp;
>
> $dc_element =~ s/^dc.([^.]+)/$1/;
> $dc_qualifier = "none";
> print STDOUT " $pttemp $pttemp ";
>
> if (defined $2) {
> $dc_qualifier = $2;
> }
>
> print STDOUT "element $dc_element ";
> print STDOUT "qualifier $dc_qualifier ";
>
> if (!defined $explicit_dc->{$dc_element}) {
> $explicit_dc->{$dc_element} = [];
> }
> push(@{$explicit_dc->{$dc_element}},$escaped_value);
>
> if (defined $version && ($version eq "oai_dc")) {
> $all_text .= " <dc:$dc_element>$escaped_value</dc:$dc_element> ";
> }
> else {
> # qualifier???
> $all_text .= ' <dcvalue element="'. $dc_element.'" qualifier="'.
> $dc_qualifier.'">'. $escaped_value. "</dcvalue> ";
> }
>
> }
> elsif (($data->[0] =~ m/^ex./) || ($data->[0] !~ m/./)) {
> $data->[0] =~ m/^(ex.)?(.*)/;
> my $ex_element = $2;
> my $lc_ex_element = lc($ex_element);
>
> if (defined $dc_set->{$ex_element}) {
> if (!defined $explicit_ex->{$lc_ex_element}) {
> $explicit_ex->{$lc_ex_element} = [];
> }
> push(@{$explicit_ex->{$lc_ex_element}},$escaped_value);
> }
> }
> }
>
> # go through dc_set and for any element *not* defined in explicit_dc
> # that do exist in explicit_ex, add it in as metadata
>
>
> -function continues as normal-
>
>
> I hope this helps someone.
>
> Cheers,
>
> Stephen
>
> --
> Stephen De Gabrielle
>


--
--
Stephen De Gabrielle