/[webpac]/trunk2/all2all.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk2/all2all.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 500 - (hide annotations)
Sun Oct 10 11:04:52 2004 UTC (14 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 8135 byte(s)
implement filter{name} which can be embedded inside filed, just like
eval{...}. Code for filters is not compatibile with old implementation, but
it should be easier.
If you mix eval{} and filter{}, eval has to come first.

1 dpavlin 1 #!/usr/bin/perl -w
2    
3 dpavlin 348 =head1 NAME
4    
5 dpavlin 354 all2all.pl - basic script for all WebPAC needs
6 dpavlin 348
7     =cut
8    
9 dpavlin 1 use strict;
10 dpavlin 490 use locale;
11 dpavlin 454 use YAML;
12 dpavlin 352 use Carp;
13 dpavlin 437 use Getopt::Long;
14 dpavlin 1
15 dpavlin 352 use lib './lib';
16 dpavlin 354 use WebPAC;
17 dpavlin 390 use WebPAC::jsFind;
18 dpavlin 410 use WebPAC::Index;
19 dpavlin 441 use WebPAC::Tree;
20 dpavlin 348
21 dpavlin 437 # options which can be changed via command line
22     #
23     my $code_page = 'ISO-8859-2';
24     my ($limit_mfn, $start_mfn, $debug, $low_mem);
25     my $index_path = './out/index';
26    
27     my $result = GetOptions(
28     "code_page=s" => \$code_page,
29     "limit_mfn=i" => \$limit_mfn,
30     "start_mfn=i" => \$start_mfn,
31     "debug!" => \$debug,
32     "low_mem!" => \$low_mem,
33     );
34    
35 dpavlin 500 my $filter = {
36     'CROVOC' => sub {
37     my $tmp = shift || return;
38     return undef unless ($tmp =~ s/CROVOC.*$/ */);
39     return $tmp;
40     },
41     };
42    
43 dpavlin 437 # create WebPAC object
44     #
45 dpavlin 354 my $webpac = new WebPAC(
46 dpavlin 437 code_page => $code_page,
47     limit_mfn => $limit_mfn,
48     start_mfn => $start_mfn,
49     debug => $debug,
50     low_mem => $low_mem,
51 dpavlin 500 filter => $filter,
52 dpavlin 352 ) || die;
53    
54 dpavlin 421 my $log = $webpac->_get_logger() || die "can't get logger";
55 dpavlin 373
56 dpavlin 421 $log->debug("creating WebPAC::jsFind object");
57    
58 dpavlin 390 my $index = new WebPAC::jsFind(
59 dpavlin 437 index_path => $index_path,
60 dpavlin 413 keys => 10,
61 dpavlin 390 ) || die;
62    
63 dpavlin 410 my $thes;
64    
65 dpavlin 10 $|=1;
66 dpavlin 9
67 dpavlin 352 my $maxmfn = $webpac->open_isis(
68 dpavlin 357 filename => shift @ARGV || '/data/hidra/THS/THS',
69 dpavlin 352 lookup => [
70 dpavlin 348 { 'key' => 'd:v900', 'val' => 'v250^a' },
71 dpavlin 352 # { 'eval' => '"v901^a" eq "Podruèje"', 'key' => 'pa:v561^4:v562^4:v461^1', 'val' => 'v900' },
72     # { 'eval '=> '"v901^a" eq "Mikrotezaurus"', 'key' => 'a:v561^4:v562^4:v461^1', 'val' => 'v900' },
73     # { 'eval' => '"v901^a" eq "Deskriptor"', 'key' => 'a:v561^4:v562^4:v461^1', 'val' => 'v900' },
74     { 'key' => 'a:v561^4:v562^4:v461^1', 'val' => 'v900' },
75 dpavlin 374 { 'key' => '900_mfn:v900', 'val' => 'v000' },
76 dpavlin 419 # tree structure
77 dpavlin 471 { 'eval' => 'length("v251") == 2 && "v800" =~ m/EUROVOC/ || "v800" =~ m/CROVOC/ && "v251" =~ m/^(H|HD|L|Z|P)$/', 'key' => 'root:v251', 'val' => 'v900' },
78 dpavlin 419 { 'eval' => '"v251"', 'key' => 'code:v900', 'val' => 'v561^4:v251' },
79 dpavlin 460 { 'eval' => '"v561^4" && "v562^4"', 'key' => 'code:v900', 'val' => 'v561^4:v562^4' },
80 dpavlin 352 ],
81 dpavlin 54 );
82 dpavlin 3
83 dpavlin 421 $log->debug("isis file ",$webpac->{'isis_filename'}," opened");
84    
85 dpavlin 372 $log->info("rows: $maxmfn");
86 dpavlin 170
87 dpavlin 363 $webpac->open_import_xml(type => 'isis_hidra_ths');
88    
89 dpavlin 425 if(1) { # XXX
90 dpavlin 424
91 dpavlin 362 while (my $rec = $webpac->fetch_rec) {
92 dpavlin 358
93 dpavlin 370 my @ds = $webpac->data_structure($rec);
94 dpavlin 366
95 dpavlin 411 if (0 && $log->is_debug) {
96 dpavlin 454 $log->debug("rec = ",Dump($rec));
97     $log->debug("ds = ",Dump(\@ds));
98 dpavlin 372 }
99    
100 dpavlin 374 next if (! @ds);
101 dpavlin 366
102 dpavlin 421 my $filename = $webpac->{'current_filename'} || $log->logdie("no current_filename in webpac object");
103 dpavlin 374
104     if ($filename) {
105 dpavlin 411 $webpac->output_file(
106     file => $filename,
107 dpavlin 374 template => 'html.tt',
108     data => \@ds,
109 dpavlin 398 headline => $webpac->{'headline'},
110 dpavlin 374 );
111     } else {
112     print $webpac->output(
113     template => 'text.tt',
114     data => \@ds,
115 dpavlin 398 headline => $webpac->{'headline'},
116 dpavlin 374 );
117     }
118    
119 dpavlin 398 my $headline = $webpac->{'headline'};
120 dpavlin 390
121 dpavlin 392 my $f = $filename;
122     $f =~ s!out/!!;
123    
124 dpavlin 390 # save into index
125     foreach my $ds (@ds) {
126     next if (! $ds->{'swish'});
127    
128 dpavlin 466 # strip all non word characters from beginning or end
129     # of word
130     my $words = join(" ",@{$ds->{'swish'}});
131     $words =~ s/^\W+//;
132     $words =~ s/\W*\s+\W*/ /g;
133     $words =~ s/\W+$//;
134    
135 dpavlin 390 $index->insert(
136     index_name => $ds->{'tag'},
137 dpavlin 466 #path => $f,
138     path => $webpac->mfn,
139 dpavlin 390 headline => $headline,
140 dpavlin 466 words => $words,
141 dpavlin 390 );
142     }
143    
144 dpavlin 410 # save into sorted index (thesaurus)
145     foreach my $ds (@ds) {
146     next if (! $ds->{'index'});
147    
148     $thes->{$ds->{'tag'}} ||= new WebPAC::Index;
149    
150 dpavlin 415 foreach my $h (@{$ds->{'index'}}) {
151     $thes->{$ds->{'tag'}}->insert(
152     headline => $h,
153 dpavlin 448 mfn => $webpac->mfn,
154 dpavlin 415 );
155     }
156 dpavlin 410 }
157    
158 dpavlin 454 # print Dump(\@ds);
159 dpavlin 390
160 dpavlin 3 }
161    
162 dpavlin 411 foreach my $t (keys %{$thes}) {
163    
164     my @e = $thes->{$t}->elements;
165     if (! @e) {
166     $log->logwarn("no elements in sorted index $t?");
167     next;
168     }
169    
170 dpavlin 415 my $file = "./out/bfilter/$t.txt";
171     $log->info("saving sorted index $t to '$file' [".scalar(@e)." elements]");
172 dpavlin 411
173     $webpac->output_file(
174 dpavlin 415 file => $file,
175 dpavlin 411 template => 'index.tt',
176     data => \@e,
177     index_name => $t,
178     );
179     }
180    
181     if (0 && $log->is_debug) {
182 dpavlin 454 $log->debug("lookup hash: ",Dump($webpac->{'lookup'}));
183     $log->debug("data hash: ",Dump($webpac->{'data'}));
184 dpavlin 410 foreach my $t (keys %{$thes}) {
185 dpavlin 454 $log->debug("thesaurus $t hash: ",Dump($thes->{$t}));
186 dpavlin 410 }
187 dpavlin 372 }
188 dpavlin 390
189 dpavlin 424 } # XXX if(0)
190    
191 dpavlin 454 $log->debug("lookup hash: ",Dump($webpac->{'lookup'}));
192 dpavlin 420
193 dpavlin 441 $log->info("creating tree");
194    
195 dpavlin 419 #
196 dpavlin 441 # define tree structure
197 dpavlin 419 #
198    
199 dpavlin 424 my $l = $webpac->{'lookup'} || $log->logconfess("can't find lookup");
200 dpavlin 419
201 dpavlin 424 my @tree = ({
202     # level 0
203     code_arr => sub { sort keys %{$l} },
204     filter_code => sub {
205     my $t = shift;
206     return $t if ($t =~ s/root://);
207     },
208     lookup_v900 => sub { shift @{$l->{"root:".$_[0]}} },
209     lookup_term => sub { shift @{$l->{"d:".$_[1]}} },
210     lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[1]}} },
211 dpavlin 454 have_children => sub { return $l->{"a:".$_[0]."::"} },
212     have_children_at_level => sub {
213 dpavlin 471 return unless (defined($l->{"code:".$_[1]}));
214     my $code = shift @{$l->{"code:".$_[1]}};
215     print STDERR "## $_[1] -> $code\n";
216     return undef unless($code);
217     return(9, $l->{"a:$code:"} ) if (defined($l->{"a:$code:"}));
218 dpavlin 454 },
219 dpavlin 424 style => 'display: none',
220     },{
221     # 1
222 dpavlin 454 code_arr => sub { @{$_[0]} },
223 dpavlin 424 filter_code => sub { shift }, # nop
224     lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} },
225     lookup_term => sub { shift @{$l->{"d:".$_[0]}} },
226     lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} },
227 dpavlin 454 have_children => sub { return $l->{"a:".$_[1].":"} },
228 dpavlin 424 style => 'display: none',
229     },{
230     # 2
231 dpavlin 454 code_arr => sub { @{$_[0]} },
232 dpavlin 424 filter_code => sub { shift },
233 dpavlin 460 lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} },
234 dpavlin 424 lookup_term => sub { shift @{$l->{"d:".$_[0]}} },
235     lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} },
236 dpavlin 460 have_children => sub { return $l->{"a:".$_[1].":".$_[0]} },
237 dpavlin 454 #style => 'display: none',
238 dpavlin 425 },{
239     # 3 u¾i pojam
240 dpavlin 454 code_arr => sub { @{$_[0]} },
241 dpavlin 425 filter_code => sub { shift },
242 dpavlin 460 lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} },
243 dpavlin 426 lookup_term => sub { shift @{$l->{"d:".$_[0]}} },
244     lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} },
245 dpavlin 460 have_children => sub { return $l->{"a:".$_[1].":".$_[0]} },
246 dpavlin 426 },{
247     # 4
248 dpavlin 454 code_arr => sub { @{$_[0]} },
249 dpavlin 426 filter_code => sub { shift },
250 dpavlin 460 lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} },
251 dpavlin 426 lookup_term => sub { shift @{$l->{"d:".$_[0]}} },
252     lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} },
253 dpavlin 460 have_children => sub { return $l->{"a:".$_[1].":".$_[0]} },
254 dpavlin 427 },{
255     # 5
256 dpavlin 454 code_arr => sub { @{$_[0]} },
257 dpavlin 427 filter_code => sub { shift },
258 dpavlin 460 lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} },
259 dpavlin 427 lookup_term => sub { shift @{$l->{"d:".$_[0]}} },
260     lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} },
261 dpavlin 460 have_children => sub { return $l->{"a:".$_[1].":".$_[0]} },
262 dpavlin 427 },{
263     # 6
264 dpavlin 454 code_arr => sub { @{$_[0]} },
265 dpavlin 427 filter_code => sub { shift },
266 dpavlin 460 lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} },
267 dpavlin 427 lookup_term => sub { shift @{$l->{"d:".$_[0]}} },
268     lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} },
269 dpavlin 460 have_children => sub { return $l->{"a:".$_[1].":".$_[0]} },
270 dpavlin 427 },{
271     # 7
272 dpavlin 454 code_arr => sub { @{$_[0]} },
273 dpavlin 427 filter_code => sub { shift },
274 dpavlin 460 lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} },
275 dpavlin 427 lookup_term => sub { shift @{$l->{"d:".$_[0]}} },
276     lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} },
277 dpavlin 460 have_children => sub { return $l->{"a:".$_[1].":".$_[0]} },
278 dpavlin 427 },{
279     # 8
280 dpavlin 454 code_arr => sub { @{$_[0]} },
281 dpavlin 427 filter_code => sub { shift },
282 dpavlin 460 lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} },
283 dpavlin 427 lookup_term => sub { shift @{$l->{"d:".$_[0]}} },
284     lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} },
285 dpavlin 460 # have_children => sub { return $l->{"a:".$_[1].":".$_[0]} },
286 dpavlin 424 have_children => sub { 0 },
287 dpavlin 454 },{
288     # 9 - level which is never reached except explicitly
289 dpavlin 471 code_arr => sub { @{$_[0]} },
290 dpavlin 454 filter_code => sub { shift },
291 dpavlin 460 lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} },
292 dpavlin 454 lookup_term => sub { shift @{$l->{"d:".$_[0]}} },
293     lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} },
294     have_children => sub { 0 },
295 dpavlin 471 have_children_at_level => sub { defined($l->{"a:".$_[1].":".$_[0]}) && return (9,$l->{"a:".$_[1].":".$_[0]}) },
296 dpavlin 454 },{
297 dpavlin 424 });
298 dpavlin 419
299 dpavlin 441 my $tree = new WebPAC::Tree(
300     dir => './out',
301     html => 'browse.html',
302     template => './output_template/tree.tt',
303     js => 'tree-ids.js',
304     tree => \@tree,
305     );
306 dpavlin 428
307     $log->info("closing index");
308 dpavlin 390 $index->close;
309    
310 dpavlin 422 $log->info("elapsed time: ",$webpac->fmt_time(time() - $webpac->{'start_t'}));

Properties

Name Value
cvs2svn:cvs-rev 1.64
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26