Changeset 24012

Show
Ignore:
Timestamp:
11.05.2011 16:47:52 (8 years ago)
Author:
ak19
Message:

Bugfix to the way List deals with subclassification levels specified by the forward slash token. The bug was that when sub classifications were not specified for a document, it would never appear (even in a classification level higher up, which was specified for it). Now such docs appears under the lowest classification level specified for them. E.g. dc.Creator/dc.Date. If Date is not specified for doc x even if Creator is, then x used to not appear under dc.Creator either. Now it appears under dc.Creator.

Files:
1 modified

Legend:

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

    r23302 r24012  
    142142    die "Error: No metadata fields specified for List.\n"; 
    143143    } 
    144     my @metadata_groups = split(/\//, $self->{'metadata'}); 
     144 
     145    my @metadata_groups = split(/[\/]/, $self->{'metadata'}); 
    145146    $self->{'metadata_groups'} = \@metadata_groups; 
    146147 
     
    148149    if (!$self->{'buttonname'}) { 
    149150    my $first_metadata_group = $metadata_groups[0]; 
    150     my $first_metadata_element = (split(/\;|,/, $first_metadata_group))[0]; 
     151    my $first_metadata_element = (split(/[\;|,\/]/, $first_metadata_group))[0];  
    151152    $self->{'buttonname'} = $self->generate_title_from_metadata($first_metadata_element); 
    152153    } 
     
    451452    } 
    452453    } 
    453      #print STDERR "Number of distinct values: " . scalar(keys %metadata_value_to_OIDs_hash) . "\n"; 
     454    #print STDERR "Number of distinct values: " . scalar(keys %metadata_value_to_OIDs_hash) . "\n"; 
    454455 
    455456    # Partition the values (if necessary) 
     
    495496    my @metadata_values_in_bucket = (); 
    496497    my $num_items_in_bucket = 0; 
    497     foreach my $metadata_value (@sortedmetadata_values) {        
     498    foreach my $metadata_value (@sortedmetadata_values) { 
    498499        my $metadata_valuepartition = substr($metadata_value, 0, 1); 
    499500        if ($metadata_valuepartition ne $last_partition) { 
     
    801802    } 
    802803    # Otherwise create a sublist (bookshelf) for the metadata value 
    803     else {           
     804    else { 
    804805        my %child_classifier_node = ( 'Title' => $self->convert_unicode_string_to_utf8_string($metadata_value), 
    805806                      'childtype' => "VList", 
     
    807808                      'contains' => [] ); 
    808809 
     810        #@OIDs = $self->sort_leaf_items(\@OIDs); 
    809811        # If there are metadata elements remaining, recursively apply the process 
    810812        if (@metadata_groups > 0) { 
    811         my $next_metadata_group = $metadata_groups[0]; 
     813        my $next_metadata_group = $metadata_groups[0];       
    812814        $child_classifier_node{'childtype'} = $self->{$next_metadata_group . ".list_type"}; 
    813         $self->add_level(\@metadata_groups, \@OIDs, \%child_classifier_node); 
     815 
     816        # separate metadata into those that below in the next/sub-metadata_group 
     817        # and those that below at the current level's metadata_group 
     818 
     819        my $OID_to_metadata_values_hash_ref = $self->{$next_metadata_group . ".list"}; 
     820        my @current_level_OIDs = (); 
     821        my @next_level_OIDs = (); 
     822        foreach my $OID (@OIDs) 
     823        { 
     824            if ($OID_to_metadata_values_hash_ref->{$OID}) { 
     825            push(@next_level_OIDs, $OID); 
     826            } else { 
     827            push(@current_level_OIDs, $OID); 
     828            } 
     829        } 
     830        # recursively process those docs belonging to the sub-metadata_group 
     831        $self->add_level(\@metadata_groups, \@next_level_OIDs, \%child_classifier_node); 
     832 
     833        # For those docs that don't belong in the sub/next_metadata_group, but which belong 
     834        # at this level, just add the documents as children of this list at the current level 
     835        @current_level_OIDs = $self->sort_leaf_items(\@current_level_OIDs); 
     836        foreach my $current_level_OID (@current_level_OIDs) { 
     837            my $offset = $self->metadata_offset($metadata_group, $current_level_OID, $metadata_value); 
     838            push(@{$child_classifier_node{'contains'}}, { 'OID' => $current_level_OID , 'offset' => $offset }); 
     839        }        
    814840        } 
    815841        # Otherwise just add the documents as children of this list