source: trunk/gsdl/perllib/mgbuilder.pm@ 900

Last change on this file since 900 was 835, checked in by davidb, 24 years ago

added 'begin' and 'end' function for plugins

  • Property svn:keywords set to Author Date Id Revision
File size: 22.4 KB
Line 
1###########################################################################
2#
3# mgbuilder.pm -- MGBuilder object
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26package mgbuilder;
27
28use classify;
29use cfgread;
30use colcfg;
31use plugin;
32use util;
33
34$maxdocsize = 12000;
35
36%wanted_index_files = ('td'=>1,
37 't'=>1,
38 'idb'=>1,
39 'ib1'=>1,
40 'ib2'=>1,
41 'ib3'=>1,
42 'i'=>1,
43 'ip'=>1,
44 'tiw'=>1,
45 'wa'=>1);
46
47
48sub new {
49 my ($class, $collection, $source_dir, $build_dir, $verbosity,
50 $maxdocs, $debug, $keepold, $allclassifications) = @_;
51
52 # create an mgbuilder object
53 my $self = bless {'collection'=>$collection,
54 'source_dir'=>$source_dir,
55 'build_dir'=>$build_dir,
56 'verbosity'=>$verbosity,
57 'maxdocs'=>$maxdocs,
58 'debug'=>$debug,
59 'keepold'=>$keepold,
60 'allclassifications'=>$allclassifications,
61 'notbuilt'=>[] # indexes not built
62 }, $class;
63
64
65 # read in the collection configuration file
66 my $colcfgname = "$ENV{'GSDLCOLLECTDIR'}/etc/collect.cfg";
67 if (!-e $colcfgname) {
68 die "mgbuilder::new - couldn't find collect.cfg for collection $collection\n";
69 }
70 $self->{'collect_cfg'} = &colcfg::read_collect_cfg ($colcfgname);
71
72 # sort out subcollection indexes
73 if (defined $self->{'collect_cfg'}->{'indexsubcollections'}) {
74 my $indexes = $self->{'collect_cfg'}->{'indexes'};
75 $self->{'collect_cfg'}->{'indexes'} = [];
76 foreach $subcollection (@{$self->{'collect_cfg'}->{'indexsubcollections'}}) {
77 foreach $index (@$indexes) {
78 push (@{$self->{'collect_cfg'}->{'indexes'}}, "$index:$subcollection");
79 }
80 }
81 }
82
83 # sort out language subindexes
84 if (defined $self->{'collect_cfg'}->{'languages'}) {
85 my $indexes = $self->{'collect_cfg'}->{'indexes'};
86 $self->{'collect_cfg'}->{'indexes'} = [];
87 foreach $language (@{$self->{'collect_cfg'}->{'languages'}}) {
88 foreach $index (@$indexes) {
89 push (@{$self->{'collect_cfg'}->{'indexes'}}, "$index:$language");
90 }
91 }
92 }
93
94 # get the list of plugins for this collection
95 my $plugins = [];
96 if (defined $self->{'collect_cfg'}->{'plugin'}) {
97 $plugins = $self->{'collect_cfg'}->{'plugin'};
98 }
99
100 # load all the plugins
101 $self->{'pluginfo'} = &plugin::load_plugins ($plugins);
102 if (scalar(@{$self->{'pluginfo'}}) == 0) {
103 print STDERR "No plugins were loaded.\n";
104 die "\n";
105 }
106
107 # get the list of classifiers for this collection
108 my $classifiers = [];
109 if (defined $self->{'collect_cfg'}->{'classify'}) {
110 $classifiers = $self->{'collect_cfg'}->{'classify'};
111 }
112
113 # load all the classifiers
114 $self->{'classifiers'} = &classify::load_classifiers ($classifiers);
115
116 # load up any dontgdbm fields
117 $self->{'dontgdbm'} = {};
118 if (defined ($self->{'collect_cfg'}->{'dontgdbm'})) {
119 foreach $dg (@{$self->{'collect_cfg'}->{'dontgdbm'}}) {
120 $self->{'dontgdbm'}->{$dg} = 1;
121 }
122 }
123
124 # load up the document processor for building
125 # if a buildproc class has been created for this collection, use it
126 # otherwise, use the mg buildproc
127 my ($buildprocdir, $buildproctype);
128 if (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/${collection}buildproc.pm") {
129 $buildprocdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
130 $buildproctype = "${collection}buildproc";
131 } else {
132 $buildprocdir = "$ENV{'GSDLHOME'}/perllib";
133 $buildproctype = "mgbuildproc";
134 }
135 require "$buildprocdir/$buildproctype.pm";
136
137 eval("\$self->{'buildproc'} = new $buildproctype(\$collection, " .
138 "\$source_dir, \$build_dir, \$verbosity)");
139 die "$@" if $@;
140
141
142 return $self;
143}
144
145sub init {
146 my $self = shift (@_);
147
148 if (!$self->{'debug'} && !$self->{'keepold'}) {
149 # remove any old builds
150 &util::rm_r($self->{'build_dir'});
151 &util::mk_all_dir($self->{'build_dir'});
152
153 # make the text directory
154 my $textdir = "$self->{'build_dir'}/text";
155 &util::mk_all_dir($textdir);
156 }
157}
158
159sub compress_text {
160 my $self = shift (@_);
161 my ($textindex) = @_;
162 my $exedir = "$ENV{'GSDLHOME'}/bin/$ENV{'GSDLOS'}";
163 my $exe = &util::get_os_exe ();
164 my $mg_passes_exe = &util::filename_cat($exedir, "mg_passes$exe");
165 my $mg_compression_dict_exe = &util::filename_cat($exedir, "mg_compression_dict$exe");
166
167 &util::mk_all_dir (&util::filename_cat($self->{'build_dir'}, "text"));
168 my $basefilename = "text/$self->{'collection'}";
169 my $fulltextprefix = &util::filename_cat ($self->{'build_dir'}, $basefilename);
170
171 my $osextra = "";
172 if ($ENV{'GSDLOS'} =~ /^windows$/i) {
173 $fulltextprefix =~ s/\//\\/g;
174 } else {
175 $osextra = " -d /";
176 }
177
178 print STDERR "\n*** creating the compressed text\n" if ($self->{'verbosity'} >= 1);
179
180 # collect the statistics for the text
181 # -b $maxdocsize sets the maximum document size to be 12 meg
182 print STDERR "\n collecting text statistics\n" if ($self->{'verbosity'} >= 1);
183
184 my ($handle);
185 if ($self->{'debug'}) {
186 $handle = STDOUT;
187 } else {
188 if (!-e "$mg_passes_exe" ||
189 !open (PIPEOUT, "| $mg_passes_exe -f $fulltextprefix -b $maxdocsize -T1 $osextra")) {
190 die "mgbuilder::compress_text - couldn't run $mg_passes_exe\n";
191 }
192 $handle = mgbuilder::PIPEOUT;
193 }
194
195 $self->{'buildproc'}->set_output_handle ($handle);
196 $self->{'buildproc'}->set_mode ('text');
197 $self->{'buildproc'}->set_index ($textindex);
198 $self->{'buildproc'}->set_indexing_text (0);
199 $self->{'buildproc'}->reset();
200 &plugin::begin($self->{'pluginfo'}, $self->{'source_dir'},
201 $self->{'buildproc'}, $self->{'maxdocs'});
202 &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
203 "", {}, $self->{'buildproc'}, $self->{'maxdocs'});
204 &plugin::end($self->{'pluginfo'});
205 close (PIPEOUT);
206
207 close ($handle) unless $self->{'debug'};
208
209 # create the compression dictionary
210 # the compression dictionary is built by assuming the stats are from a seed
211 # dictionary (-S), if a novel word is encountered it is spelled out (-H),
212 # and the resulting dictionary must be less than 5 meg with the most frequent
213 # words being put into the dictionary first (-2 -k 5120)
214 if (!$self->{'debug'}) {
215 print STDERR "\n creating the compression dictionary\n" if ($self->{'verbosity'} >= 1);
216 if (!-e "$mg_compression_dict_exe") {
217 die "mgbuilder::compress_text - couldn't run $mg_compression_dict_exe\n";
218 }
219 system ("$mg_compression_dict_exe -f $fulltextprefix -S -H -2 -k 5120 $osextra");
220
221 # -b $maxdocsize sets the maximum document size to be 12 meg
222 if (!$self->{'debug'}) {
223 if (!-e "$mg_passes_exe" ||
224 !open ($handle, "| $mg_passes_exe -f $fulltextprefix -b $maxdocsize -T2 $osextra")) {
225 die "mgbuilder::compress_text - couldn't run $mg_passes_exe\n";
226 }
227 }
228 }
229
230 $self->{'buildproc'}->reset();
231 # compress the text
232 print STDERR "\n compressing the text\n" if ($self->{'verbosity'} >= 1);
233 &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
234 "", {}, $self->{'buildproc'}, $self->{'maxdocs'});
235 close ($handle) unless $self->{'debug'};
236}
237
238sub want_built {
239 my $self = shift (@_);
240 my ($index) = @_;
241
242 if (defined ($self->{'collect_cfg'}->{'dontbuild'})) {
243 foreach $checkstr (@{$self->{'collect_cfg'}->{'dontbuild'}}) {
244 if ($index =~ /^$checkstr$/) {
245 push (@{$self->{'notbuilt'}}, $self->{'index_mapping'}->{$index});
246 return 0;
247 }
248 }
249 }
250
251 return 1;
252}
253
254sub build_indexes {
255 my $self = shift (@_);
256 my ($indexname) = @_;
257
258 my $indexes = [];
259 if (defined $indexname && $indexname =~ /\w/) {
260 push @$indexes, $indexname;
261 } else {
262 $indexes = $self->{'collect_cfg'}->{'indexes'};
263 }
264
265 # create the mapping between the index descriptions
266 # and their directory names
267 $self->{'index_mapping'} = $self->create_index_mapping ($indexes);
268
269 # build each of the indexes
270 foreach $index (@$indexes) {
271 if ($self->want_built($index)) {
272 print STDERR "\n*** building index $index in subdirectory " .
273 "$self->{'index_mapping'}->{$index}\n" if ($self->{'verbosity'} >= 1);
274 $self->build_index($index);
275 } else {
276 print STDERR "\n*** ignoring index $index\n" if ($self->{'verbosity'} >= 1);
277 }
278 }
279}
280
281# creates directory names for each of the index descriptions
282sub create_index_mapping {
283 my $self = shift (@_);
284 my ($indexes) = @_;
285
286 my %mapping = ();
287 $mapping{'indexmaporder'} = [];
288 $mapping{'subcollectionmaporder'} = [];
289 $mapping{'languagemaporder'} = [];
290
291 # dirnames is used to check for collisions. Start this off
292 # with the manditory directory names
293 my %dirnames = ('text'=>'text',
294 'extra'=>'extra');
295 my %pnames = ('index' => '', 'subcollection' => '', 'languages' => '');
296
297 foreach $index (@$indexes) {
298 my ($level, $gran, $subcollection, $languages) = split (":", $index);
299
300 # the directory name starts with the first character of the index level
301 my ($pindex) = $level =~ /^(.)/;
302
303 # next comes a processed version of the index
304 $pindex .= $self->process_field ($gran);
305 $pindex = lc ($pindex);
306
307 # next comes a processed version of the subcollection if there is one.
308 my $psub = $self->process_field ($subcollection);
309 $psub = lc ($psub);
310
311 # next comes a processed version of the language if there is one.
312 my $plang = $self->process_field ($languages);
313 $plang = lc ($plang);
314
315 my $dirname = $pindex . $psub . $plang;
316
317 # check to be sure all index names are unique
318 while (defined ($dirnames{$dirname})) {
319 $dirname = $self->make_unique (\%pnames, $index, \$pindex, \$psub, \$plang);
320 }
321
322 # store the mapping orders as well as the maps
323 if (!defined $mapping{'indexmap'}{"$level:$gran"}) {
324 $mapping{'indexmap'}{"$level:$gran"} = $pindex;
325 push (@{$mapping{'indexmaporder'}}, "$level:$gran");
326 }
327 if ($psub =~ /\w/ && !defined ($mapping{'subcollectionmap'}{$subcollection})) {
328 $mapping{'subcollectionmap'}{$subcollection} = $psub;
329 push (@{$mapping{'subcollectionmaporder'}}, $subcollection);
330 }
331 if ($plang =~ /\w/ && !defined ($mapping{'languagemap'}{$languages})) {
332 $mapping{'languagemap'}{$languages} = $plang;
333 push (@{$mapping{'languagemaporder'}}, $language);
334 }
335 $mapping{$index} = $dirname;
336 $dirnames{$dirname} = $index;
337 $pnames{'index'}{$pindex} = "$level:$gran";
338 $pnames{'subcollection'}{$psub} = $subcollection;
339 $pnames{'languages'}{$plang} = $languages;
340 }
341
342 return \%mapping;
343}
344
345# returns a processed version of a field.
346# if the field has only one component the processed
347# version will contain the first character and next consonant
348# of that componant - otherwise it will contain the first
349# character of the first two components
350sub process_field {
351 my $self = shift (@_);
352 my ($field) = @_;
353
354 return "" unless (defined ($field) && $field =~ /\w/);
355
356 my @components = split /,/, $field;
357 if (scalar @components >= 2) {
358 splice (@components, 2);
359 map {s/^(.).*$/$1/;} @components;
360 return join("", @components);
361 } else {
362 my ($a, $b) = $field =~ /^(.).*?([bcdfghjklmnpqrstvwxyz])/i;
363 ($a, $b) = $field =~ /^(.)(.)/ unless defined $a && defined $b;
364 return "$a$b";
365 }
366}
367
368sub make_unique {
369 my $self = shift (@_);
370 my ($namehash, $index, $indexref, $subref, $langref) = @_;
371 my ($level, $gran, $subcollection, $languages) = split (":", $index);
372
373 if ($namehash->{'index'}->{$$indexref} ne "$level:$gran") {
374 $self->get_next_version ($indexref);
375 } elsif ($namehash->{'subcollection'}->{$$subref} ne $subcollection) {
376 $self->get_next_version ($subref);
377 } elsif ($namehash->{'languages'}->{$$langref} ne $languages) {
378 $self->get_next_version ($langref);
379 }
380 return "$$indexref$$subref$$langref";
381}
382
383sub get_next_version {
384 my $self = shift (@_);
385 my ($nameref) = @_;
386
387 if ($$nameref =~ /(\d\d)$/) {
388 my $num = $1; $num ++;
389 $$nameref =~ s/\d\d$/$num/;
390 } elsif ($$nameref =~ /(\d)$/) {
391 my $num = $1;
392 if ($num == 9) {$$nameref =~ s/\d\d$/10/;}
393 else {$num ++; $$nameref =~ s/\d$/$num/;}
394 } else {
395 $$nameref =~ s/.$/0/;
396 }
397}
398
399sub build_index {
400 my $self = shift (@_);
401 my ($index) = @_;
402
403 # get the full index directory path and make sure it exists
404 my $indexdir = $self->{'index_mapping'}->{$index};
405 &util::mk_all_dir (&util::filename_cat($self->{'build_dir'}, $indexdir));
406 my $fullindexprefix = &util::filename_cat ($self->{'build_dir'}, $indexdir,
407 $self->{'collection'});
408 my $fulltextprefix = &util::filename_cat ($self->{'build_dir'}, "text",
409 $self->{'collection'});
410
411 # get any os specific stuff
412 my $exedir = "$ENV{'GSDLHOME'}/bin/$ENV{'GSDLOS'}";
413 my $exe = &util::get_os_exe ();
414 my $mg_passes_exe = &util::filename_cat($exedir, "mg_passes$exe");
415 my $mg_perf_hash_build_exe =
416 &util::filename_cat($exedir, "mg_perf_hash_build$exe");
417 my $mg_weights_build_exe =
418 &util::filename_cat ($exedir, "mg_weights_build$exe");
419 my $mg_invf_dict_exe =
420 &util::filename_cat ($exedir, "mg_invf_dict$exe");
421 my $mg_stem_idx_exe =
422 &util::filename_cat ($exedir, "mg_stem_idx$exe");
423
424 my $osextra = "";
425 if ($ENV{'GSDLOS'} =~ /^windows$/i) {
426 $fullindexprefix =~ s/\//\\/g;
427 } else {
428 $osextra = " -d /";
429 }
430
431 # get the index level from the index description
432 # the index will be level 2 unless we are building a
433 # paragraph level index
434 my $index_level = 2;
435 $index_level = 3 if $index =~ /^paragraph/i;
436
437 # get the index expression if this index belongs
438 # to a subcollection
439 my $indexexparr = [];
440 my ($level, $fields, $subcollection) = split (":", $index);
441 my @subcollections = ();
442 @subcollections = split /,/, $subcollection if (defined $subcollection);
443
444 foreach $subcollection (@subcollections) {
445 if (defined ($self->{'collect_cfg'}->{'subcollection'}->{$subcollection})) {
446 push (@$indexexparr, $self->{'collect_cfg'}->{'subcollection'}->{$subcollection});
447 }
448 }
449
450 # add expressions for languages if this index belongs to
451 # a language subcollection
452 foreach $language (@{$self->{'collect_cfg'}->{'languages'}}) {
453 if ($language =~ s/^\!//) {
454 push (@$indexexparr, "!Language/$language/");
455 } else {
456 push (@$indexexparr, "Language/$language/");
457 }
458 }
459
460 # Build index dictionary. Uses verbatim stem method
461 print STDERR "\n creating index dictionary\n" if ($self->{'verbosity'} >= 1);
462 my ($handle);
463 if ($self->{'debug'}) {
464 $handle = STDOUT;
465 } else {
466 if (!-e "$mg_passes_exe" ||
467 !open (PIPEOUT, "| $mg_passes_exe -f $fullindexprefix -b $maxdocsize " .
468 "-$index_level -m 32 -s 0 -G -t 10 -N1 $osextra")) {
469 die "mgbuilder::build_index - couldn't run $mg_passes_exe\n";
470 }
471 $handle = mgbuilder::PIPEOUT;
472 }
473
474 # set up the document processor
475 $self->{'buildproc'}->set_output_handle ($handle);
476 $self->{'buildproc'}->set_mode ('text');
477 $self->{'buildproc'}->set_index ($index, $indexexparr);
478 $self->{'buildproc'}->set_indexing_text (1);
479
480 $self->{'buildproc'}->reset();
481 &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
482 "", {}, $self->{'buildproc'}, $self->{'maxdocs'});
483 close ($handle) unless $self->{'debug'};
484
485 if (!$self->{'debug'}) {
486 # create the perfect hash function
487 if (!-e "$mg_perf_hash_build_exe") {
488 die "mgbuilder::build_index - couldn't run $mg_perf_hash_build_exe\n";
489 }
490 system ("$mg_perf_hash_build_exe -f $fullindexprefix $osextra");
491
492 if (!-e "$mg_passes_exe" ||
493 !open ($handle, "| $mg_passes_exe -f $fullindexprefix -b $maxdocsize " .
494 "-$index_level -c 3 -G -t 10 -N2 $osextra")) {
495 die "mgbuilder::build_index - couldn't run $mg_passes_exe\n";
496 }
497 }
498
499 # invert the text
500 print STDERR "\n inverting the text\n" if ($self->{'verbosity'} >= 1);
501
502 $self->{'buildproc'}->reset();
503 &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
504 "", {}, $self->{'buildproc'}, $self->{'maxdocs'});
505
506 if (!$self->{'debug'}) {
507
508 close ($handle);
509
510 # create the weights file
511 print STDERR "\n create the weights file\n" if ($self->{'verbosity'} >= 1);
512 if (!-e "$mg_weights_build_exe") {
513 die "mgbuilder::build_index - couldn't run $mg_weights_build_exe\n";
514 }
515 system ("$mg_weights_build_exe -f $fullindexprefix -t $fulltextprefix $osextra");
516
517 # create 'on-disk' stemmed dictionary
518 print STDERR "\n creating 'on-disk' stemmed dictionary\n" if ($self->{'verbosity'} >= 1);
519 if (!-e "$mg_invf_dict_exe") {
520 die "mgbuilder::build_index - couldn't run $mg_invf_dict_exe\n";
521 }
522 system ("$mg_invf_dict_exe -f $fullindexprefix $osextra");
523
524
525 # creates stem index files for the various stemming methods
526 print STDERR "\n creating stem indexes\n" if ($self->{'verbosity'} >= 1);
527 if (!-e "$mg_stem_idx_exe") {
528 die "mgbuilder::build_index - couldn't run $mg_stem_idx_exe\n";
529 }
530 system ("$mg_stem_idx_exe -b 4096 -s1 -f $fullindexprefix $osextra");
531 system ("$mg_stem_idx_exe -b 4096 -s2 -f $fullindexprefix $osextra");
532 system ("$mg_stem_idx_exe -b 4096 -s3 -f $fullindexprefix $osextra");
533
534
535 # remove unwanted files
536 my $tmpdir = &util::filename_cat ($self->{'build_dir'}, $indexdir);
537 opendir (DIR, $tmpdir) || die
538 "mgbuilder::build_index - couldn't read directory $tmpdir\n";
539 foreach $file (readdir(DIR)) {
540 next if $file =~ /^\./;
541 my ($suffix) = $file =~ /\.([^\.]+)$/;
542 if (defined $suffix && !defined $wanted_index_files{$suffix}) {
543 # delete it!
544 print STDERR "deleting $file\n" if $self->{'verbosity'} > 2;
545 &util::rm (&util::filename_cat ($tmpdir, $file));
546 }
547 }
548 closedir (DIR);
549 }
550}
551
552sub make_infodatabase {
553 my $self = shift (@_);
554 my $textdir = &util::filename_cat($self->{'build_dir'}, "text");
555 my $assocdir = &util::filename_cat($self->{'build_dir'}, "assoc");
556 &util::mk_all_dir ($textdir);
557 &util::mk_all_dir ($assocdir);
558
559 # get db name
560 my $dbext = ".bdb";
561 $dbext = ".ldb" if &util::is_little_endian();
562 my $fulldbname = &util::filename_cat ($textdir, "$self->{'collection'}$dbext");
563 $fulldbname =~ s/\//\\/g if ($ENV{'GSDLOS'} =~ /^windows$/i);
564
565 my $exedir = "$ENV{'GSDLHOME'}/bin/$ENV{'GSDLOS'}";
566 my $exe = &util::get_os_exe ();
567 my $txt2db_exe = &util::filename_cat($exedir, "txt2db$exe");
568
569 print STDERR "\n*** creating the info database and processing associated files\n"
570 if ($self->{'verbosity'} >= 1);
571
572 # init all the classifiers
573 &classify::init_classifiers ($self->{'classifiers'});
574
575 # set up the document processor
576 my ($handle);
577 if ($self->{'debug'}) {
578 $handle = STDOUT;
579 } else {
580 if (!-e "$txt2db_exe" || !open (PIPEOUT, "| $txt2db_exe $fulldbname")) {
581 die "mgbuilder::make_infodatabase - couldn't run $txt2db_exe\n";
582 }
583 $handle = mgbuilder::PIPEOUT;
584 }
585
586 $self->{'buildproc'}->set_output_handle ($handle);
587 $self->{'buildproc'}->set_mode ('infodb');
588 $self->{'buildproc'}->set_assocdir ($assocdir);
589 $self->{'buildproc'}->set_dontgdbm ($self->{'dontgdbm'});
590 $self->{'buildproc'}->set_classifiers ($self->{'classifiers'});
591 $self->{'buildproc'}->set_indexing_text (0);
592 $self->{'buildproc'}->reset();
593
594 if (defined $self->{'collect_cfg'}->{'collectionmeta'}) {
595
596 if (!defined $self->{'index_mapping'}) {
597 $self->{'index_mapping'} =
598 $self->create_index_mapping ($self->{'collect_cfg'}->{'indexes'});
599 }
600
601 print $handle "[collection]\n";
602
603 foreach $cmeta (keys (%{$self->{'collect_cfg'}->{'collectionmeta'}})) {
604 if ($cmeta =~ s/^\.//) {
605 if (defined $self->{'index_mapping'}->{$cmeta}) {
606 print $handle "<$self->{'index_mapping'}->{$cmeta}>" .
607 $self->{'collect_cfg'}->{'collectionmeta'}->{".$cmeta"} . "\n";
608 } else {
609 print STDERR "mgbuilder: warning bad collectionmeta option '$cmeta' - ignored\n";
610 }
611 } else {
612 print $handle "<$cmeta>$self->{'collect_cfg'}->{'collectionmeta'}->{$cmeta}\n";
613 }
614 }
615 print $handle "\n" . ('-' x 70) . "\n";
616
617 }
618
619 &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
620 "", {}, $self->{'buildproc'}, $self->{'maxdocs'});
621
622 # output classification information
623 &classify::output_classify_info ($self->{'classifiers'}, $handle,
624 $self->{'allclassifications'});
625
626 close ($handle) if !$self->{'debug'};
627}
628
629sub collect_specific {
630 my $self = shift (@_);
631}
632
633sub make_auxiliary_files {
634 my $self = shift (@_);
635 my ($index);
636 my %build_cfg = ();
637
638 print STDERR "\n*** creating auxiliary files \n" if ($self->{'verbosity'} >= 1);
639
640 # get the text directory
641 &util::mk_all_dir ($self->{'build_dir'});
642
643 # store the build date
644 $build_cfg->{'builddate'} = time;
645
646 # store the number of documents and number of bytes
647 $build_cfg->{'numdocs'} = $self->{'buildproc'}->get_num_docs();
648 $build_cfg->{'numbytes'} = $self->{'buildproc'}->get_num_bytes();
649
650 # store the mapping between the index names and the directory names
651 my @indexmap = ();
652 foreach $index (@{$self->{'index_mapping'}->{'indexmaporder'}}) {
653 push (@indexmap, "$index\-\>$self->{'index_mapping'}->{'indexmap'}->{$index}");
654 }
655 $build_cfg->{'indexmap'} = \@indexmap;
656
657 my @subcollectionmap = ();
658 foreach $subcollection (@{$self->{'index_mapping'}->{'subcollectionmaporder'}}) {
659 push (@subcollectionmap, "$subcollection\-\>" .
660 $self->{'index_mapping'}->{'subcollectionmap'}->{$subcollection});
661 }
662 $build_cfg->{'subcollectionmap'} = \@subcollectionmap if scalar (@subcollectionmap);
663
664 my @languagemap = ();
665 foreach $language (@{$self->{'index_mapping'}->{'languagemaporder'}}) {
666 push (@languagemap, "$language\-\>" .
667 $self->{'index_mapping'}->{'languagemap'}->{$language});
668 }
669 $build_cfg->{'languagemap'} = \@languagemap if scalar (@languagemap);
670
671 $build_cfg->{'notbuilt'} = $self->{'notbuilt'};
672
673 # write out the build information
674 &cfgread::write_cfg_file("$self->{'build_dir'}/build.cfg", $build_cfg,
675 '^(builddate|numdocs|numbytes)$',
676 '^(indexmap|subcollectionmap|languagemap|notbuilt)$');
677
678}
679
680sub deinit {
681 my $self = shift (@_);
682}
683
684
6851;
686
687
Note: See TracBrowser for help on using the repository browser.