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