Changeset 29094

Show
Ignore:
Timestamp:
09.06.2014 14:40:40 (6 years ago)
Author:
kjdon
Message:

added -metadata_selection_mode firstvalue|firstvalidmetadata|allvalues option, to decide which values to classify on if using a list of metadata, eg dc.Date,Date. Replicates -firstvalueonly and -allvalues of AZCompactList, but can specify for each level in hierarchy.

Location:
main/trunk/greenstone2/perllib
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/classify/List.pm

    r27098 r29094  
    4444} 
    4545 
     46my $meta_select_type_list = 
     47    [  
     48      { 'name' => "firstvalue", 
     49    'desc' => "{List.metadata_selection.firstvalue}"}, 
     50      { 'name' => "firstvalidmetadata", 
     51    'desc' => "{List.metadata_selection.firstvalidmetadata}"}, 
     52      { 'name' => "allvalues", 
     53    'desc' => "{List.metadata_selection.allvalues}"} ]; 
     54my $valid_meta_select_types = { 'firstvalue' => 1, 
     55                'firstvalidmetadata' => 1, 
     56                'allvalues' => 1 }; 
    4657my $partition_type_list =  
    4758    [ { 'name' => "per_letter", 
     
    7485    'type' => "metadata", 
    7586    'reqd' => "yes" }, 
    76  
     87      { 'name' => "metadata_selection_mode", 
     88    'desc' => "{List.metadata_selection_mode}", 
     89    'type' => "enumstring", # Must be enumstring because multiple values can be specified (separated by '/') 
     90    'list' => $meta_select_type_list, 
     91    'deft' => "firstvalidmetadata" }, 
    7792      # The interesting options 
    7893      { 'name' => "bookshelf_type",  
     
    162177    } 
    163178 
     179    # meta selection mode for each level 
     180    if (!$self->{'metadata_selection_mode'}) { 
     181    foreach my $metadata_group (@metadata_groups) { 
     182        $self->{$metadata_group . ".metadata_selection_mode"} = "firstvalidmetadata"; 
     183    } 
     184    } else { 
     185    my @metadata_selection_mode_list = split(/\//, $self->{'metadata_selection_mode'}); 
     186    foreach my $metadata_group (@metadata_groups) { 
     187        my $meta_select_mode = shift(@metadata_selection_mode_list); 
     188        if (defined($meta_select_mode) && defined $valid_meta_select_types->{$meta_select_mode}) { 
     189        $self->{$metadata_group . ".metadata_selection_mode"} = $meta_select_mode; 
     190        } else { 
     191        $self->{$metadata_group . ".metadata_selection_mode"} = "firstvalidmetadata";    
     192        } 
     193    } 
     194    }    
    164195    # Whether to group items into a bookshelf, (must be 'always' for all metadata fields except the last) 
    165196    foreach my $metadata_group (@metadata_groups) { 
     
    276307    } 
    277308    $self->{'sort_leaf_nodes_using_metadata_groups'} = \@sort_leaf_nodes_using_metadata_groups; 
    278  
     309    foreach my $sort_group (@sort_leaf_nodes_using_metadata_groups) { 
     310    # set metadata_select_type, if not already set - might be already set if the same group was used in -metadata 
     311    if (!defined $self->{$sort_group . ".metadata_selection_mode"}) { 
     312        $self->{$sort_group . ".metadata_selection_mode"} = "firstvalue"; 
     313    } 
     314    } 
    279315    # Create an instance of the Unicode::Collate object if better Unicode sorting is desired 
    280316    if ($self->{'sort_using_unicode_collation'}) { 
     
    413449 
    414450            # Add the metadata value into the list for this combination of metadata group and section 
    415             push(@{$self->{$metadata_group . ".list"}->{$section_OID}}, $lc_metadata_value); 
     451            # text that we have some non-whitespace chars 
     452            if ($lc_metadata_value =~ /\S/) { 
     453             
     454            push(@{$self->{$metadata_group . ".list"}->{$section_OID}}, $lc_metadata_value); 
     455             
     456             
    416457            # add the actual value into the stored values so we can remember the case 
    417458            if (!$self->{'standardize_capitalization'}) { 
     
    421462                $self->{$metadata_group . ".actualvalues"}->{$lc_metadata_value}->{$metadata_value} = 1; 
    422463            } 
    423             }        
    424         } 
    425         last if (@metadata_values > 0); 
    426         } 
     464            } 
     465            last if ($self->{$metadata_group . ".metadata_selection_mode"} eq "firstvalue"); 
     466            } 
     467        } # foreach metadatavalue 
     468        last if ((@metadata_values > 0) &&  $self->{$metadata_group . ".metadata_selection_mode"} =~ /^(firstvalue|firstvalidmetadata)$/ ); 
     469        } # foreach metadata element 
    427470 
    428471        $metadata_groups_done{$metadata_group} = 1; 
  • main/trunk/greenstone2/perllib/strings.properties

    r29013 r29094  
    649649List.level_partition.approximate_size:Create a partition per letter, then group or split the letters to get approximately the same sized partitions.  
    650650 
    651 List.metadata:Metadata fields used for classification. Use '/' to separate the levels in the hierarchy and ';' to separate metadata fields within each level. 
    652  
     651List.metadata:Metadata fields used for classification. Use '/' to separate the levels in the hierarchy and ';' or ',' to separate metadata fields within each level. 
     652 
     653List.metadata_selection_mode:Determines how many metadata values the document is classified by, within each level. Use '/' to separate the levels. 
     654List.metadata_selection.firstvalue:Only classify by a single metadata value, the first one encountered. 
     655List.metadata_selection.firstvalidmetadata:Classify by all the metadata values of the first element in the list that has values. 
     656List.metadata_selection.allvalues:Classify by all metadata values found, from all elements in the list. 
    653657List.partition_name_length:The length of the partition name; defaults to a variable length from 1 up to 3 characters, depending on how many are required to distinguish the partition start from its end. This option only applies when partition_type_within_level is set to 'constant_size'. 
    654658