source: main/tags/2.52/gsdl/perllib/classify/AZCompactSectionList.pm

Last change on this file was 6968, checked in by kjdon, 20 years ago

all classifiers now use BasClas.buttonname for their buttonname option description.
removed the old print_usage methods and old usage notes.
added in a test for $self->{'info_only'} in new(): if this is set, don't try and parse the arguments cos we are only running classinfo.pl.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1###########################################################################
2#
3# AZCompactSectionList.pm --
4#
5# Experimental AZCompactList with fixes to handle section-level metadata
6#
7###########################################################################
8
9package AZCompactSectionList;
10
11use AZCompactList;
12
13sub BEGIN {
14 @ISA = ('AZCompactList');
15}
16
17my $options =
18{ 'name' => "AZCompactSectionList",
19 'desc' => "{AZCompactSectionList.desc}",
20 'abstract' => "no",
21 'inherits' => "yes",
22 'args' => $arguments };
23
24sub new {
25 my $class = shift (@_);
26 my $self = new AZCompactList($class, @_);
27
28 # 14-05-02 To allow for proper inheritance of arguments - John Thompson
29 my $option_list = $self->{'option_list'};
30 push( @{$option_list}, $options );
31
32 #if ($self->{'info_only'}) {
33 # created from classinfo.pl - don't need to parse the arguments
34 #return bless $self, $class;
35 #}
36
37 return bless $self, $class;
38}
39
40#
41# override reinit() & reclassify() to demonstrate possible bug fixes
42# (search for SECTIONFIX? to see lines changed from AZCompactList.pm)
43#
44sub reinit
45{
46 my ($self,$classlist_ref) = @_;
47
48 my %mtfreq = ();
49 my @single_classlist = ();
50 my @multiple_classlist = ();
51
52 # find out how often each metavalue occurs
53 map
54 {
55 my $mv;
56 foreach $mv (@{$self->{'listmetavalue'}->{$_}} )
57 {
58 $mtfreq{$mv}++;
59 }
60 } @$classlist_ref;
61
62 # use this information to split the list: single metavalue/repeated value
63 map
64 {
65 my $i = 1;
66 my $metavalue;
67 foreach $metavalue (@{$self->{'listmetavalue'}->{$_}})
68 {
69 if ($mtfreq{$metavalue} >= $self->{'mingroup'})
70 {
71 push(@multiple_classlist,[$_,$i,$metavalue]);
72 }
73 else
74 {
75 push(@single_classlist,[$_,$metavalue]);
76 $metavalue =~ tr/[A-Z]/[a-z]/;
77 $self->{'reclassifylist'}->{"Metavalue_$i.$_"} = $metavalue;
78 }
79 $i++;
80 }
81 } @$classlist_ref;
82
83
84 # Setup sub-classifiers for multiple list
85
86 $self->{'classifiers'} = {};
87
88 my $pm;
89 foreach $pm ("List", "SectionList")
90 {
91 my $listname
92 = &util::filename_cat($ENV{'GSDLHOME'},"perllib/classify/$pm.pm");
93 if (-e $listname) { require $listname; }
94 else
95 {
96 my $outhandle = $self->{'outhandle'};
97 print $outhandle "AZCompactList ERROR - couldn't find classifier \"$listname\"\n";
98 die "\n";
99 }
100 }
101
102 # Create classifiers objects for each entry >= mingroup
103 my $metavalue;
104 foreach $metavalue (keys %mtfreq)
105 {
106 if ($mtfreq{$metavalue} >= $self->{'mingroup'})
107 {
108 my $listclassobj;
109 my $doclevel = $self->{'doclevel'};
110 my $metaname = $self->{'metaname'};
111 my @metaname_list = split('/',$metaname);
112 $metaname = shift(@metaname_list);
113 if (@metaname_list==0)
114 {
115 my @args;
116 push @args, ("-metadata", "$metaname");
117# buttonname is also used for the node's title
118 push @args, ("-buttonname", "$metavalue");
119 push @args, ("-sort", "Date");
120
121 if ($doclevel =~ m/^top(level)?/i)
122 {
123 eval ("\$listclassobj = new List(\@args)"); warn $@ if $@;
124 }
125 else
126 {
127 # SECTIONFIX?
128 #eval ("\$listclassobj = new SectionList($args)");
129 eval ("\$listclassobj = new SectionList(\@args)");
130 }
131 }
132 else
133 {
134 $metaname = join('/',@metaname_list);
135
136 my @args;
137 push @args, ("-metadata", "$metaname");
138# buttonname is also used for the node's title
139 push @args, ("-buttonname", "$metavalue");
140 push @args, ("-doclevel", "$doclevel");
141 push @args, "-recopt";
142
143 # SECTIONFIX?
144 #eval ("\$listclassobj = new AZCompactList($args)");
145 eval ("\$listclassobj = new AZCompactList(\@args)");
146 }
147 if ($@) {
148 my $outhandle = $self->{'outhandle'};
149 print $outhandle "$@";
150 die "\n";
151 }
152
153 $listclassobj->init();
154
155 if (defined $metavalue && $metavalue =~ /\w/)
156 {
157 my $formatted_node = $metavalue;
158 if ($self->{'metaname'} =~ m/^Creator(:.*)?$/)
159 {
160 &sorttools::format_string_name_english(\$formatted_node);
161 }
162 else
163 {
164 &sorttools::format_string_english(\$formatted_node);
165 }
166
167 $self->{'classifiers'}->{$metavalue}
168 = { 'classifyobj' => $listclassobj,
169 'formattednode' => $formatted_node };
170 }
171 }
172 }
173
174
175 return (\@single_classlist,\@multiple_classlist);
176}
177
178
179sub reclassify
180{
181 my ($self,$multiple_cl_ref) = @_;
182
183 # Entries in the current classify list that are "book nodes"
184 # should be recursively classified.
185 #--
186 foreach $dm_pair (@$multiple_cl_ref)
187 {
188 my ($doc_OID,$mdoffset,$metavalue) = @$dm_pair;
189 my $listclassobj;
190
191 # find metavalue in list of sub-classifiers
192 my $found = 0;
193 my $node_name;
194 foreach $node_name (keys %{$self->{'classifiers'}})
195 {
196 $resafe_node_name = $node_name;
197 $resafe_node_name =~ s/(\(|\)|\[|\]|\{|\}|\^|\$|\.|\+|\*|\?|\|)/\\$1/g;
198 if ($metavalue =~ m/^$resafe_node_name$/i)
199 {
200 my ($doc_obj,$date) = @{$self->{'reclassify'}->{$doc_OID}};
201
202 ## date appears to not be used in classifier call ####
203
204 # SECTIONFIX? section must include multiple levels, e.g. '1.12'
205 #if ($doc_OID =~ m/^.*\.(\d+)$/)
206 if ($doc_OID =~ m/^[^\.]*\.([\d\.]+)$/)
207 {
208 $self->{'classifiers'}->{$node_name}->{'classifyobj'}
209 # SECTIONFIX? classify can't handle multi-level section
210 #->classify($doc_obj, "Section=$1");
211 ->classify_section($1, $doc_obj, $date);
212 }
213 else
214 {
215 $self->{'classifiers'}->{$node_name}->{'classifyobj'}
216 ->classify($doc_obj);
217 }
218
219 $found = 1;
220 last;
221 }
222 }
223
224 if (!$found)
225 {
226 print $outhandle "Warning: AZCompactList::reclassify ";
227 print $outhandle "could not find sub-node for $metavalue with doc_OID $doc_OID\n";
228 }
229 }
230}
231
2321;
Note: See TracBrowser for help on using the repository browser.