Changeset 12889
- Timestamp:
- 2006-09-28T11:14:32+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/classify/GenericList.pm
r11541 r12889 37 37 38 38 use strict; 39 no strict 'refs'; # Allow filehandles to be variables and viceversa40 39 41 40 … … 50 49 'type' => "metadata", 51 50 'reqd' => "yes" }, 51 52 52 # The interesting options 53 53 { 'name' => "always_bookshelf_last_level", … … 89 89 90 90 my $self = (defined $hashArgOptLists) ? new BasClas($classifierslist, $inputargs, $hashArgOptLists) : new BasClas($classifierslist, $inputargs); 91 $self->{'OID list'} = [];91 $self->{'OIDs'} = []; 92 92 93 93 if ($self->{'info_only'}) { … … 108 108 die "Error: No metadata fields specified for GenericList.\n"; 109 109 } 110 my @meta list= split(/\//, $metadata);111 $self->{'meta list'} = \@metalist;110 my @metadata_groups = split(/\//, $metadata); 111 $self->{'metadata_groups'} = \@metadata_groups; 112 112 113 113 # The classifier button name 114 114 if (!$buttonname) { 115 115 # Default: the first metadata element specified 116 my $firstmetagroupfirstelem = (split(/\;/, $meta list[0]))[0];116 my $firstmetagroupfirstelem = (split(/\;/, $metadata_groups[0]))[0]; 117 117 $buttonname = $self->generate_title_from_metadata($firstmetagroupfirstelem); 118 118 } … … 120 120 121 121 # Whether to group single items into a bookshelf (must be true for all metadata fields except the last) 122 foreach my $meta group (@metalist) {123 $self->{$meta group . ".always_bookshelf"} = "t";122 foreach my $metadata_group (@metadata_groups) { 123 $self->{$metadata_group . ".always_bookshelf"} = "t"; 124 124 } 125 125 if (!$self->{'always_bookshelf_last_level'}) { 126 126 # Default: leave leafnodes ungrouped (equivalent to AZCompactList -mingroup 2) 127 my $last metagroup = $metalist[$#metalist];128 $self->{$last metagroup . ".always_bookshelf"} = "f";127 my $last_metadata_group = $metadata_groups[$#metadata_groups]; 128 $self->{$last_metadata_group . ".always_bookshelf"} = "f"; 129 129 } 130 130 131 131 # Whether to use an hlist or a vlist for each level in the hierarchy 132 foreach my $meta group (@metalist) {133 $self->{$meta group . ".use_hlist"} = "f";134 } 135 foreach my $meta group (split(/\,/, $use_hlist_for)) {136 $self->{$meta group . ".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"; 137 137 } 138 138 … … 147 147 if (!$partition_size_within_level) { 148 148 # Default: 20 149 foreach my $meta group (@metalist) {150 $self->{$meta group . ".partition_size_within_level"} = 20;149 foreach my $metadata_group (@metadata_groups) { 150 $self->{$metadata_group . ".partition_size_within_level"} = 20; 151 151 } 152 152 } … … 155 155 156 156 # Assign values based on the partition_size_within_level parameter 157 foreach my $meta group (@metalist) {157 foreach my $metadata_group (@metadata_groups) { 158 158 my $partition_size_within_levelelem = shift(@partition_size_within_levellist); 159 159 if (defined($partition_size_within_levelelem)) { 160 $self->{$meta group . ".partition_size_within_level"} = $partition_size_within_levelelem;160 $self->{$metadata_group . ".partition_size_within_level"} = $partition_size_within_levelelem; 161 161 } 162 162 else { 163 $self->{$meta group . ".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"}; 164 164 } 165 165 } … … 167 167 168 168 # The metadata elements to use to sort the leaf nodes 169 my @sort_leaf_nodes_usingmeta list= ( "Title" );169 my @sort_leaf_nodes_usingmetadata_groups = ( "Title" ); 170 170 if ($sort_leaf_nodes_using) { 171 @sort_leaf_nodes_usingmeta list= split(/\|/, $sort_leaf_nodes_using);172 } 173 $self->{'sort_leaf_nodes_usingmeta list'} = \@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; 174 174 175 175 return bless $self, $class; … … 210 210 my $section = shift(@_); 211 211 212 my @meta list = @{$self->{'metalist'}};212 my @metadata_groups = @{$self->{'metadata_groups'}}; 213 213 214 214 # Only classify the document if it has a value for one of the metadata elements in the first group 215 foreach my $firstmetagroupelem (split(/\;/, $meta list[0])) {215 foreach my $firstmetagroupelem (split(/\;/, $metadata_groups[0])) { 216 216 my $firstmetagroupelemvalue = $doc_obj->get_metadata_element($section, $firstmetagroupelem); 217 217 if (defined($firstmetagroupelemvalue) && $firstmetagroupelemvalue ne "") { 218 push(@{$self->{'OID list'}}, $doc_OID);218 push(@{$self->{'OIDs'}}, $doc_OID); 219 219 220 220 # Create a hash for the metadata values of each metadata element we're interested in 221 221 my %metagroupsdone = (); 222 foreach my $meta group (@metalist, @{$self->{'sort_leaf_nodes_usingmetalist'}}) {222 foreach my $metadata_group (@metadata_groups, @{$self->{'sort_leaf_nodes_usingmetadata_groups'}}) { 223 223 # Take care not to do a metadata group more than once 224 unless ($metagroupsdone{$meta group}) {225 foreach my $metaelem (split(/\;/, $meta group)) {224 unless ($metagroupsdone{$metadata_group}) { 225 foreach my $metaelem (split(/\;/, $metadata_group)) { 226 226 my @metavalues = @{$doc_obj->get_metadata($section, $metaelem)}; 227 227 foreach my $metavalue (@metavalues) { … … 229 229 $metavalue =~ s/^\s*//; 230 230 $metavalue =~ s/\s*$//; 231 push(@{$self->{$meta group . ".list"}->{$doc_OID}}, $metavalue);231 push(@{$self->{$metadata_group . ".list"}->{$doc_OID}}, $metavalue); 232 232 } 233 233 last if (@metavalues > 0); 234 234 } 235 235 236 $metagroupsdone{$meta group} = 1;236 $metagroupsdone{$metadata_group} = 1; 237 237 } 238 238 } … … 249 249 250 250 # The metadata elements to classify by 251 my @meta list = @{$self->{'metalist'}};252 my $first metagroup = $metalist[0];251 my @metadata_groups = @{$self->{'metadata_groups'}}; 252 my $first_metadata_group = $metadata_groups[0]; 253 253 254 254 # The OID values of the documents to include in the classification 255 my @OID list = @{$self->{'OIDlist'}};255 my @OIDs = @{$self->{'OIDs'}}; 256 256 257 257 # The root node of the classification hierarchy 258 my $childtype = (($self->{$first metagroup . ".use_hlist"} eq "t") ? "HList" : "VList");258 my $childtype = (($self->{$first_metadata_group . ".use_hlist"} eq "t") ? "HList" : "VList"); 259 259 my %classifyinfo = ( 'thistype' => "Invisible", 260 260 'childtype' => $childtype, … … 263 263 264 264 # Recursively create the classification hierarchy, one level for each metadata element 265 &add_az_list($self, \@meta list, \@OIDlist, \%classifyinfo);265 &add_az_list($self, \@metadata_groups, \@OIDs, \%classifyinfo); 266 266 return \%classifyinfo; 267 267 } … … 271 271 { 272 272 my $self = shift(@_); 273 my @meta list= @{shift(@_)};274 my @OID list= @{shift(@_)};273 my @metadata_groups = @{shift(@_)}; 274 my @OIDs = @{shift(@_)}; 275 275 my $classifyinfo = shift(@_); 276 276 # print STDERR "\nAdding AZ list for " . $classifyinfo->{'Title'} . "\n"; 277 277 278 my $meta group = $metalist[0];279 # print STDERR "Processing metadata group: " . $meta group . "\n";280 # print STDERR "Number of OID values: " . @OID list. "\n";281 282 my %OIDtometavaluehash = %{$self->{$meta group . ".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"}}; 283 283 284 284 # Create a mapping from metadata value to OID 285 285 my %metavaluetoOIDhash = (); 286 foreach my $OID (@OID list) {286 foreach my $OID (@OIDs) { 287 287 if ($OIDtometavaluehash{$OID}) { 288 288 my @metavalues = @{$OIDtometavaluehash{$OID}}; … … 307 307 # Is this the start of a new partition? 308 308 if ($metavaluepartition ne $lastpartition) { 309 &add_hlist_partition($self, \@meta list, $classifyinfo, $lastpartition, \%metavaluetoOIDsubhash);309 &add_hlist_partition($self, \@metadata_groups, $classifyinfo, $lastpartition, \%metavaluetoOIDsubhash); 310 310 %metavaluetoOIDsubhash = (); 311 311 $lastpartition = $metavaluepartition; … … 316 316 317 317 # Don't forget to add the last partition 318 &add_hlist_partition($self, \@meta list, $classifyinfo, $lastpartition, \%metavaluetoOIDsubhash);318 &add_hlist_partition($self, \@metadata_groups, $classifyinfo, $lastpartition, \%metavaluetoOIDsubhash); 319 319 320 320 # The partitions are stored in an HList … … 324 324 else { 325 325 # Generate hlists of a certain size 326 my $partition_size_within_level = $self->{$meta group . ".partition_size_within_level"};326 my $partition_size_within_level = $self->{$metadata_group . ".partition_size_within_level"}; 327 327 if ($partition_type_within_level =~ /^constant_size$/i && scalar(keys %metavaluetoOIDhash) > $partition_size_within_level) { 328 328 my @sortedmetavalues = sort(keys %metavaluetoOIDhash); … … 349 349 } 350 350 351 &add_hlist_partition($self, \@meta list, $classifyinfo, $partitionname, \%metavaluetoOIDsubhash);351 &add_hlist_partition($self, \@metadata_groups, $classifyinfo, $partitionname, \%metavaluetoOIDsubhash); 352 352 %metavaluetoOIDsubhash = (); 353 353 $lastpartitionend = $partitionend; … … 361 361 # Otherwise just add all the values to a VList 362 362 else { 363 &add_vlist($self, \@meta list, $classifyinfo, \%metavaluetoOIDhash);363 &add_vlist($self, \@metadata_groups, $classifyinfo, \%metavaluetoOIDhash); 364 364 } 365 365 } … … 418 418 { 419 419 my $self = shift(@_); 420 my @meta list= @{shift(@_)};420 my @metadata_groups = @{shift(@_)}; 421 421 my $classifyinfo = shift(@_); 422 422 my $partitionname = shift(@_); … … 429 429 430 430 # Add the children to the hlist partition 431 &add_vlist($self, \@meta list, \%subclassifyinfo, \%metavaluetoOIDhash);431 &add_vlist($self, \@metadata_groups, \%subclassifyinfo, \%metavaluetoOIDhash); 432 432 push(@{$classifyinfo->{'contains'}}, \%subclassifyinfo); 433 433 } … … 437 437 { 438 438 my $self = shift(@_); 439 my @meta list= @{shift(@_)};439 my @metadata_groups = @{shift(@_)}; 440 440 my $classifyinfo = shift(@_); 441 441 my %metavaluetoOIDhash = %{shift(@_)}; 442 442 443 my $meta group = shift(@metalist);443 my $metadata_group = shift(@metadata_groups); 444 444 445 445 # Create an entry in the vlist for each value 446 446 foreach my $metavalue (sort(keys %metavaluetoOIDhash)) { 447 my @OID list= @{$metavaluetoOIDhash{$metavalue}};447 my @OIDs = @{$metavaluetoOIDhash{$metavalue}}; 448 448 449 449 # If there is only one item and 'always_bookshelf' is false, add the item to the list 450 if (@OID list == 1 && $self->{$metagroup . ".always_bookshelf"} eq "f") {451 push(@{$classifyinfo->{'contains'}}, { 'OID' => $OID list[0] });450 if (@OIDs == 1 && $self->{$metadata_group . ".always_bookshelf"} eq "f") { 451 push(@{$classifyinfo->{'contains'}}, { 'OID' => $OIDs[0] }); 452 452 } 453 453 … … 459 459 460 460 # If there are metadata elements remaining, recursively apply the process 461 if (@meta list> 0) {462 my $next metagroup = $metalist[0];463 my $childtype = (($self->{$next metagroup . ".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"); 464 464 $subclassifyinfo{'childtype'} = $childtype; 465 &add_az_list($self, \@meta list, \@OIDlist, \%subclassifyinfo);465 &add_az_list($self, \@metadata_groups, \@OIDs, \%subclassifyinfo); 466 466 } 467 467 # Otherwise just add the documents as children of this list 468 468 else { 469 469 # Sort the leaf nodes by the metadata elements specified with -sort_leaf_nodes_using 470 my @sort_leaf_nodes_usingmeta list = @{$self->{'sort_leaf_nodes_usingmetalist'}};471 foreach my $sort_leaf_nodes_usingmetaelem (reverse @sort_leaf_nodes_usingmeta list) {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) { 472 472 my %OIDtometavaluehash = %{$self->{$sort_leaf_nodes_usingmetaelem . ".list"}}; 473 473 # Force a stable sort (Perl 5.6's sort isn't stable) 474 474 # !! The [0] bits aren't ideal (multiple metadata values) !! 475 @OID list = @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 ]; 476 476 } 477 477 478 foreach my $OID (@OID list) {478 foreach my $OID (@OIDs) { 479 479 push(@{$subclassifyinfo{'contains'}}, { 'OID' => $OID }); 480 480 }
Note:
See TracChangeset
for help on using the changeset viewer.