source: trunk/gsdl/perllib/classify/AZCompactSectionList.pm@ 3114

Last change on this file since 3114 was 2897, checked in by sjboddie, 22 years ago

Added AZCompactSectionList which was contributed by Don Gourley
<gourley@…> - All these classifiers need sorting out some time ...

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