[537] | 1 | ###########################################################################
|
---|
[4] | 2 | #
|
---|
[537] | 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 | ###########################################################################
|
---|
[4] | 25 |
|
---|
| 26 | package mgbuilder;
|
---|
| 27 |
|
---|
[10468] | 28 | use basebuilder;
|
---|
[4] | 29 | use plugin;
|
---|
[15716] | 30 | use strict; no strict 'refs';
|
---|
[4] | 31 | use util;
|
---|
| 32 |
|
---|
[15716] | 33 |
|
---|
[1304] | 34 | BEGIN {
|
---|
[10468] | 35 | @mgbuilder::ISA = ('basebuilder');
|
---|
[1304] | 36 | }
|
---|
| 37 |
|
---|
| 38 |
|
---|
[8716] | 39 | my %wanted_index_files = ('td'=>1,
|
---|
[4] | 40 | 't'=>1,
|
---|
| 41 | 'idb'=>1,
|
---|
| 42 | 'ib1'=>1,
|
---|
| 43 | 'ib2'=>1,
|
---|
| 44 | 'ib3'=>1,
|
---|
| 45 | 'i'=>1,
|
---|
| 46 | 'ip'=>1,
|
---|
| 47 | 'tiw'=>1,
|
---|
| 48 | 'wa'=>1);
|
---|
| 49 |
|
---|
[10468] | 50 | my $maxdocsize = $basebuilder::maxdocsize;
|
---|
[4] | 51 |
|
---|
[10468] | 52 |
|
---|
[4] | 53 | sub new {
|
---|
[10468] | 54 | my $class = shift(@_);
|
---|
| 55 |
|
---|
| 56 | my $self = new basebuilder (@_);
|
---|
| 57 | $self = bless $self, $class;
|
---|
[1424] | 58 |
|
---|
[10468] | 59 | $self->{'buildtype'} = "mg";
|
---|
| 60 | return $self;
|
---|
| 61 | }
|
---|
[4] | 62 |
|
---|
[10468] | 63 | sub default_buildproc {
|
---|
| 64 | my $self = shift (@_);
|
---|
[4] | 65 |
|
---|
[10468] | 66 | return "mgbuildproc";
|
---|
| 67 | }
|
---|
[4] | 68 |
|
---|
[10468] | 69 | sub generate_index_list {
|
---|
| 70 | my $self = shift (@_);
|
---|
| 71 |
|
---|
[5225] | 72 | if (!defined($self->{'collect_cfg'}->{'indexes'})) {
|
---|
| 73 | $self->{'collect_cfg'}->{'indexes'} = [];
|
---|
| 74 | }
|
---|
[4743] | 75 | if (scalar(@{$self->{'collect_cfg'}->{'indexes'}}) == 0) {
|
---|
| 76 | # no indexes have been specified so we'll build a "dummy:text" index
|
---|
| 77 | push (@{$self->{'collect_cfg'}->{'indexes'}}, "dummy:text");
|
---|
| 78 | }
|
---|
[22352] | 79 | # remove any ex.
|
---|
| 80 | my @orig_indexes = @{$self->{'collect_cfg'}->{'indexes'}};
|
---|
| 81 | $self->{'collect_cfg'}->{'indexes'} = [];
|
---|
| 82 | foreach my $index (@orig_indexes) {
|
---|
| 83 | $index =~ s/([:,])ex\./$1/g;
|
---|
| 84 | push (@{$self->{'collect_cfg'}->{'indexes'}}, $index);
|
---|
| 85 | }
|
---|
[4] | 86 | }
|
---|
| 87 |
|
---|
[12910] | 88 | sub generate_index_options {
|
---|
| 89 | my $self = shift (@_);
|
---|
[17110] | 90 | $self->SUPER::generate_index_options();
|
---|
| 91 |
|
---|
[12910] | 92 | $self->{'casefold'} = 0;
|
---|
| 93 | $self->{'stem'} = 0;
|
---|
| 94 | $self->{'accentfold'} = 0; #not yet implemented for mg
|
---|
| 95 |
|
---|
| 96 | if (!defined($self->{'collect_cfg'}->{'indexoptions'})) {
|
---|
| 97 | # just use default options
|
---|
| 98 | $self->{'casefold'} = 1;
|
---|
| 99 | $self->{'stem'} = 1;
|
---|
[17110] | 100 |
|
---|
[12910] | 101 | } else {
|
---|
| 102 | foreach my $option (@{$self->{'collect_cfg'}->{'indexoptions'}}) {
|
---|
| 103 | if ($option =~ /stem/) {
|
---|
| 104 | $self->{'stem'} = 1;
|
---|
| 105 | } elsif ($option =~ /casefold/) {
|
---|
| 106 | $self->{'casefold'} = 1;
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | # now we record this for the build cfg
|
---|
| 112 | $self->{'stemindexes'} = 0;
|
---|
| 113 | if ($self->{'casefold'}) {
|
---|
| 114 | $self->{'stemindexes'} += 1;
|
---|
| 115 | }
|
---|
| 116 | if ($self->{'stem'}) {
|
---|
| 117 | $self->{'stemindexes'} += 2;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[4] | 123 | sub compress_text {
|
---|
| 124 | my $self = shift (@_);
|
---|
[134] | 125 | my ($textindex) = @_;
|
---|
[4] | 126 | my $exedir = "$ENV{'GSDLHOME'}/bin/$ENV{'GSDLOS'}";
|
---|
| 127 | my $exe = &util::get_os_exe ();
|
---|
[486] | 128 | my $mg_passes_exe = &util::filename_cat($exedir, "mg_passes$exe");
|
---|
| 129 | my $mg_compression_dict_exe = &util::filename_cat($exedir, "mg_compression_dict$exe");
|
---|
[1424] | 130 | my $outhandle = $self->{'outhandle'};
|
---|
[4] | 131 |
|
---|
[12340] | 132 | my $maxnumeric = $self->{'maxnumeric'};
|
---|
[4192] | 133 |
|
---|
[4] | 134 | &util::mk_all_dir (&util::filename_cat($self->{'build_dir'}, "text"));
|
---|
[15003] | 135 |
|
---|
| 136 | my $collect_tail = &util::get_dirsep_tail($self->{'collection'});
|
---|
| 137 | my $basefilename = &util::filename_cat("text",$collect_tail);
|
---|
[4] | 138 | my $fulltextprefix = &util::filename_cat ($self->{'build_dir'}, $basefilename);
|
---|
| 139 |
|
---|
| 140 | my $osextra = "";
|
---|
| 141 | if ($ENV{'GSDLOS'} =~ /^windows$/i) {
|
---|
[3115] | 142 | $fulltextprefix =~ s@/@\\@g;
|
---|
[4] | 143 | } else {
|
---|
| 144 | $osextra = " -d /";
|
---|
| 145 | }
|
---|
| 146 |
|
---|
[1424] | 147 | print $outhandle "\n*** creating the compressed text\n" if ($self->{'verbosity'} >= 1);
|
---|
[6332] | 148 | print STDERR "<Stage name='CompressText'>\n" if $self->{'gli'};
|
---|
[4] | 149 |
|
---|
| 150 | # collect the statistics for the text
|
---|
| 151 | # -b $maxdocsize sets the maximum document size to be 12 meg
|
---|
[1424] | 152 | print $outhandle "\n collecting text statistics\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 153 | print STDERR "<Phase name='CollectTextStats'/>\n" if $self->{'gli'};
|
---|
[782] | 154 |
|
---|
| 155 | my ($handle);
|
---|
| 156 | if ($self->{'debug'}) {
|
---|
[15716] | 157 | $handle = *STDOUT;
|
---|
| 158 | }
|
---|
| 159 | else {
|
---|
[782] | 160 | if (!-e "$mg_passes_exe" ||
|
---|
[15716] | 161 | !open($handle, "| mg_passes$exe -f \"$fulltextprefix\" -b $maxdocsize -T1 -M $maxnumeric $osextra")) {
|
---|
[6407] | 162 | print STDERR "<FatalError name='NoRunMGPasses'>\n</Stage>\n" if $self->{'gli'};
|
---|
[782] | 163 | die "mgbuilder::compress_text - couldn't run $mg_passes_exe\n";
|
---|
| 164 | }
|
---|
[4] | 165 | }
|
---|
[782] | 166 |
|
---|
| 167 | $self->{'buildproc'}->set_output_handle ($handle);
|
---|
| 168 | $self->{'buildproc'}->set_mode ('text');
|
---|
| 169 | $self->{'buildproc'}->set_index ($textindex);
|
---|
| 170 | $self->{'buildproc'}->set_indexing_text (0);
|
---|
[7904] | 171 |
|
---|
| 172 |
|
---|
[2336] | 173 | if ($self->{'no_text'}) {
|
---|
| 174 | $self->{'buildproc'}->set_store_text(0);
|
---|
| 175 | } else {
|
---|
| 176 | $self->{'buildproc'}->set_store_text(1);
|
---|
| 177 | }
|
---|
[4] | 178 | $self->{'buildproc'}->reset();
|
---|
[7904] | 179 |
|
---|
[835] | 180 | &plugin::begin($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
| 181 | $self->{'buildproc'}, $self->{'maxdocs'});
|
---|
| 182 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
[16379] | 183 | "", {}, {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
|
---|
[835] | 184 | &plugin::end($self->{'pluginfo'});
|
---|
[7904] | 185 |
|
---|
[4] | 186 |
|
---|
[782] | 187 | close ($handle) unless $self->{'debug'};
|
---|
| 188 |
|
---|
[1251] | 189 | $self->print_stats();
|
---|
| 190 |
|
---|
[4] | 191 | # create the compression dictionary
|
---|
| 192 | # the compression dictionary is built by assuming the stats are from a seed
|
---|
| 193 | # dictionary (-S), if a novel word is encountered it is spelled out (-H),
|
---|
| 194 | # and the resulting dictionary must be less than 5 meg with the most frequent
|
---|
| 195 | # words being put into the dictionary first (-2 -k 5120)
|
---|
[782] | 196 | if (!$self->{'debug'}) {
|
---|
[1424] | 197 | print $outhandle "\n creating the compression dictionary\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 198 | print STDERR "<Phase name='CreatingCompress'/>\n" if $self->{'gli'};
|
---|
[782] | 199 | if (!-e "$mg_compression_dict_exe") {
|
---|
| 200 | die "mgbuilder::compress_text - couldn't run $mg_compression_dict_exe\n";
|
---|
| 201 | }
|
---|
[1679] | 202 | system ("mg_compression_dict$exe -f \"$fulltextprefix\" -S -H -2 -k 5120 $osextra");
|
---|
[782] | 203 |
|
---|
| 204 | # -b $maxdocsize sets the maximum document size to be 12 meg
|
---|
[1072] | 205 | if (!-e "$mg_passes_exe" ||
|
---|
[4192] | 206 | !open ($handle, "| mg_passes$exe -f \"$fulltextprefix\" -b $maxdocsize -T2 -M $maxnumeric $osextra")) {
|
---|
[6407] | 207 | print STDERR "<FatalError name='NoRunMGPasses'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[1072] | 208 | die "mgbuilder::compress_text - couldn't run $mg_passes_exe\n";
|
---|
[782] | 209 | }
|
---|
[4] | 210 | }
|
---|
[6332] | 211 | else {
|
---|
[6407] | 212 | print STDERR "<Phase name='SkipCreatingComp'/>\n" if $self->{'gli'};
|
---|
[6332] | 213 | }
|
---|
[4] | 214 |
|
---|
[22820] | 215 | $self->{'buildproc'}->set_output_handle ($handle);
|
---|
[782] | 216 | $self->{'buildproc'}->reset();
|
---|
[22820] | 217 |
|
---|
[4] | 218 | # compress the text
|
---|
[1424] | 219 | print $outhandle "\n compressing the text\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 220 | print STDERR "<Phase name='CompressingText'/>\n" if $self->{'gli'};
|
---|
[6332] | 221 |
|
---|
[4] | 222 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
[16379] | 223 | "", {}, {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
|
---|
[7904] | 224 |
|
---|
[782] | 225 | close ($handle) unless $self->{'debug'};
|
---|
[1251] | 226 |
|
---|
| 227 | $self->print_stats();
|
---|
[6407] | 228 | print STDERR "</Stage>\n" if $self->{'gli'};
|
---|
[4] | 229 | }
|
---|
| 230 |
|
---|
[486] | 231 |
|
---|
[4] | 232 | # creates directory names for each of the index descriptions
|
---|
| 233 | sub create_index_mapping {
|
---|
| 234 | my $self = shift (@_);
|
---|
| 235 | my ($indexes) = @_;
|
---|
| 236 |
|
---|
| 237 | my %mapping = ();
|
---|
[290] | 238 | $mapping{'indexmaporder'} = [];
|
---|
| 239 | $mapping{'subcollectionmaporder'} = [];
|
---|
| 240 | $mapping{'languagemaporder'} = [];
|
---|
[4] | 241 |
|
---|
| 242 | # dirnames is used to check for collisions. Start this off
|
---|
| 243 | # with the manditory directory names
|
---|
| 244 | my %dirnames = ('text'=>'text',
|
---|
| 245 | 'extra'=>'extra');
|
---|
[8716] | 246 | my %pnames = ('index' => {}, 'subcollection' => {}, 'languages' => {});
|
---|
| 247 | foreach my $index (@$indexes) {
|
---|
[139] | 248 | my ($level, $gran, $subcollection, $languages) = split (":", $index);
|
---|
[4] | 249 |
|
---|
[139] | 250 | # the directory name starts with the first character of the index level
|
---|
| 251 | my ($pindex) = $level =~ /^(.)/;
|
---|
[4] | 252 |
|
---|
[139] | 253 | # next comes a processed version of the index
|
---|
| 254 | $pindex .= $self->process_field ($gran);
|
---|
| 255 | $pindex = lc ($pindex);
|
---|
| 256 |
|
---|
[69] | 257 | # next comes a processed version of the subcollection if there is one.
|
---|
[139] | 258 | my $psub = $self->process_field ($subcollection);
|
---|
| 259 | $psub = lc ($psub);
|
---|
[69] | 260 |
|
---|
[139] | 261 | # next comes a processed version of the language if there is one.
|
---|
| 262 | my $plang = $self->process_field ($languages);
|
---|
| 263 | $plang = lc ($plang);
|
---|
[4] | 264 |
|
---|
[139] | 265 | my $dirname = $pindex . $psub . $plang;
|
---|
| 266 |
|
---|
| 267 | # check to be sure all index names are unique
|
---|
| 268 | while (defined ($dirnames{$dirname})) {
|
---|
| 269 | $dirname = $self->make_unique (\%pnames, $index, \$pindex, \$psub, \$plang);
|
---|
[4] | 270 | }
|
---|
[1973] | 271 | $mapping{$index} = $dirname;
|
---|
[139] | 272 |
|
---|
[290] | 273 | # store the mapping orders as well as the maps
|
---|
[1973] | 274 | # also put index, subcollection and language fields into the mapping thing -
|
---|
| 275 | # (the full index name (eg document:text:subcol:lang) is not used on
|
---|
| 276 | # the query page) -these are used for collectionmeta later on
|
---|
[290] | 277 | if (!defined $mapping{'indexmap'}{"$level:$gran"}) {
|
---|
| 278 | $mapping{'indexmap'}{"$level:$gran"} = $pindex;
|
---|
| 279 | push (@{$mapping{'indexmaporder'}}, "$level:$gran");
|
---|
[1973] | 280 | if (!defined $mapping{"$level:$gran"}) {
|
---|
| 281 | $mapping{"$level:$gran"} = $pindex;
|
---|
| 282 | }
|
---|
[290] | 283 | }
|
---|
| 284 | if ($psub =~ /\w/ && !defined ($mapping{'subcollectionmap'}{$subcollection})) {
|
---|
| 285 | $mapping{'subcollectionmap'}{$subcollection} = $psub;
|
---|
| 286 | push (@{$mapping{'subcollectionmaporder'}}, $subcollection);
|
---|
[1973] | 287 | $mapping{$subcollection} = $psub;
|
---|
[290] | 288 | }
|
---|
| 289 | if ($plang =~ /\w/ && !defined ($mapping{'languagemap'}{$languages})) {
|
---|
| 290 | $mapping{'languagemap'}{$languages} = $plang;
|
---|
[1973] | 291 | push (@{$mapping{'languagemaporder'}}, $languages);
|
---|
| 292 | $mapping{$languages} = $plang;
|
---|
[290] | 293 | }
|
---|
[4] | 294 | $dirnames{$dirname} = $index;
|
---|
[8716] | 295 | $pnames{'index'}->{$pindex} = "$level:$gran";
|
---|
| 296 | $pnames{'subcollection'}->{$psub} = $subcollection;
|
---|
| 297 | $pnames{'languages'}->{$plang} = $languages;
|
---|
[4] | 298 | }
|
---|
| 299 |
|
---|
| 300 | return \%mapping;
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 |
|
---|
[139] | 304 | sub make_unique {
|
---|
| 305 | my $self = shift (@_);
|
---|
| 306 | my ($namehash, $index, $indexref, $subref, $langref) = @_;
|
---|
| 307 | my ($level, $gran, $subcollection, $languages) = split (":", $index);
|
---|
| 308 |
|
---|
| 309 | if ($namehash->{'index'}->{$$indexref} ne "$level:$gran") {
|
---|
| 310 | $self->get_next_version ($indexref);
|
---|
| 311 | } elsif ($namehash->{'subcollection'}->{$$subref} ne $subcollection) {
|
---|
| 312 | $self->get_next_version ($subref);
|
---|
| 313 | } elsif ($namehash->{'languages'}->{$$langref} ne $languages) {
|
---|
| 314 | $self->get_next_version ($langref);
|
---|
| 315 | }
|
---|
| 316 | return "$$indexref$$subref$$langref";
|
---|
| 317 | }
|
---|
| 318 |
|
---|
[4] | 319 | sub build_index {
|
---|
| 320 | my $self = shift (@_);
|
---|
| 321 | my ($index) = @_;
|
---|
[1424] | 322 | my $outhandle = $self->{'outhandle'};
|
---|
[4] | 323 |
|
---|
| 324 | # get the full index directory path and make sure it exists
|
---|
| 325 | my $indexdir = $self->{'index_mapping'}->{$index};
|
---|
| 326 | &util::mk_all_dir (&util::filename_cat($self->{'build_dir'}, $indexdir));
|
---|
[15003] | 327 |
|
---|
| 328 | my $collect_tail = &util::get_dirsep_tail($self->{'collection'});
|
---|
[4] | 329 | my $fullindexprefix = &util::filename_cat ($self->{'build_dir'}, $indexdir,
|
---|
[15003] | 330 | $collect_tail);
|
---|
[4] | 331 | my $fulltextprefix = &util::filename_cat ($self->{'build_dir'}, "text",
|
---|
[15003] | 332 | $collect_tail);
|
---|
[4] | 333 |
|
---|
| 334 | # get any os specific stuff
|
---|
| 335 | my $exedir = "$ENV{'GSDLHOME'}/bin/$ENV{'GSDLOS'}";
|
---|
| 336 | my $exe = &util::get_os_exe ();
|
---|
[486] | 337 | my $mg_passes_exe = &util::filename_cat($exedir, "mg_passes$exe");
|
---|
| 338 | my $mg_perf_hash_build_exe =
|
---|
| 339 | &util::filename_cat($exedir, "mg_perf_hash_build$exe");
|
---|
| 340 | my $mg_weights_build_exe =
|
---|
| 341 | &util::filename_cat ($exedir, "mg_weights_build$exe");
|
---|
| 342 | my $mg_invf_dict_exe =
|
---|
| 343 | &util::filename_cat ($exedir, "mg_invf_dict$exe");
|
---|
| 344 | my $mg_stem_idx_exe =
|
---|
| 345 | &util::filename_cat ($exedir, "mg_stem_idx$exe");
|
---|
| 346 |
|
---|
[12340] | 347 | my $maxnumeric = $self->{'maxnumeric'};
|
---|
[4192] | 348 |
|
---|
[4] | 349 | my $osextra = "";
|
---|
| 350 | if ($ENV{'GSDLOS'} =~ /^windows$/i) {
|
---|
[3115] | 351 | $fullindexprefix =~ s@/@\\@g;
|
---|
[4] | 352 | } else {
|
---|
| 353 | $osextra = " -d /";
|
---|
[3115] | 354 | if ($outhandle ne "STDERR") {
|
---|
| 355 | # so mg_passes doesn't print to stderr if we redirect output
|
---|
| 356 | $osextra .= " 2>/dev/null";
|
---|
| 357 | }
|
---|
[4] | 358 | }
|
---|
| 359 |
|
---|
| 360 | # get the index level from the index description
|
---|
| 361 | # the index will be level 2 unless we are building a
|
---|
| 362 | # paragraph level index
|
---|
| 363 | my $index_level = 2;
|
---|
| 364 | $index_level = 3 if $index =~ /^paragraph/i;
|
---|
| 365 |
|
---|
[69] | 366 | # get the index expression if this index belongs
|
---|
| 367 | # to a subcollection
|
---|
| 368 | my $indexexparr = [];
|
---|
[9669] | 369 | my $langarr = [];
|
---|
[1973] | 370 | # there may be subcollection info, and language info.
|
---|
| 371 | my ($level, $fields, $subcollection, $language) = split (":", $index);
|
---|
[85] | 372 | my @subcollections = ();
|
---|
| 373 | @subcollections = split /,/, $subcollection if (defined $subcollection);
|
---|
[69] | 374 |
|
---|
[8716] | 375 | foreach my $subcollection (@subcollections) {
|
---|
[69] | 376 | if (defined ($self->{'collect_cfg'}->{'subcollection'}->{$subcollection})) {
|
---|
| 377 | push (@$indexexparr, $self->{'collect_cfg'}->{'subcollection'}->{$subcollection});
|
---|
| 378 | }
|
---|
| 379 | }
|
---|
| 380 |
|
---|
[139] | 381 | # add expressions for languages if this index belongs to
|
---|
[1973] | 382 | # a language subcollection - only put languages expressions for the
|
---|
| 383 | # ones we want in the index
|
---|
| 384 |
|
---|
| 385 | my @languages = ();
|
---|
[20418] | 386 | my $languagemetadata = "Language";
|
---|
| 387 | if (defined ($self->{'collect_cfg'}->{'languagemetadata'})) {
|
---|
| 388 | $languagemetadata = $self->{'collect_cfg'}->{'languagemetadata'};
|
---|
[9548] | 389 | }
|
---|
[1973] | 390 | @languages = split /,/, $language if (defined $language);
|
---|
[8716] | 391 | foreach my $language (@languages) {
|
---|
[1973] | 392 | my $not=0;
|
---|
[139] | 393 | if ($language =~ s/^\!//) {
|
---|
[1973] | 394 | $not = 1;
|
---|
[139] | 395 | }
|
---|
[6543] | 396 | if($not) {
|
---|
[9669] | 397 | push (@$langarr, "!$language");
|
---|
[6543] | 398 | } else {
|
---|
[9669] | 399 | push (@$langarr, "$language");
|
---|
[1973] | 400 | }
|
---|
[139] | 401 | }
|
---|
[9669] | 402 |
|
---|
[782] | 403 | # Build index dictionary. Uses verbatim stem method
|
---|
[1424] | 404 | print $outhandle "\n creating index dictionary\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 405 | print STDERR "<Phase name='CreatingIndexDic'/>\n" if $self->{'gli'};
|
---|
[782] | 406 | my ($handle);
|
---|
| 407 | if ($self->{'debug'}) {
|
---|
[15716] | 408 | $handle = *STDOUT;
|
---|
| 409 | }
|
---|
| 410 | else {
|
---|
[782] | 411 | if (!-e "$mg_passes_exe" ||
|
---|
[15716] | 412 | !open($handle, "| mg_passes$exe -f \"$fullindexprefix\" -b $maxdocsize " .
|
---|
[4192] | 413 | "-$index_level -m 32 -s 0 -G -t 10 -N1 -M $maxnumeric $osextra")) {
|
---|
[6407] | 414 | print STDERR "<FatalError name='NoRunMGPasses'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[782] | 415 | die "mgbuilder::build_index - couldn't run $mg_passes_exe\n";
|
---|
| 416 | }
|
---|
| 417 | }
|
---|
| 418 |
|
---|
[4] | 419 | # set up the document processor
|
---|
[782] | 420 | $self->{'buildproc'}->set_output_handle ($handle);
|
---|
[4] | 421 | $self->{'buildproc'}->set_mode ('text');
|
---|
[69] | 422 | $self->{'buildproc'}->set_index ($index, $indexexparr);
|
---|
[20418] | 423 | $self->{'buildproc'}->set_index_languages ($languagemetadata, $langarr) if (defined $language);
|
---|
[292] | 424 | $self->{'buildproc'}->set_indexing_text (1);
|
---|
[2336] | 425 | $self->{'buildproc'}->set_store_text(1);
|
---|
[4] | 426 |
|
---|
| 427 | $self->{'buildproc'}->reset();
|
---|
| 428 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
[16379] | 429 | "", {}, {}, $self->{'buildproc'}, $self->{'maxdocs'},0, $self->{'gli'});
|
---|
[782] | 430 | close ($handle) unless $self->{'debug'};
|
---|
[4] | 431 |
|
---|
[1251] | 432 | $self->print_stats();
|
---|
| 433 |
|
---|
[5768] | 434 | # now we check to see if the required files have been produced - if not we quit building this index so the whole process doesn't crap out.
|
---|
| 435 | # we check on the .id file - index dictionary
|
---|
| 436 | my $dict_file = "$fullindexprefix.id";
|
---|
| 437 | if (!-e $dict_file) {
|
---|
| 438 | print $outhandle "mgbuilder::build_index - Couldn't create index $index\n";
|
---|
| 439 | $self->{'notbuilt'}->{$index}=1;
|
---|
| 440 | return;
|
---|
| 441 | }
|
---|
[782] | 442 | if (!$self->{'debug'}) {
|
---|
| 443 | # create the perfect hash function
|
---|
| 444 | if (!-e "$mg_perf_hash_build_exe") {
|
---|
[6407] | 445 | print STDERR "<FatalError name='NoRunMGHash'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[782] | 446 | die "mgbuilder::build_index - couldn't run $mg_perf_hash_build_exe\n";
|
---|
| 447 | }
|
---|
[1679] | 448 | system ("mg_perf_hash_build$exe -f \"$fullindexprefix\" $osextra");
|
---|
[782] | 449 |
|
---|
| 450 | if (!-e "$mg_passes_exe" ||
|
---|
[1679] | 451 | !open ($handle, "| mg_passes$exe -f \"$fullindexprefix\" -b $maxdocsize " .
|
---|
[4192] | 452 | "-$index_level -c 3 -G -t 10 -N2 -M $maxnumeric $osextra")) {
|
---|
[6407] | 453 | print STDERR "<FatalError name='NoRunMGPasses'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[782] | 454 | die "mgbuilder::build_index - couldn't run $mg_passes_exe\n";
|
---|
| 455 | }
|
---|
[4] | 456 | }
|
---|
[782] | 457 |
|
---|
[4] | 458 | # invert the text
|
---|
[1424] | 459 | print $outhandle "\n inverting the text\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 460 | print STDERR "<Phase name='InvertingText'/>\n" if $self->{'gli'};
|
---|
[22820] | 461 |
|
---|
| 462 | $self->{'buildproc'}->set_output_handle ($handle);
|
---|
[4] | 463 | $self->{'buildproc'}->reset();
|
---|
[22820] | 464 |
|
---|
[4] | 465 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
[16379] | 466 | "", {}, {}, $self->{'buildproc'}, $self->{'maxdocs'},0, $self->{'gli'});
|
---|
[1304] | 467 |
|
---|
[7904] | 468 |
|
---|
[1251] | 469 | $self->print_stats ();
|
---|
| 470 |
|
---|
[782] | 471 | if (!$self->{'debug'}) {
|
---|
[4] | 472 |
|
---|
[782] | 473 | close ($handle);
|
---|
| 474 |
|
---|
| 475 | # create the weights file
|
---|
[1424] | 476 | print $outhandle "\n create the weights file\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 477 | print STDERR "<Phase name='CreateTheWeights'/>\n" if $self->{'gli'};
|
---|
[782] | 478 | if (!-e "$mg_weights_build_exe") {
|
---|
[6407] | 479 | print STDERR "<FatalError name='NoRunMGWeights'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[782] | 480 | die "mgbuilder::build_index - couldn't run $mg_weights_build_exe\n";
|
---|
| 481 | }
|
---|
[1679] | 482 | system ("mg_weights_build$exe -f \"$fullindexprefix\" -t \"$fulltextprefix\" $osextra");
|
---|
[4] | 483 |
|
---|
[782] | 484 | # create 'on-disk' stemmed dictionary
|
---|
[1424] | 485 | print $outhandle "\n creating 'on-disk' stemmed dictionary\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 486 | print STDERR "<Phase name='CreateStemmedDic'/>\n" if $self->{'gli'};
|
---|
[782] | 487 | if (!-e "$mg_invf_dict_exe") {
|
---|
[6407] | 488 | print STDERR "<FatalError name='NoRunMGInvf'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[782] | 489 | die "mgbuilder::build_index - couldn't run $mg_invf_dict_exe\n";
|
---|
| 490 | }
|
---|
[1679] | 491 | system ("mg_invf_dict$exe -f \"$fullindexprefix\" $osextra");
|
---|
[4] | 492 |
|
---|
| 493 |
|
---|
[782] | 494 | # creates stem index files for the various stemming methods
|
---|
[1424] | 495 | print $outhandle "\n creating stem indexes\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 496 | print STDERR "<Phase name='CreatingStemIndx'/>\n" if $self->{'gli'};
|
---|
[782] | 497 | if (!-e "$mg_stem_idx_exe") {
|
---|
[6407] | 498 | print STDERR "<FatalError name='NoRunMGStem'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[782] | 499 | die "mgbuilder::build_index - couldn't run $mg_stem_idx_exe\n";
|
---|
| 500 | }
|
---|
[12910] | 501 | # currently mg wont work if we don't generate all the stem idexes
|
---|
| 502 | # so we generate them whatever, but don't advertise the fact
|
---|
| 503 | #if ($self->{'casefold'}) {
|
---|
[12971] | 504 | system ("mg_stem_idx$exe -b 4096 -s1 -f \"$fullindexprefix\" $osextra");
|
---|
[12910] | 505 | #}
|
---|
| 506 | #if ($self->{'stem'}) {
|
---|
[12971] | 507 | system ("mg_stem_idx$exe -b 4096 -s2 -f \"$fullindexprefix\" $osextra");
|
---|
[12910] | 508 | #}
|
---|
| 509 | #if ($self->{'casefold'} && $self->{'stem'}) {
|
---|
[12971] | 510 | system ("mg_stem_idx$exe -b 4096 -s3 -f \"$fullindexprefix\" $osextra");
|
---|
[12910] | 511 | #}
|
---|
| 512 |
|
---|
[782] | 513 | # remove unwanted files
|
---|
| 514 | my $tmpdir = &util::filename_cat ($self->{'build_dir'}, $indexdir);
|
---|
| 515 | opendir (DIR, $tmpdir) || die
|
---|
| 516 | "mgbuilder::build_index - couldn't read directory $tmpdir\n";
|
---|
[8716] | 517 | foreach my $file (readdir(DIR)) {
|
---|
[782] | 518 | next if $file =~ /^\./;
|
---|
| 519 | my ($suffix) = $file =~ /\.([^\.]+)$/;
|
---|
| 520 | if (defined $suffix && !defined $wanted_index_files{$suffix}) {
|
---|
| 521 | # delete it!
|
---|
[1424] | 522 | print $outhandle "deleting $file\n" if $self->{'verbosity'} > 2;
|
---|
[782] | 523 | &util::rm (&util::filename_cat ($tmpdir, $file));
|
---|
| 524 | }
|
---|
[4] | 525 | }
|
---|
[782] | 526 | closedir (DIR);
|
---|
[4] | 527 | }
|
---|
[6407] | 528 | print STDERR "</Stage>\n" if $self->{'gli'};
|
---|
[4] | 529 | }
|
---|
| 530 |
|
---|
[10468] | 531 | sub build_cfg_extra {
|
---|
| 532 | my $self = shift(@_);
|
---|
| 533 | my ($build_cfg) = @_;
|
---|
[2506] | 534 |
|
---|
[1252] | 535 | # get additional stats from mg
|
---|
| 536 | my $exedir = "$ENV{'GSDLHOME'}/bin/$ENV{'GSDLOS'}";
|
---|
| 537 | my $exe = &util::get_os_exe ();
|
---|
| 538 | my $mgstat_exe = &util::filename_cat($exedir, "mgstat$exe");
|
---|
[15003] | 539 |
|
---|
| 540 | my $collect_tail = &util::get_dirsep_tail($self->{'collection'});
|
---|
| 541 | my $input_file = &util::filename_cat ("text", $collect_tail);
|
---|
[1679] | 542 | if (!-e "$mgstat_exe" || !open (PIPEIN, "mgstat$exe -d \"$self->{'build_dir'}\" -f \"$input_file\" |")) {
|
---|
[15716] | 543 | my $outhandle = $self->{'outhandle'};
|
---|
[1424] | 544 | print $outhandle "Warning: Couldn't open pipe to $mgstat_exe to get additional stats\n";
|
---|
[1252] | 545 | } else {
|
---|
| 546 | my $line = "";
|
---|
| 547 | while (defined ($line = <PIPEIN>)) {
|
---|
| 548 | if ($line =~ /^Words in collection \[dict\]\s+:\s+(\d+)/) {
|
---|
| 549 | ($build_cfg->{'numwords'}) = $1;
|
---|
| 550 | } elsif ($line =~ /^Documents\s+:\s+(\d+)/) {
|
---|
| 551 | ($build_cfg->{'numsections'}) = $1;
|
---|
| 552 | }
|
---|
| 553 | }
|
---|
| 554 | close PIPEIN;
|
---|
| 555 | }
|
---|
[4] | 556 | }
|
---|
| 557 |
|
---|
| 558 | 1;
|
---|
[7904] | 559 |
|
---|
| 560 |
|
---|
| 561 |
|
---|