Changeset 13196


Ignore:
Timestamp:
2006-10-30T16:14:32+13:00 (17 years ago)
Author:
shaoqun
Message:

now all subfield values of a field, instead of the first one, are used for that field if no subfield mappings exist in the marctodc mapping file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugins/XMLMARCPlug.pm

    r13153 r13196  
    6666    $self->{'encoding'} = "";
    6767    $self->{'marc_mapping'} = {};
    68     $self->{'current_attr'} = "";
     68    $self->{'current_code'} = "";
     69    $self->{'current_tag'} = "";
    6970    $self->{'current_element'} = "";
    7071    $self->{'metadata_mapping'} = undef;
     72    $self->{'num_processed'} = 0;
    7173   
    7274    return bless $self, $class;
     
    227229    $self->set_OID($doc_obj, $doc_obj->get_OID() , $self->{'record_count'});
    228230
     231    my $outhandle = $self->{'outhandle'};
     232    print $outhandle "Record $self->{'record_count'} - XMLMARCPlug: processing $self->{'file'}\n" if $self->{'verbosity'} > 1;
     233
    229234        $self->{'record_count'}++;
    230235        $self->{'doc_obj'} = $doc_obj;       
    231    
    232     }
    233 
    234      ## get the marc code, for example 520
     236    $self->{'num_processed'}++;
     237
     238    }
     239   
     240    ## get the marc code, for example 520
    235241     if ($element eq "datafield") {
    236242     if (defined $attr_map{'tag'} and $attr_map{'tag'} ne ""){
    237          $self->{'current_attr'} = $attr_map{tag}; 
     243         $self->{'current_tag'} = $attr_map{tag}; 
    238244     }
    239245     }
    240246
     247
    241248    ## append the subcode to the marc code for example 520a or 520b
    242249    if ($element eq "subfield"){
    243     if (defined $attr_map{'code'} and $attr_map{'code'} ne "" and $self->{'current_attr'} ne ""){
    244         $self->{'current_attr'} = $self->{'current_attr'}.$attr_map{'code'};
     250    if (defined $attr_map{'code'} and $attr_map{'code'} ne "" and $self->{'current_tag'} ne ""){
     251        $self->{'current_code'} = $attr_map{'code'};
    245252    }
    246253    }
     
    276283       ##map { print STDERR $_."=>".$metadata_mapping->{$_}."\n"; } keys %$metadata_mapping;
    277284
    278     foreach my $code (keys %$marc_mapping){
     285    foreach my $marc_field (keys %$metadata_mapping){
    279286        my ($meta_name,$meta_value);
    280         if (defined $metadata_mapping->{$code} and $metadata_mapping->{$code} ne ""){
    281             $meta_name = $metadata_mapping->{$code};
    282         $meta_value = $marc_mapping->{$code};
    283         $doc_obj->add_utf8_metadata($doc_obj->get_top_section(),$meta_name, $meta_value);
    284         }
    285         else{ ##strip the subcode and try lookup again
    286         $code =~ /(\d{3})/;
    287         ## get the firt three digits
    288         $code = $1 ;
    289         if (defined $metadata_mapping->{$code} and $metadata_mapping->{$code} ne ""){
    290             $meta_name = $metadata_mapping->{$code};
    291             ## get the first entry starting with this code from the marc_mapping           
    292             foreach my $key (keys %$marc_mapping){
    293             my $old_key = $key;
    294             $key =~ /(\d{3})/;
    295             ## get the firt three digits
    296             $key = $1 ;
    297             if ($code =~ /$key/){
    298                 $meta_value = $marc_mapping->{$old_key};
    299                 last;
     287        my $matched_field = $marc_mapping->{$marc_field};
     288        my $subfield = undef;
     289        if (defined $matched_field){
     290        ## test whether this field has subfield
     291        if ($marc_field =~ /\d\d\d(\w)/){
     292            $subfield = $1;
     293        }
     294        $meta_name = $metadata_mapping->{$marc_field};
     295
     296        if (defined $subfield){
     297            my %mapped_subfield = {@$matched_field};
     298            $meta_value = $mapped_subfield{$subfield};
     299        }
     300        else{ ## get all values
     301            my $i =0;
     302            foreach my $value (@$matched_field){
     303            if ($i%2 != 0){
     304                $meta_value .= $value." ";
    300305            }
    301             }
    302             if (defined $meta_value and $meta_value ne ""){
    303             $doc_obj->add_utf8_metadata($doc_obj->get_top_section(),$meta_name, $meta_value);
     306            $i++;
    304307            }
    305308        }
    306         } 
     309       
     310        ## escape [ and ]
     311        $meta_value =~ s/\[/\\\[/g;
     312        $meta_value =~ s/\]/\\\]/g;
     313        ##print STDERR  "$meta_name=$meta_value\n";
     314        $doc_obj->add_utf8_metadata($doc_obj->get_top_section(),$meta_name, $meta_value);
     315       
     316        }           
     317           
    307318    }
    308319
    309320    ##clean up
    310321    $self->{'marc_mapping'} = undef;
     322    $self->{'current_tag'} = "";
    311323    }
    312324}
     
    324336    my ($expat) = @_;
    325337
     338
    326339    ## store the text of a marc code, for exapmle 520a=>A poem about....
    327     if ($self->{'current_element'} eq "subfield" and $self->{'current_attr'} ne "" and $_ ne "" ){
     340    if ($self->{'current_element'} eq "subfield" and $self->{'current_code'} ne "" and $_ ne "" ){
    328341    ##stored it in the marc_mapping
    329     $self->{'marc_mapping'}->{$self->{'current_attr'}} = $_;
    330     ## clean up
    331     $self->{'current_attr'} = "";
     342        push(@{$self->{'marc_mapping'}->{$self->{'current_tag'}}},$self->{'current_code'});
     343    push(@{$self->{'marc_mapping'}->{$self->{'current_tag'}}},$_);
     344    $self->{'current_code'} = "";
    332345    }
    333346   
Note: See TracChangeset for help on using the changeset viewer.