Changeset 6970
- Timestamp:
- 2004-03-08T16:27:43+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/classify/SectionList.pm
r6408 r6970 44 44 'inherits' => "yes" }; 45 45 46 # sub print_usage {47 # print STDERR "48 # usage: classify SectionList [options]49 # options:50 51 # -metadata X Metadata field used for classification,52 # list will be sorted by this element.53 54 # -buttonname X (optional) Title field for this classification.55 # if not included title field will be Metaname.56 57 # -sort X (optional) Sort documents in list by this metadata field.58 # By default it will sort by Metaname, or (if this is not59 # set) in build (random) order.60 61 # Same as List classifier but includes all sections of document62 # (excluding top level) rather than just top level document.63 # ";64 # }65 46 66 47 sub new { … … 72 53 push( @{$option_list}, $options ); 73 54 55 #if ($self->{'info_only'}) { 56 # created from classinfo.pl - don't need to parse the arguments 57 # return bless $self, $class; 58 #} 74 59 return bless $self, $class; 75 60 } … … 77 62 sub classify { 78 63 my $self = shift (@_); 79 my ($doc_obj , @options) = @_;64 my ($doc_obj) = @_; 80 65 81 my $thissection = undef; 82 83 my $option; 84 foreach $option (@options) 85 { 86 if ($option =~ m/^section=(\d+)$/i) 87 { 88 $thissection = $1; 89 } 66 # are we sorting the list?? 67 my $nosort = 0; 68 if (defined $self->{'sortname'} && $self->{'sortname'} eq "nosort") { 69 $nosort = 1; 90 70 } 91 71 72 # do we want to put -section as an option for the classifier??? 73 #my $thissection = undef; 74 75 #my $option; 76 #foreach $option (@options) 77 #{ 78 # if ($option =~ m/^section=(\d+)$/i) 79 # { 80 # $thissection = $1; 81 # } 82 # } 83 92 84 my $sortmeta = ""; 93 if ( defined $self->{'sortname'}) {85 if (!$nosort && defined $self->{'sortname'}) { 94 86 if ($self->{'sortname'} =~ /^filename$/i) { 95 87 $sortmeta = $doc_obj->get_source_filename(); 96 88 } else { 97 $sortmeta = $doc_obj->get_metadata_element($doc_obj->get_top_section(), 98 $self->{'sortname'}); 99 if ($self->{'sortname'} eq "Creator") { 100 &sorttools::format_string_name_english (\$sortmeta); 101 } else { 102 &sorttools::format_string_english (\$sortmeta); 89 $sortmeta = $doc_obj->get_metadata_element($doc_obj->get_top_section(), $self->{'sortname'}); 90 if (defined $sortmeta) { 91 $sortmeta = $self->format_metadata_for_sorting($self->{'sortname'}, $sortmeta, $doc_obj); 103 92 } 104 93 } … … 106 95 } 107 96 108 if (!defined $thissection) 109 { 110 $thissection = $doc_obj->get_next_section ($doc_obj->get_top_section()); 111 while (defined $thissection) { 112 $self->classify_section($thissection, $doc_obj, $sortmeta); 113 $thissection = $doc_obj->get_next_section ($thissection); 114 } 97 # if (defined $thissection) { 98 # $self->classify_section($thissection, $doc_obj, $sortmeta); 99 # } else 100 # { 101 $thissection = $doc_obj->get_next_section ($doc_obj->get_top_section()); 102 while (defined $thissection) { 103 $self->classify_section($thissection, $doc_obj, $nosort, $sortmeta); 104 $thissection = $doc_obj->get_next_section ($thissection); 115 105 } 116 else 117 { 118 $self->classify_section($thissection, $doc_obj, $sortmeta); 119 } 106 #} 120 107 } 121 108 122 109 sub classify_section { 123 110 my $self = shift (@_); 124 my ($section, $doc_obj, $ sortmeta) = @_;111 my ($section, $doc_obj, $nosort, $sortmeta) = @_; 125 112 126 113 my $doc_OID = $doc_obj->get_OID(); 114 $nosort = 0 unless defined $nosort; 127 115 $sortmeta = "" unless defined $sortmeta; 128 116 117 my $metavalue; 118 my $metaname; 119 if (defined $self->{'meta_list'}) { 120 # find the first available metadata 121 foreach $m (@{$self->{'meta_list'}}) { 122 $metavalue = $doc_obj->get_metadata_element($section, $m); 123 $metaname = $m; 124 last if defined $metavalue; 125 } 126 #if we haven't found a metavalue here, then the section shouldn't be included 127 return unless defined $metavalue; 128 } 129 130 # we know the section should be included, add it now if we are not sorting 131 if ($nosort) { 132 push (@{$self->{'list'}}, "$doc_OID.$section"); 133 return; 134 } 135 # check that it hasn't been added already 136 if (defined $self->{'list'}->{"$doc_OID.$section"}) { 137 my $outhandle = $self->{'outhandle'}; 138 print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n"; 139 } 140 129 141 if (defined $self->{'sortname'}) { 130 if (defined $self->{'metaname'}) { 131 132 my $metavalue = $doc_obj->get_metadata_element ($section, $self->{'metaname'}); 133 if (defined $metavalue) { 134 if (defined $self->{'list'}->{"$doc_OID.$section"}) { 135 my $outhandle = $self->{'outhandle'}; 136 print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n"; 137 } 138 $self->{'list'}->{"$doc_OID.$section"} = $sortmeta; 139 } 140 } else { 141 if (defined $self->{'list'}->{"$doc_OID.$section"}) { 142 my $outhandle = $self->{'outhandle'}; 143 print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n"; 144 } 145 $self->{'list'}->{"$doc_OID.$section"} = $sortmeta; 146 } 147 142 # sorting on alternative metadata 143 $self->{'list'}->{"$doc_OID.$section"} = $sortmeta; 148 144 } else { 149 if (defined $self->{'metaname'}) { 150 151 my $metavalue = $doc_obj->get_metadata_element ($section, $self->{'metaname'}); 152 if (defined $metavalue) { 153 push (@{$self->{'list'}}, "$doc_OID.$section"); 154 } 155 } else { 156 push (@{$self->{'list'}}, "$doc_OID.$section"); 157 } 145 # sortingon the classification metadata 146 # do the same formatting on the meta value as for sort meta 147 $metavalue = $self->format_metadata_for_sorting($metaname, $metavalue, $doc_obj); 148 $self->{'list'}->{"$doc_OID.$section"} = $metavalue; 158 149 } 159 150 } 160 161 151 1;
Note:
See TracChangeset
for help on using the changeset viewer.