Changeset 12896


Ignore:
Timestamp:
2006-09-28T13:40:40+12:00 (18 years ago)
Author:
mdewsnip
Message:

More tidying up of the code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/classify/GenericList.pm

    r12895 r12896  
    174174
    175175
     176# Called for each document in the collection
    176177sub classify
    177178{
     
    179180    my $doc_obj = shift(@_);
    180181
    181     my $doc_OID = $doc_obj->get_OID();
    182 
     182    # If "-classify_sections" is set, classify every section of the document
    183183    if ($self->{'classify_sections'}) {
    184184    my $section = $doc_obj->get_next_section($doc_obj->get_top_section());
    185185    while (defined $section) {
    186         $self->classify_section($doc_obj, $doc_OID . ".$section", $section);
     186        $self->classify_section($doc_obj, $doc_obj->get_OID() . ".$section", $section);
    187187        $section = $doc_obj->get_next_section($section);
    188188    }
    189189    }
     190    # Otherwise just classify the top document section
    190191    else {
    191     $self->classify_section($doc_obj, $doc_OID, $doc_obj->get_top_section());
     192    $self->classify_section($doc_obj, $doc_obj->get_OID(), $doc_obj->get_top_section());
    192193    }
    193194}
     
    198199    my $self = shift(@_);
    199200    my $doc_obj = shift(@_);
    200     my $doc_OID = shift(@_);
     201    my $section_OID = shift(@_);
    201202    my $section = shift(@_);
    202203
    203204    my @metadata_groups = @{$self->{'metadata_groups'}};
    204205
    205     # Only classify the document if it has a value for one of the metadata elements in the first group
    206     foreach my $firstmetagroupelem (split(/\;/, $metadata_groups[0])) {
    207     my $firstmetagroupelemvalue = $doc_obj->get_metadata_element($section, $firstmetagroupelem);
    208     if (defined($firstmetagroupelemvalue) && $firstmetagroupelemvalue ne "") {
    209         push(@{$self->{'OIDs'}}, $doc_OID);
    210 
    211         # Create a hash for the metadata values of each metadata element we're interested in
    212         my %metagroupsdone = ();
    213         foreach my $metadata_group (@metadata_groups, @{$self->{'sort_leaf_nodes_using_metadata_groups'}}) {
    214         # Take care not to do a metadata group more than once
    215         unless ($metagroupsdone{$metadata_group}) {
    216             foreach my $metaelem (split(/\;/, $metadata_group)) {
    217             my @metavalues = @{$doc_obj->get_metadata($section, $metaelem)};
    218             foreach my $metavalue (@metavalues) {
    219                 # Strip leading and trailing whitespace
    220                 $metavalue =~ s/^\s*//;
    221                 $metavalue =~ s/\s*$//;
    222                 push(@{$self->{$metadata_group . ".list"}->{$doc_OID}}, $metavalue);
    223             }
    224             last if (@metavalues > 0);
    225             }
    226 
    227             $metagroupsdone{$metadata_group} = 1;
     206    # Only classify the section if it has a value for one of the metadata elements in the first group
     207    my $classify_section = 0;
     208    my $first_metadata_group = $metadata_groups[0];
     209    foreach my $first_metadata_group_element (split(/\;/, $first_metadata_group)) {
     210    my $first_metadata_group_element_value = $doc_obj->get_metadata_element($section, $first_metadata_group_element);
     211    if (defined($first_metadata_group_element_value) && $first_metadata_group_element_value ne "") {
     212        # This section must be included in the classifier
     213        $classify_section = 1;
     214        last;
     215    }
     216    }
     217
     218    # We're not classifying this section because it doesn't have the required metadata
     219    return if (!$classify_section);
     220
     221    # Otherwise, include this section in the classifier
     222    push(@{$self->{'OIDs'}}, $section_OID);
     223
     224    # Create a hash for the metadata values of each metadata element we're interested in
     225    my %metadata_groups_done = ();
     226    foreach my $metadata_group (@metadata_groups, @{$self->{'sort_leaf_nodes_using_metadata_groups'}}) {
     227    # Take care not to do a metadata group more than once
     228    unless ($metadata_groups_done{$metadata_group}) {
     229        foreach my $metadata_element (split(/\;/, $metadata_group)) {
     230        my @metadata_values = @{$doc_obj->get_metadata($section, $metadata_element)};
     231        foreach my $metadata_value (@metadata_values) {
     232            # Strip leading and trailing whitespace
     233            $metadata_value =~ s/^\s*//;
     234            $metadata_value =~ s/\s*$//;
     235            push(@{$self->{$metadata_group . ".list"}->{$section_OID}}, $metadata_value);
    228236        }
    229         }
    230 
    231         last;
     237        last if (@metadata_values > 0);
     238        }
     239
     240        $metadata_groups_done{$metadata_group} = 1;
    232241    }
    233242    }
     
    239248    my $self = shift(@_);
    240249
    241     # The metadata elements to classify by
     250    # The metadata groups to classify by
    242251    my @metadata_groups = @{$self->{'metadata_groups'}};
    243252    my $first_metadata_group = $metadata_groups[0];
    244253
    245     # The OID values of the documents to include in the classification
     254    # The OID values of the documents to include in the classifier
    246255    my @OIDs = @{$self->{'OIDs'}};
    247256
    248     # The root node of the classification hierarchy
     257    # Create the root node of the classification hierarchy
    249258    my %classifier_node = ( 'thistype' => "Invisible",
    250259                'childtype' => $self->{$first_metadata_group . ".list_type"},
Note: See TracChangeset for help on using the changeset viewer.