Changeset 13196
- Timestamp:
- 2006-10-30T16:14:32+13:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/plugins/XMLMARCPlug.pm
r13153 r13196 66 66 $self->{'encoding'} = ""; 67 67 $self->{'marc_mapping'} = {}; 68 $self->{'current_attr'} = ""; 68 $self->{'current_code'} = ""; 69 $self->{'current_tag'} = ""; 69 70 $self->{'current_element'} = ""; 70 71 $self->{'metadata_mapping'} = undef; 72 $self->{'num_processed'} = 0; 71 73 72 74 return bless $self, $class; … … 227 229 $self->set_OID($doc_obj, $doc_obj->get_OID() , $self->{'record_count'}); 228 230 231 my $outhandle = $self->{'outhandle'}; 232 print $outhandle "Record $self->{'record_count'} - XMLMARCPlug: processing $self->{'file'}\n" if $self->{'verbosity'} > 1; 233 229 234 $self->{'record_count'}++; 230 235 $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 235 241 if ($element eq "datafield") { 236 242 if (defined $attr_map{'tag'} and $attr_map{'tag'} ne ""){ 237 $self->{'current_ attr'} = $attr_map{tag};243 $self->{'current_tag'} = $attr_map{tag}; 238 244 } 239 245 } 240 246 247 241 248 ## append the subcode to the marc code for example 520a or 520b 242 249 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'}; 245 252 } 246 253 } … … 276 283 ##map { print STDERR $_."=>".$metadata_mapping->{$_}."\n"; } keys %$metadata_mapping; 277 284 278 foreach my $ code (keys %$marc_mapping){285 foreach my $marc_field (keys %$metadata_mapping){ 279 286 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." "; 300 305 } 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++; 304 307 } 305 308 } 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 307 318 } 308 319 309 320 ##clean up 310 321 $self->{'marc_mapping'} = undef; 322 $self->{'current_tag'} = ""; 311 323 } 312 324 } … … 324 336 my ($expat) = @_; 325 337 338 326 339 ## 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 "" ){ 328 341 ##stored it in the marc_mapping 329 $self->{'marc_mapping'}->{$self->{'current_attr'}} = $_;330 ## clean up331 $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'} = ""; 332 345 } 333 346
Note:
See TracChangeset
for help on using the changeset viewer.