Changeset 12889


Ignore:
Timestamp:
2006-09-28T11:14:32+12:00 (18 years ago)
Author:
mdewsnip
Message:

Tidied up lots of variable names.

File:
1 edited

Legend:

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

    r11541 r12889  
    3737
    3838use strict;
    39 no strict 'refs';  # Allow filehandles to be variables and viceversa
    4039
    4140
     
    5049    'type' => "metadata",
    5150    'reqd' => "yes" },
     51
    5252      # The interesting options
    5353      { 'name' => "always_bookshelf_last_level",
     
    8989
    9090    my $self = (defined $hashArgOptLists) ? new BasClas($classifierslist, $inputargs, $hashArgOptLists) : new BasClas($classifierslist, $inputargs);
    91     $self->{'OIDlist'} = [];
     91    $self->{'OIDs'} = [];
    9292
    9393    if ($self->{'info_only'}) {
     
    108108    die "Error: No metadata fields specified for GenericList.\n";
    109109    }
    110     my @metalist = split(/\//, $metadata);
    111     $self->{'metalist'} = \@metalist;
     110    my @metadata_groups = split(/\//, $metadata);
     111    $self->{'metadata_groups'} = \@metadata_groups;
    112112
    113113    # The classifier button name
    114114    if (!$buttonname) {
    115115    # Default: the first metadata element specified
    116     my $firstmetagroupfirstelem = (split(/\;/, $metalist[0]))[0];
     116    my $firstmetagroupfirstelem = (split(/\;/, $metadata_groups[0]))[0];
    117117    $buttonname = $self->generate_title_from_metadata($firstmetagroupfirstelem);
    118118    }
     
    120120
    121121    # Whether to group single items into a bookshelf (must be true for all metadata fields except the last)
    122     foreach my $metagroup (@metalist) {
    123     $self->{$metagroup . ".always_bookshelf"} = "t";
     122    foreach my $metadata_group (@metadata_groups) {
     123    $self->{$metadata_group . ".always_bookshelf"} = "t";
    124124    }
    125125    if (!$self->{'always_bookshelf_last_level'}) {
    126126    # Default: leave leafnodes ungrouped (equivalent to AZCompactList -mingroup 2)
    127     my $lastmetagroup = $metalist[$#metalist];
    128     $self->{$lastmetagroup . ".always_bookshelf"} = "f";
     127    my $last_metadata_group = $metadata_groups[$#metadata_groups];
     128    $self->{$last_metadata_group . ".always_bookshelf"} = "f";
    129129    }
    130130
    131131    # Whether to use an hlist or a vlist for each level in the hierarchy
    132     foreach my $metagroup (@metalist) {
    133     $self->{$metagroup . ".use_hlist"} = "f";
    134     }
    135     foreach my $metagroup (split(/\,/, $use_hlist_for)) {
    136     $self->{$metagroup . ".use_hlist"} = "t";
     132    foreach my $metadata_group (@metadata_groups) {
     133    $self->{$metadata_group . ".use_hlist"} = "f";
     134    }
     135    foreach my $metadata_group (split(/\,/, $use_hlist_for)) {
     136    $self->{$metadata_group . ".use_hlist"} = "t";
    137137    }
    138138
     
    147147    if (!$partition_size_within_level) {
    148148    # Default: 20
    149     foreach my $metagroup (@metalist) {
    150         $self->{$metagroup . ".partition_size_within_level"} = 20;
     149    foreach my $metadata_group (@metadata_groups) {
     150        $self->{$metadata_group . ".partition_size_within_level"} = 20;
    151151    }
    152152    }
     
    155155
    156156    # Assign values based on the partition_size_within_level parameter
    157     foreach my $metagroup (@metalist) {
     157    foreach my $metadata_group (@metadata_groups) {
    158158        my $partition_size_within_levelelem = shift(@partition_size_within_levellist);
    159159        if (defined($partition_size_within_levelelem)) {
    160         $self->{$metagroup . ".partition_size_within_level"} = $partition_size_within_levelelem;
     160        $self->{$metadata_group . ".partition_size_within_level"} = $partition_size_within_levelelem;
    161161        }
    162162        else {
    163         $self->{$metagroup . ".partition_size_within_level"} = $self->{$metalist[0] . ".partition_size_within_level"};
     163        $self->{$metadata_group . ".partition_size_within_level"} = $self->{$metadata_groups[0] . ".partition_size_within_level"};
    164164        }
    165165    }
     
    167167
    168168    # The metadata elements to use to sort the leaf nodes
    169     my @sort_leaf_nodes_usingmetalist = ( "Title" );
     169    my @sort_leaf_nodes_usingmetadata_groups = ( "Title" );
    170170    if ($sort_leaf_nodes_using) {
    171     @sort_leaf_nodes_usingmetalist = split(/\|/, $sort_leaf_nodes_using);
    172     }
    173     $self->{'sort_leaf_nodes_usingmetalist'} = \@sort_leaf_nodes_usingmetalist;
     171    @sort_leaf_nodes_usingmetadata_groups = split(/\|/, $sort_leaf_nodes_using);
     172    }
     173    $self->{'sort_leaf_nodes_usingmetadata_groups'} = \@sort_leaf_nodes_usingmetadata_groups;
    174174
    175175    return bless $self, $class;
     
    210210    my $section = shift(@_);
    211211
    212     my @metalist = @{$self->{'metalist'}};
     212    my @metadata_groups = @{$self->{'metadata_groups'}};
    213213
    214214    # Only classify the document if it has a value for one of the metadata elements in the first group
    215     foreach my $firstmetagroupelem (split(/\;/, $metalist[0])) {
     215    foreach my $firstmetagroupelem (split(/\;/, $metadata_groups[0])) {
    216216    my $firstmetagroupelemvalue = $doc_obj->get_metadata_element($section, $firstmetagroupelem);
    217217    if (defined($firstmetagroupelemvalue) && $firstmetagroupelemvalue ne "") {
    218         push(@{$self->{'OIDlist'}}, $doc_OID);
     218        push(@{$self->{'OIDs'}}, $doc_OID);
    219219
    220220        # Create a hash for the metadata values of each metadata element we're interested in
    221221        my %metagroupsdone = ();
    222         foreach my $metagroup (@metalist, @{$self->{'sort_leaf_nodes_usingmetalist'}}) {
     222        foreach my $metadata_group (@metadata_groups, @{$self->{'sort_leaf_nodes_usingmetadata_groups'}}) {
    223223        # Take care not to do a metadata group more than once
    224         unless ($metagroupsdone{$metagroup}) {
    225             foreach my $metaelem (split(/\;/, $metagroup)) {
     224        unless ($metagroupsdone{$metadata_group}) {
     225            foreach my $metaelem (split(/\;/, $metadata_group)) {
    226226            my @metavalues = @{$doc_obj->get_metadata($section, $metaelem)};
    227227            foreach my $metavalue (@metavalues) {
     
    229229                $metavalue =~ s/^\s*//;
    230230                $metavalue =~ s/\s*$//;
    231                 push(@{$self->{$metagroup . ".list"}->{$doc_OID}}, $metavalue);
     231                push(@{$self->{$metadata_group . ".list"}->{$doc_OID}}, $metavalue);
    232232            }
    233233            last if (@metavalues > 0);
    234234            }
    235235
    236             $metagroupsdone{$metagroup} = 1;
     236            $metagroupsdone{$metadata_group} = 1;
    237237        }
    238238        }
     
    249249
    250250    # The metadata elements to classify by
    251     my @metalist = @{$self->{'metalist'}};
    252     my $firstmetagroup = $metalist[0];
     251    my @metadata_groups = @{$self->{'metadata_groups'}};
     252    my $first_metadata_group = $metadata_groups[0];
    253253
    254254    # The OID values of the documents to include in the classification
    255     my @OIDlist = @{$self->{'OIDlist'}};
     255    my @OIDs = @{$self->{'OIDs'}};
    256256
    257257    # The root node of the classification hierarchy
    258     my $childtype = (($self->{$firstmetagroup . ".use_hlist"} eq "t") ? "HList" : "VList");
     258    my $childtype = (($self->{$first_metadata_group . ".use_hlist"} eq "t") ? "HList" : "VList");
    259259    my %classifyinfo = ( 'thistype' => "Invisible",
    260260             'childtype' => $childtype,
     
    263263
    264264    # Recursively create the classification hierarchy, one level for each metadata element
    265     &add_az_list($self, \@metalist, \@OIDlist, \%classifyinfo);
     265    &add_az_list($self, \@metadata_groups, \@OIDs, \%classifyinfo);
    266266    return \%classifyinfo;
    267267}
     
    271271{
    272272    my $self = shift(@_);
    273     my @metalist = @{shift(@_)};
    274     my @OIDlist = @{shift(@_)};
     273    my @metadata_groups = @{shift(@_)};
     274    my @OIDs = @{shift(@_)};
    275275    my $classifyinfo = shift(@_);
    276276    # print STDERR "\nAdding AZ list for " . $classifyinfo->{'Title'} . "\n";
    277277
    278     my $metagroup = $metalist[0];
    279     # print STDERR "Processing metadata group: " . $metagroup . "\n";
    280     # print STDERR "Number of OID values: " . @OIDlist . "\n";
    281 
    282     my %OIDtometavaluehash = %{$self->{$metagroup . ".list"}};
     278    my $metadata_group = $metadata_groups[0];
     279    # print STDERR "Processing metadata group: " . $metadata_group . "\n";
     280    # print STDERR "Number of OID values: " . @OIDs . "\n";
     281
     282    my %OIDtometavaluehash = %{$self->{$metadata_group . ".list"}};
    283283
    284284    # Create a mapping from metadata value to OID
    285285    my %metavaluetoOIDhash = ();
    286     foreach my $OID (@OIDlist) {
     286    foreach my $OID (@OIDs) {
    287287    if ($OIDtometavaluehash{$OID}) {
    288288        my @metavalues = @{$OIDtometavaluehash{$OID}};
     
    307307        # Is this the start of a new partition?
    308308        if ($metavaluepartition ne $lastpartition) {
    309         &add_hlist_partition($self, \@metalist, $classifyinfo, $lastpartition, \%metavaluetoOIDsubhash);
     309        &add_hlist_partition($self, \@metadata_groups, $classifyinfo, $lastpartition, \%metavaluetoOIDsubhash);
    310310        %metavaluetoOIDsubhash = ();
    311311        $lastpartition = $metavaluepartition;
     
    316316
    317317    # Don't forget to add the last partition
    318     &add_hlist_partition($self, \@metalist, $classifyinfo, $lastpartition, \%metavaluetoOIDsubhash);
     318    &add_hlist_partition($self, \@metadata_groups, $classifyinfo, $lastpartition, \%metavaluetoOIDsubhash);
    319319
    320320    # The partitions are stored in an HList
     
    324324    else {
    325325    # Generate hlists of a certain size
    326     my $partition_size_within_level = $self->{$metagroup . ".partition_size_within_level"};
     326    my $partition_size_within_level = $self->{$metadata_group . ".partition_size_within_level"};
    327327    if ($partition_type_within_level =~ /^constant_size$/i && scalar(keys %metavaluetoOIDhash) > $partition_size_within_level) {
    328328        my @sortedmetavalues = sort(keys %metavaluetoOIDhash);
     
    349349            }
    350350
    351             &add_hlist_partition($self, \@metalist, $classifyinfo, $partitionname, \%metavaluetoOIDsubhash);
     351            &add_hlist_partition($self, \@metadata_groups, $classifyinfo, $partitionname, \%metavaluetoOIDsubhash);
    352352            %metavaluetoOIDsubhash = ();
    353353            $lastpartitionend = $partitionend;
     
    361361    # Otherwise just add all the values to a VList
    362362    else {
    363         &add_vlist($self, \@metalist, $classifyinfo, \%metavaluetoOIDhash);
     363        &add_vlist($self, \@metadata_groups, $classifyinfo, \%metavaluetoOIDhash);
    364364    }
    365365    }
     
    418418{
    419419    my $self = shift(@_);
    420     my @metalist = @{shift(@_)};
     420    my @metadata_groups = @{shift(@_)};
    421421    my $classifyinfo = shift(@_);
    422422    my $partitionname = shift(@_);
     
    429429
    430430    # Add the children to the hlist partition
    431     &add_vlist($self, \@metalist, \%subclassifyinfo, \%metavaluetoOIDhash);
     431    &add_vlist($self, \@metadata_groups, \%subclassifyinfo, \%metavaluetoOIDhash);
    432432    push(@{$classifyinfo->{'contains'}}, \%subclassifyinfo);
    433433}
     
    437437{
    438438    my $self = shift(@_);
    439     my @metalist = @{shift(@_)};
     439    my @metadata_groups = @{shift(@_)};
    440440    my $classifyinfo = shift(@_);
    441441    my %metavaluetoOIDhash = %{shift(@_)};
    442442
    443     my $metagroup = shift(@metalist);
     443    my $metadata_group = shift(@metadata_groups);
    444444
    445445    # Create an entry in the vlist for each value
    446446    foreach my $metavalue (sort(keys %metavaluetoOIDhash)) {
    447     my @OIDlist = @{$metavaluetoOIDhash{$metavalue}};
     447    my @OIDs = @{$metavaluetoOIDhash{$metavalue}};
    448448
    449449    # If there is only one item and 'always_bookshelf' is false, add the item to the list
    450     if (@OIDlist == 1 && $self->{$metagroup . ".always_bookshelf"} eq "f") {
    451         push(@{$classifyinfo->{'contains'}}, { 'OID' => $OIDlist[0] });
     450    if (@OIDs == 1 && $self->{$metadata_group . ".always_bookshelf"} eq "f") {
     451        push(@{$classifyinfo->{'contains'}}, { 'OID' => $OIDs[0] });
    452452    }
    453453
     
    459459
    460460        # If there are metadata elements remaining, recursively apply the process
    461         if (@metalist > 0) {
    462         my $nextmetagroup = $metalist[0];
    463         my $childtype = (($self->{$nextmetagroup . ".use_hlist"} eq "t") ? "HList" : "VList");
     461        if (@metadata_groups > 0) {
     462        my $next_metadata_group = $metadata_groups[0];
     463        my $childtype = (($self->{$next_metadata_group . ".use_hlist"} eq "t") ? "HList" : "VList");
    464464        $subclassifyinfo{'childtype'} = $childtype;
    465         &add_az_list($self, \@metalist, \@OIDlist, \%subclassifyinfo);
     465        &add_az_list($self, \@metadata_groups, \@OIDs, \%subclassifyinfo);
    466466        }
    467467        # Otherwise just add the documents as children of this list
    468468        else {
    469469        # Sort the leaf nodes by the metadata elements specified with -sort_leaf_nodes_using
    470         my @sort_leaf_nodes_usingmetalist = @{$self->{'sort_leaf_nodes_usingmetalist'}};
    471         foreach my $sort_leaf_nodes_usingmetaelem (reverse @sort_leaf_nodes_usingmetalist) {
     470        my @sort_leaf_nodes_usingmetadata_groups = @{$self->{'sort_leaf_nodes_usingmetadata_groups'}};
     471        foreach my $sort_leaf_nodes_usingmetaelem (reverse @sort_leaf_nodes_usingmetadata_groups) {
    472472            my %OIDtometavaluehash = %{$self->{$sort_leaf_nodes_usingmetaelem . ".list"}};
    473473            # Force a stable sort (Perl 5.6's sort isn't stable)
    474474            # !! The [0] bits aren't ideal (multiple metadata values) !!
    475             @OIDlist = @OIDlist[ sort { $OIDtometavaluehash{$OIDlist[$a]}[0] cmp $OIDtometavaluehash{$OIDlist[$b]}[0] || $a <=> $b; } 0..$#OIDlist ];
     475            @OIDs = @OIDs[ sort { $OIDtometavaluehash{$OIDs[$a]}[0] cmp $OIDtometavaluehash{$OIDs[$b]}[0] || $a <=> $b; } 0..$#OIDs ];
    476476        }
    477477
    478         foreach my $OID (@OIDlist) {
     478        foreach my $OID (@OIDs) {
    479479            push(@{$subclassifyinfo{'contains'}}, { 'OID' => $OID });
    480480        }
Note: See TracChangeset for help on using the changeset viewer.