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