Changeset 32501


Ignore:
Timestamp:
2018-10-08T23:57:39+13:00 (3 years ago)
Author:
Georgiy Litvinov
Message:

Workaround to set assign metadata via csv metadata plugin. "Section" column could be used in csv file to specify section for metadata to assign

Location:
main/trunk/greenstone2/perllib/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/BaseImporter.pm

    r31493 r32501  
    924924    }
    925925    elsif (ref ($metadata->{$field}) eq "ARRAY") {
    926         map {
    927         $doc_obj->add_utf8_metadata ($cursection, $field, $_);
    928         } @{$metadata->{$field}};
     926        if ($field =~ /(.+?)\/\/\/Section\/([\d.]*)/m){
     927            my $field_new_name = $1;
     928            my $specified_section = $2;
     929            map {
     930                $doc_obj->add_utf8_metadata ($specified_section, $field_new_name, $_);
     931            } @{$metadata->{$field}};
     932        } else {
     933            map {
     934                $doc_obj->add_utf8_metadata ($cursection, $field, $_);
     935            } @{$metadata->{$field}};
     936        }
     937       
    929938    } else {
    930         $doc_obj->add_utf8_metadata ($cursection, $field, $metadata->{$field});
     939        if ($field =~ /(.+?)\/\/\/Section\/([\d.]*)/m){
     940            my $field_new_name = $1;
     941            my $specified_section = $2;
     942            $doc_obj->add_utf8_metadata ($specified_section, $field_new_name, $metadata->{$field});
     943        } else {
     944            $doc_obj->add_utf8_metadata ($cursection, $field, $metadata->{$field});
     945        }
    931946    }
    932947    }
  • main/trunk/greenstone2/perllib/plugins/MetadataCSVPlugin.pm

    r31492 r32501  
    212212    delete $csv_line_metadata{"Filename"};
    213213
     214    my $csv_line_section_array = $csv_line_metadata{"Section"};
     215    my $section_suffix = "";
     216    if (defined $csv_line_section_array) {
     217        my $section_value = shift(@$csv_line_section_array);
     218        if ($section_value =~ /[\d.]+/m){
     219            my $section_suffix = "///Section/" . $section_value;
     220            foreach my $metaname (keys %csv_line_metadata) {
     221                my $new_name = $metaname . $section_suffix;
     222                $csv_line_metadata{$new_name} = delete $csv_line_metadata{$metaname};
     223            }
     224        } else{
     225            unshift(@$csv_line_section_array, $section_value);
     226        }
     227    }
     228
    214229
    215230    # Associate the metadata now
Note: See TracChangeset for help on using the changeset viewer.