Ignore:
Timestamp:
2000-07-13T10:21:53+12:00 (24 years ago)
Author:
sjboddie
Message:

merged changes to trunk into New_Config_Format branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/New_Config_Format-branch/gsdl/perllib/classify/AZSectionList.pm

    r741 r1279  
    3030# instead of just top level metadata
    3131
    32 # options are:
    33 # metadata=Metadata
    34 
    3532# the only change is to the classify() subroutine which
    3633# must now iterate through each section, adding each
     
    3936package AZSectionList;
    4037
     38use AZList;
    4139use sorttools;
    4240
    43 sub new {
    44     my ($class, @options) = @_;
    45 
    46     my ($metaname);
    47     foreach $option (@options) {
    48     if ($option =~ /^metadata=(.*)$/i) {
    49         $metaname = $1;
    50     }
    51     }
    52 
    53     if (!defined $metaname) {
    54     die "AZSectionList used with no metadata name to classify by\n";
    55     }
    56    
    57     return bless {
    58     'list'=>{},
    59     'metaname' => $metaname
    60     }, $class;
    61 }
    62 
    63 sub init {
    64     my $self = shift (@_);
    65 
    66     $self->{'list'} = {};
     41sub BEGIN {
     42    @ISA = ('AZList');
    6743}
    6844
     
    10379}
    10480
    105 sub get_classify_info {
    106     my $self = shift (@_);
    107 
    108     my @classlist = sort {$self->{'list'}->{$a} cmp $self->{'list'}->{$b};}
    109     keys %{$self->{'list'}};
    110 
    111     return $self->splitlist (\@classlist);
    112 }
    113 
    114 sub get_entry {
    115     my $self = shift (@_);
    116     my ($title, $childtype, $thistype) = @_;
    117    
    118     # organise into classification structure
    119     my %classifyinfo = ('childtype'=>$childtype,
    120             'Title'=>$title,
    121             'contains'=>[]);
    122     $classifyinfo{'thistype'} = $thistype
    123     if defined $thistype && $thistype =~ /\w/;
    124 
    125     return \%classifyinfo;
    126 }
    127 
    128 # splitlist takes an ordered list of classifications (@$classlistref) and splits it
    129 # up into alphabetical sub-sections.
    130 sub splitlist {
    131     my $self = shift (@_);
    132     my ($classlistref) = @_;
    133     my $classhash = {};
    134 
    135     # top level
    136     my $childtype = "HList";
    137     if (scalar (@$classlistref) <= 39) {$childtype = "VList";}
    138     my $classifyinfo = $self->get_entry ($self->{'metaname'}, $childtype, "Invisible");
    139 
    140     # don't need to do any splitting if there are less than 39 (max + min -1) classifications
    141     if ((scalar @$classlistref) <= 39) {
    142     foreach $subOID (@$classlistref) {
    143         push (@{$classifyinfo->{'contains'}}, {'OID'=>$subOID});
    144     }
    145     return $classifyinfo;
    146     }
    147    
    148     # first split up the list into separate A-Z and 0-9 classifications
    149     foreach $classification (@$classlistref) {
    150     my $title = $self->{'list'}->{$classification};
    151     $title =~ s/^(.).*$/$1/;
    152     $title =~ tr/[a-z]/[A-Z]/;
    153     if ($title =~ /^[0-9]$/) {$title = '0-9';}
    154     elsif ($title !~ /^[A-Z]$/) {
    155         print STDERR "AZSectionList: WARNING $classification has badly " .
    156         "formatted title ($title)\n";
    157     }
    158     $classhash->{$title} = [] unless defined $classhash->{$title};
    159     push (@{$classhash->{$title}}, $classification);
    160     }
    161     $classhash = $self->compactlist ($classhash);
    162 
    163     my @tmparr = ();
    164     foreach $subsection (sort keys (%$classhash)) {
    165     push (@tmparr, $subsection);
    166     }
    167    
    168     # if there's a 0-9 section it will have been sorted to the beginning
    169     # but we want it at the end
    170     if ($tmparr[0] eq '0-9') {
    171     shift @tmparr;
    172     push (@tmparr, '0-9');
    173     }
    174 
    175     foreach $subclass (@tmparr) {
    176     my $tempclassify = $self->get_entry($subclass, "VList");
    177     foreach $subsubOID (@{$classhash->{$subclass}}) {
    178         push (@{$tempclassify->{'contains'}}, {'OID'=>$subsubOID});
    179     }
    180     push (@{$classifyinfo->{'contains'}}, $tempclassify);
    181     }
    182 
    183     return $classifyinfo;
    184 }
    185 
    186 sub compactlist {
    187     my $self = shift (@_);
    188     my ($classhashref) = @_;
    189     my $compactedhash = {};
    190     my @currentOIDs = ();
    191     my $currentfirstletter = "";
    192     my $currentlastletter = "";
    193     my $lastkey = "";
    194 
    195     # minimum and maximum documents to be displayed per page.
    196     # the actual maximum will be max + (min-1).
    197     # the smallest sub-section is a single letter at present
    198     # so in this case there may be many times max documents
    199     # displayed on a page.
    200     my $min = 10;
    201     my $max = 30;
    202 
    203     foreach $subsection (sort keys %$classhashref) {
    204     if ($subsection eq '0-9') {
    205         @{$compactedhash->{$subsection}} = @{$classhashref->{$subsection}};
    206         next;
    207     }
    208     $currentfirstletter = $subsection if $currentfirstletter eq "";
    209     if ((scalar (@currentOIDs) < $min) ||
    210         ((scalar (@currentOIDs) + scalar (@{$classhashref->{$subsection}})) <= $max)) {
    211         push (@currentOIDs, @{$classhashref->{$subsection}});
    212         $currentlastletter = $subsection;
    213     } else {
    214 
    215         if ($currentfirstletter eq $currentlastletter) {
    216         @{$compactedhash->{$currentfirstletter}} = @currentOIDs;
    217         $lastkey = $currentfirstletter;
    218         } else {
    219         @{$compactedhash->{"$currentfirstletter-$currentlastletter"}} = @currentOIDs;
    220         $lastkey = "$currentfirstletter-$currentlastletter";
    221         }
    222         if (scalar (@{$classhashref->{$subsection}}) >= $max) {
    223         $compactedhash->{$subsection} = $classhashref->{$subsection};
    224         @currentOIDs = ();
    225         $currentfirstletter = "";
    226         $lastkey = $subsection;
    227         } else {
    228         @currentOIDs = @{$classhashref->{$subsection}};
    229         $currentfirstletter = $subsection;
    230         $currentlastletter = $subsection;
    231         }
    232     }
    233     }
    234 
    235     # add final OIDs to last sub-classification if there aren't many otherwise
    236     # add final sub-classification
    237     if (scalar (@currentOIDs) < $min) {
    238     my ($newkey) = $lastkey =~ /^(.)/;
    239     @currentOIDs = (@{$compactedhash->{$lastkey}}, @currentOIDs);
    240     delete $compactedhash->{$lastkey};
    241     @{$compactedhash->{"$newkey-$currentlastletter"}} = @currentOIDs;   
    242     } else {
    243     if ($currentfirstletter eq $currentlastletter) {
    244         @{$compactedhash->{$currentfirstletter}} = @currentOIDs;
    245     } else {
    246         @{$compactedhash->{"$currentfirstletter-$currentlastletter"}} = @currentOIDs;
    247     }
    248     }
    249 
    250     return $compactedhash;
    251 }
    25281
    253821;
Note: See TracChangeset for help on using the changeset viewer.