Changeset 36910


Ignore:
Timestamp:
2022-11-22T11:23:20+13:00 (17 months ago)
Author:
kjdon
Message:

Added some code for tk labels - options to take a single field and store its values as individual metadata fields with true value. eg wmtb.TKLabel=tk.Clan,tk.Attribution =>tk.Clan=true, tk.Attribution=true. Implemented for tk labels, but then not needed as this is handled by xslt instead. Leaving this here in case useful in the future

File:
1 edited

Legend:

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

    r34999 r36910  
    126126    'list' => $file_rename_method_list,
    127127    'reqd' => "no"
    128     }
    129      
     128     }
     129
     130      # These options take a metadata field, and store its values as individual
     131      #fields with true value.
     132      #eg wmtb.TKLabel=tk.Clan,tk.Attribution =>tk.Clan=true, tk.Attribution=true.
     133      #Implemented for tk lables, but then not needed as this is handled by
     134      # xslt instead. Leaving this here in case useful in the future     
     135#      { 'name' => "store_metadata_values_as_fields_for",
     136#            'desc' => "For these (comma-separated list of) fields, take all values and store them as metadata fields in their own write, value=true ",
     137#            'type' => "metadata",
     138#            'reqd' => "no" },
     139#      { 'name' => "namespace_for_new_fields",
     140#            'desc' => "add the specified namespace to the new fields (comma separated list, corresponding to the fields above",
     141#            'type'=> "string",
     142#            'reqd' => "no",
     143#            'deft' => ""},
     144#      { 'name' => "include_section_level",
     145#            'desc' => "do we look for this metadata at subsection level too?",
     146#            'type' => "string",
     147#            'deft' => "false"}
    130148      ];
    131149
     
    575593#    }
    576594}
     595
    577596
    578597# this should be called by all plugins to set the oid of the doc obj, rather
     
    654673    $self->auto_extract_metadata($doc_obj);
    655674
     675    # to use tk label options commented out at top
     676    #$self->convert_special_metadata($doc_obj);
     677   
    656678    # if we haven't found any Title so far, assign one
    657679    # this was shifted to here from inside read()
     
    689711    my $self = shift(@_);
    690712    my ($doc_obj) = @_;
     713}
     714
     715# used with the tk label options commented out at the start
     716sub convert_special_metadata {
     717    my $self = shift(@_);
     718    my ($doc_obj) = @_;
     719    print STDERR "in convert special meta\n";
     720    return unless defined $self->{'store_metadata_values_as_fields_for'};
     721    print STDERR "we have fields to convert\n";
     722   
     723    my @existing_meta_fields = split(',', $self->{'store_metadata_values_as_fields_for'});
     724    my @new_ns = split(',', $self->{'namespace_for_new_fields'});
     725    my $include_section_level = $self->{'include_section_level'};
     726   
     727    foreach my $old_meta (@existing_meta_fields) {
     728        my $ns = shift(@new_ns);
     729        my $ns_prefix = "";
     730        if (defined $ns && $ns =~/\S/) {
     731            $ns_prefix = "$ns.";
     732        }
     733   
     734   
     735        my $section = $doc_obj->get_top_section();
     736        while (defined $section) {
     737            my @section_meta = @{$doc_obj->get_metadata($section, $old_meta)};
     738            foreach my $meta (@section_meta) {
     739                foreach my $submeta (split /,/, $meta) {
     740                    # add meta, ns+submeta, value = true
     741                    # remove whitepace
     742                    $submeta =~ s/\s+//g;
     743                    $doc_obj->add_utf8_metadata($section, "$ns_prefix$submeta", "true");
     744                }
     745            }
     746       
     747            last if (!$include_section_level);
     748            $section = $doc_obj->get_next_section($section);
     749        }
     750    }
    691751}
    692752
Note: See TracChangeset for help on using the changeset viewer.