Ignore:
Timestamp:
1999-09-29T08:40:14+12:00 (25 years ago)
Author:
rjmcnab
Message:

added code to calculate the number of leaf nodes in a
classification hierarchy and put the result in numleafnodes

File:
1 edited

Legend:

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

    r537 r637  
    111111 
    112112    # don't want empty classifications
    113     if ($allclassifications || &clean_contents ($classifyinfo)) {
     113    if ($allclassifications || &check_contents ($classifyinfo) > 0) {
    114114   
    115115    $OID = $classifyinfo->{'classifyOID'} if defined ($classifyinfo->{'classifyOID'});
     
    120120    $outputtext .= "<classifytype>$classifyinfo->{'classifytype'}\n" if defined $classifyinfo->{'classifytype'};
    121121    $outputtext .= "<Title>$classifyinfo->{'Title'}\n" if defined $classifyinfo->{'Title'};
     122    $outputtext .= "<numleafdocs>$classifyinfo->{'numleafdocs'}\n" if defined $classifyinfo->{'numleafdocs'};
     123    print "numleafdocs = $classifyinfo->{'numleafdocs'}\n" if defined $classifyinfo->{'numleafdocs'};
    122124   
    123125    $outputtext .= "<contains>";
     
    153155}
    154156
    155 sub clean_contents {
     157sub check_contents {
    156158    my ($classifyinfo) = @_;
    157     my $has_content = 0;
     159    my $num_leaf_docs = 0;
     160    my $sub_num_leaf_docs = 0;
     161
     162    return $classifyinfo->{'numleafdocs'} if (defined $classifyinfo->{'numleafdocs'});
    158163
    159164    foreach $content (@{$classifyinfo->{'contains'}}) {
    160165    if (defined $content->{'OID'}) {
    161166        # found a book
    162         $has_content = 1;
    163     } elsif (&clean_contents ($content)) {
     167        $num_leaf_docs ++;
     168    } elsif (($sub_num_leaf_docs = &check_contents ($content)) > 0) {
    164169        # there's a book somewhere below
    165         $has_content = 1;
     170        $num_leaf_docs += $sub_num_leaf_docs;
    166171    } else {
    167172        # section contains no books so we want to remove
     
    170175    }
    171176    }
    172     return $has_content;
     177
     178    $classifyinfo->{'numleafdocs'} = $num_leaf_docs;
     179    return $num_leaf_docs;
    173180}
    174181
Note: See TracChangeset for help on using the changeset viewer.