- Timestamp:
- 1999-07-14T14:52:39+12:00 (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/classify/Hierarchy.pm
r342 r384 1 1 # classifier plugin for generating hierarchical classifications 2 3 # options for this classifier are: 4 # file.txt - classification file 5 # Metaname - metadata field to test against file.txt 6 # sort=Meta - this option is optional (genious;-). by default this 7 # classifier will sort documents within each section 8 # alphabetically by Title. sort=nosort prevents sorting 9 # (i.e. documents will end up in build order), sort=Meta 10 # will sort each field alphabetically by Meta (Meta may 11 # also be 'Filename' to sort by the original filename). 12 2 13 3 14 package Hierarchy; … … 5 16 use util; 6 17 use cfgread; 18 use sorttools; 7 19 8 20 sub new { … … 13 25 "Usage: Hierarchy subjectfile metadata\n"; 14 26 } 15 27 my $sortname = "Title"; 28 if ((scalar @options > 2) && $options[2] =~ /^sort=(.*)$/i) { 29 $sortname = $1; 30 $sortname = undef if $sortname =~ /^nosort$/; 31 } 32 16 33 my $subjectfile = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"etc", $options[0]); 17 34 if (!-e $subjectfile) { … … 28 45 'locatorlist'=>{}, # second field in subject file 29 46 'subjectfile' => $subjectfile, 30 'metaname' => $options[1] 47 'metaname' => $options[1], 48 'sortname' => $sortname 31 49 }, $class; 32 50 } … … 62 80 if ((defined $self->{'descriptorlist'}->{$metaelement}) && 63 81 (defined $self->{'locatorlist'}->{$self->{'descriptorlist'}->{$metaelement}})) { 64 push (@{$self->{'locatorlist'}->{$self->{'descriptorlist'}->{$metaelement}}->{'contents'}}, $doc_OID); 82 83 my $sortmeta = ""; 84 if (defined $self->{'sortname'}) { 85 if ($self->{'sortname'} =~ /^filename$/i) { 86 $sortmeta = $doc_obj->get_source_filename(); 87 } else { 88 $sortmeta = $doc_obj->get_metadata_element($doc_obj->get_top_section(), 89 $self->{'sortname'}); 90 if ($self-{'sortname'} eq "Creator") { 91 &sorttools::format_string_name_english ($sortmeta); 92 } else { 93 &sorttools::format_string_english ($sortmeta); 94 } 95 } 96 $sortmeta = "" unless defined $sortmeta; 97 } 98 99 push (@{$self->{'locatorlist'}->{$self->{'descriptorlist'}->{$metaelement}}->{'contents'}}, 100 [$doc_OID, $sortmeta]); 65 101 } 66 102 } … … 76 112 foreach $OID (keys (%$list)) { 77 113 my $tempinfo = $self->get_OID_entry ($OID, $classifyinfo, $list->{$OID}->{'title'}, "Hierarchy"); 78 foreach $subOID (@{$list->{$OID}->{'contents'}}) { 79 push (@{$tempinfo->{'contains'}}, {'OID'=>$subOID}); 114 115 if (defined $self->{'sortname'}) { 116 foreach $subOID (sort {$a->[1] cmp $b->[1];} @{$list->{$OID}->{'contents'}}) { 117 push (@{$tempinfo->{'contains'}}, {'OID'=>$subOID->[0]}); 118 } 119 } else { 120 foreach $subOID (@{$list->{$OID}->{'contents'}}) { 121 push (@{$tempinfo->{'contains'}}, {'OID'=>$subOID->[0]}); 122 } 80 123 } 81 124 } 82 125 83 126 return $classifyinfo; 84 127 } … … 124 167 } 125 168 169 170 126 171 1;
Note:
See TracChangeset
for help on using the changeset viewer.