[14930] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # basebuilder.pm -- base class for collection builders
|
---|
| 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 |
|
---|
| 26 | package basebuilder;
|
---|
| 27 |
|
---|
| 28 | use strict;
|
---|
| 29 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
| 30 |
|
---|
| 31 | use classify;
|
---|
| 32 | use cfgread;
|
---|
| 33 | use colcfg;
|
---|
[15709] | 34 | use dbutil;
|
---|
[14930] | 35 | use plugin;
|
---|
| 36 | use util;
|
---|
| 37 |
|
---|
[15709] | 38 |
|
---|
[14930] | 39 | BEGIN {
|
---|
| 40 | # set autoflush on for STDERR and STDOUT so that mgpp
|
---|
| 41 | # doesn't get out of sync with plugins
|
---|
| 42 | STDOUT->autoflush(1);
|
---|
| 43 | STDERR->autoflush(1);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | END {
|
---|
| 47 | STDOUT->autoflush(0);
|
---|
| 48 | STDERR->autoflush(0);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | our $maxdocsize = 12000;
|
---|
| 52 |
|
---|
| 53 | # used to signify "gs2"(default) or "gs3"
|
---|
| 54 | my $gs_mode = "gs2";
|
---|
| 55 |
|
---|
| 56 | sub new {
|
---|
| 57 | my ($class, $collection, $source_dir, $build_dir, $verbosity,
|
---|
| 58 | $maxdocs, $debug, $keepold, $incremental, $incremental_dlc,
|
---|
| 59 | $remove_empty_classifications,
|
---|
| 60 | $outhandle, $no_text, $failhandle, $gli, $disable_OAI) = @_;
|
---|
| 61 |
|
---|
| 62 | $outhandle = *STDERR unless defined $outhandle;
|
---|
| 63 | $no_text = 0 unless defined $no_text;
|
---|
| 64 | $failhandle = *STDERR unless defined $failhandle;
|
---|
| 65 |
|
---|
| 66 | # create a builder object
|
---|
| 67 | my $self = bless {'collection'=>$collection,
|
---|
| 68 | 'source_dir'=>$source_dir,
|
---|
| 69 | 'build_dir'=>$build_dir,
|
---|
| 70 | 'verbosity'=>$verbosity,
|
---|
| 71 | 'maxdocs'=>$maxdocs,
|
---|
| 72 | 'debug'=>$debug,
|
---|
| 73 | 'keepold'=>$keepold,
|
---|
| 74 | 'incremental'=>$incremental,
|
---|
| 75 | 'incremental_dlc' => $incremental_dlc,
|
---|
| 76 | 'remove_empty_classifications'=>$remove_empty_classifications,
|
---|
| 77 | 'outhandle'=>$outhandle,
|
---|
| 78 | 'no_text'=>$no_text,
|
---|
| 79 | 'failhandle'=>$failhandle,
|
---|
| 80 | 'notbuilt'=>{}, # indexes not built
|
---|
| 81 | 'gli'=>$gli,
|
---|
| 82 | 'disable_OAI'=>$disable_OAI
|
---|
| 83 | }, $class;
|
---|
| 84 |
|
---|
| 85 | $self->{'gli'} = 0 unless defined $self->{'gli'};
|
---|
| 86 |
|
---|
| 87 | # disable_OIA applies to greenstone 3 only and is only passed to &colcfg::write_build_cfg_xml (then cfgread4gs3::write_cfg_file) when writing the buildConfig.xml
|
---|
| 88 | $self->{'disable_OAI'} = 0 unless defined $self->{'disable_OAI'};
|
---|
| 89 |
|
---|
| 90 | # Read in the collection configuration file.
|
---|
| 91 | my ($colcfgname);
|
---|
| 92 | ($colcfgname, $gs_mode) = &colcfg::get_collect_cfg_name($outhandle);
|
---|
| 93 | if ($gs_mode eq "gs2") {
|
---|
| 94 | $self->{'collect_cfg'} = &colcfg::read_collect_cfg ($colcfgname);
|
---|
| 95 | } elsif ($gs_mode eq "gs3") {
|
---|
[14384] | 96 | $self->{'collect_cfg'} = &colcfg::read_collection_cfg_xml ($colcfgname);
|
---|
| 97 |
|
---|
[14668] | 98 | #this $self->{'collect_cfg_preserve'} is used for gs3 only and to be passed to &colcfg::write_build_cfg_xml in sub make_auxilary_files later in this basebuilder.pm, we use this preserve object because $self->{'collect_cfg'}->{'classify'} somewhat gets modified during the calling of &classify::load_classifiers.
|
---|
| 99 | $self->{'collect_cfg_preserve'} = &colcfg::read_collection_cfg_xml ($colcfgname);
|
---|
[14930] | 100 | }
|
---|
| 101 |
|
---|
| 102 | # get the list of plugins for this collection
|
---|
| 103 | my $plugins = [];
|
---|
| 104 | if (defined $self->{'collect_cfg'}->{'plugin'}) {
|
---|
| 105 | $plugins = $self->{'collect_cfg'}->{'plugin'};
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | # load all the plugins
|
---|
[14384] | 109 |
|
---|
[14930] | 110 | #build up the extra global options for the plugins
|
---|
| 111 | my @global_opts = ();
|
---|
| 112 | if (defined $self->{'collect_cfg'}->{'separate_cjk'} && $self->{'collect_cfg'}->{'separate_cjk'} =~ /^true$/i) {
|
---|
| 113 | push @global_opts, "-separate_cjk";
|
---|
[14384] | 114 | }
|
---|
[14930] | 115 | $self->{'pluginfo'} = &plugin::load_plugins ($plugins, $verbosity, $outhandle, $failhandle, \@global_opts, $keepold);
|
---|
| 116 |
|
---|
| 117 | if (scalar(@{$self->{'pluginfo'}}) == 0) {
|
---|
| 118 | print $outhandle "No plugins were loaded.\n";
|
---|
| 119 | die "\n";
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | # get the list of classifiers for this collection
|
---|
| 123 | my $classifiers = [];
|
---|
| 124 | if (defined $self->{'collect_cfg'}->{'classify'}) {
|
---|
| 125 | $classifiers = $self->{'collect_cfg'}->{'classify'};
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | # load all the classifiers
|
---|
[14384] | 129 | $self->{'classifiers'} = &classify::load_classifiers ($classifiers, $build_dir, $outhandle);
|
---|
[14930] | 130 |
|
---|
[15688] | 131 | # load up any dontdb fields
|
---|
| 132 | $self->{'dontdb'} = {};
|
---|
[14930] | 133 | if (defined ($self->{'collect_cfg'}->{'dontgdbm'})) {
|
---|
| 134 | foreach my $dg (@{$self->{'collect_cfg'}->{'dontgdbm'}}) {
|
---|
[15688] | 135 | $self->{'dontdb'}->{$dg} = 1;
|
---|
[14930] | 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | $self->{'maxnumeric'} = 4;
|
---|
| 140 | return $self;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | # stuff has been moved here from new, so we can use subclass methods
|
---|
| 144 | sub init {
|
---|
| 145 | my $self = shift(@_);
|
---|
| 146 |
|
---|
| 147 | $self->generate_index_list();
|
---|
| 148 | $self->generate_index_options();
|
---|
| 149 |
|
---|
| 150 | # sort out subcollection indexes
|
---|
| 151 | if (defined $self->{'collect_cfg'}->{'indexsubcollections'}) {
|
---|
| 152 | my $indexes = $self->{'collect_cfg'}->{'indexes'};
|
---|
| 153 | $self->{'collect_cfg'}->{'indexes'} = [];
|
---|
| 154 | foreach my $subcollection (@{$self->{'collect_cfg'}->{'indexsubcollections'}}) {
|
---|
| 155 | foreach my $index (@$indexes) {
|
---|
| 156 | push (@{$self->{'collect_cfg'}->{'indexes'}}, "$index:$subcollection");
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | # sort out language subindexes
|
---|
| 162 | if (defined $self->{'collect_cfg'}->{'languages'}) {
|
---|
| 163 | my $indexes = $self->{'collect_cfg'}->{'indexes'};
|
---|
| 164 | $self->{'collect_cfg'}->{'indexes'} = [];
|
---|
| 165 | foreach my $language (@{$self->{'collect_cfg'}->{'languages'}}) {
|
---|
| 166 | foreach my $index (@$indexes) {
|
---|
| 167 | if (defined ($self->{'collect_cfg'}->{'indexsubcollections'})) {
|
---|
| 168 | push (@{$self->{'collect_cfg'}->{'indexes'}}, "$index:$language");
|
---|
| 169 | }
|
---|
| 170 | else { # add in an empty subcollection field
|
---|
| 171 | push (@{$self->{'collect_cfg'}->{'indexes'}}, "$index\:\:$language");
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | if (defined($self->{'collect_cfg'}->{'indexes'})) {
|
---|
| 178 | # make sure that the same index isn't specified more than once
|
---|
| 179 | my %tmphash = ();
|
---|
| 180 | my @tmparray = @{$self->{'collect_cfg'}->{'indexes'}};
|
---|
| 181 | $self->{'collect_cfg'}->{'indexes'} = [];
|
---|
| 182 | foreach my $i (@tmparray) {
|
---|
| 183 | if (!defined ($tmphash{$i})) {
|
---|
| 184 | push (@{$self->{'collect_cfg'}->{'indexes'}}, $i);
|
---|
| 185 | $tmphash{$i} = 1;
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
| 188 | } else {
|
---|
| 189 | $self->{'collect_cfg'}->{'indexes'} = [];
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | # load up the document processor for building
|
---|
| 193 | # if a buildproc class has been created for this collection, use it
|
---|
| 194 | # otherwise, use the mg buildproc
|
---|
| 195 | my ($buildprocdir, $buildproctype);
|
---|
| 196 | my $collection = $self->{'collection'};
|
---|
| 197 | if (-e "$ENV{'GSDLCOLLECTDIR'}/custom/${collection}/perllib/custombuildproc.pm") {
|
---|
| 198 | $buildprocdir = "$ENV{'GSDLCOLLECTDIR'}/custom/${collection}/perllib";
|
---|
| 199 | $buildproctype = "custombuildproc";
|
---|
| 200 | } elsif (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/custombuildproc.pm") {
|
---|
| 201 | $buildprocdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
|
---|
| 202 | $buildproctype = "custombuildproc";
|
---|
| 203 | } elsif (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/${collection}buildproc.pm") {
|
---|
| 204 | $buildprocdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
|
---|
| 205 | $buildproctype = "${collection}buildproc";
|
---|
| 206 | } else {
|
---|
| 207 | $buildprocdir = "$ENV{'GSDLHOME'}/perllib";
|
---|
| 208 | $buildproctype = $self->default_buildproc();
|
---|
| 209 | }
|
---|
| 210 | require "$buildprocdir/$buildproctype.pm";
|
---|
| 211 |
|
---|
| 212 | eval("\$self->{'buildproc'} = new $buildproctype(\$self->{'collection'}, " .
|
---|
| 213 | "\$self->{'source_dir'}, \$self->{'build_dir'}, \$self->{'keepold'}, \$self->{'verbosity'}, \$self->{'outhandle'})");
|
---|
| 214 | die "$@" if $@;
|
---|
| 215 |
|
---|
| 216 | if (!$self->{'debug'} && !$self->{'keepold'}) {
|
---|
| 217 | # remove any old builds
|
---|
| 218 | &util::rm_r($self->{'build_dir'});
|
---|
| 219 | &util::mk_all_dir($self->{'build_dir'});
|
---|
| 220 |
|
---|
| 221 | # make the text directory
|
---|
| 222 | my $textdir = "$self->{'build_dir'}/text";
|
---|
| 223 | &util::mk_all_dir($textdir);
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | sub deinit {
|
---|
| 229 | my $self = shift (@_);
|
---|
| 230 |
|
---|
| 231 | &plugin::deinit($self->{'pluginfo'},$self->{'buildproc'});
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | sub set_sections_index_document_metadata {
|
---|
| 235 | my $self = shift (@_);
|
---|
| 236 | my ($index) = @_;
|
---|
| 237 |
|
---|
| 238 | $self->{'buildproc'}->set_sections_index_document_metadata($index);
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | sub set_maxnumeric {
|
---|
| 242 | my $self = shift (@_);
|
---|
| 243 | my ($maxnumeric) = @_;
|
---|
| 244 |
|
---|
| 245 | $self->{'maxnumeric'} = $maxnumeric;
|
---|
| 246 | }
|
---|
| 247 | sub set_strip_html {
|
---|
| 248 | my $self = shift (@_);
|
---|
| 249 | my ($strip) = @_;
|
---|
| 250 |
|
---|
| 251 | $self->{'strip_html'} = $strip;
|
---|
| 252 | $self->{'buildproc'}->set_strip_html($strip);
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | sub compress_text {
|
---|
| 256 | my $self = shift (@_);
|
---|
| 257 | my ($textindex) = @_;
|
---|
| 258 |
|
---|
| 259 | print STDERR "compress_text() should be implemented in subclass!!";
|
---|
| 260 | return;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 |
|
---|
| 264 | sub build_indexes {
|
---|
| 265 | my $self = shift (@_);
|
---|
| 266 | my ($indexname) = @_;
|
---|
| 267 | my $outhandle = $self->{'outhandle'};
|
---|
| 268 |
|
---|
| 269 | my $indexes = [];
|
---|
| 270 | if (defined $indexname && $indexname =~ /\w/) {
|
---|
| 271 | push @$indexes, $indexname;
|
---|
| 272 | } else {
|
---|
| 273 | $indexes = $self->{'collect_cfg'}->{'indexes'};
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | # create the mapping between the index descriptions
|
---|
| 277 | # and their directory names (includes subcolls and langs)
|
---|
| 278 | $self->{'index_mapping'} = $self->create_index_mapping ($indexes);
|
---|
| 279 |
|
---|
| 280 | # build each of the indexes
|
---|
| 281 | foreach my $index (@$indexes) {
|
---|
| 282 | if ($self->want_built($index)) {
|
---|
| 283 | print $outhandle "\n*** building index $index in subdirectory " .
|
---|
| 284 | "$self->{'index_mapping'}->{$index}\n" if ($self->{'verbosity'} >= 1);
|
---|
| 285 | print STDERR "<Stage name='Index' source='$index'>\n" if $self->{'gli'};
|
---|
| 286 | $self->build_index($index);
|
---|
| 287 | } else {
|
---|
| 288 | print $outhandle "\n*** ignoring index $index\n" if ($self->{'verbosity'} >= 1);
|
---|
| 289 | }
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | $self->build_indexes_extra();
|
---|
| 293 |
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | sub build_indexes_extra {
|
---|
| 297 | my $self = shift(@_);
|
---|
| 298 |
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | sub build_index {
|
---|
| 302 | my $self = shift (@_);
|
---|
| 303 | my ($index) = @_;
|
---|
| 304 |
|
---|
| 305 | print STDERR "build_index should be implemented in subclass\n";
|
---|
| 306 | return;
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 |
|
---|
| 310 |
|
---|
| 311 | sub make_infodatabase {
|
---|
| 312 | my $self = shift (@_);
|
---|
| 313 | my $outhandle = $self->{'outhandle'};
|
---|
| 314 |
|
---|
| 315 | print STDERR "BuildDir: $self->{'build_dir'}\n";
|
---|
| 316 |
|
---|
| 317 | my $textdir = &util::filename_cat($self->{'build_dir'}, "text");
|
---|
| 318 | my $assocdir = &util::filename_cat($self->{'build_dir'}, "assoc");
|
---|
| 319 | &util::mk_all_dir ($textdir);
|
---|
| 320 | &util::mk_all_dir ($assocdir);
|
---|
| 321 |
|
---|
[15710] | 322 | # Get info database file path
|
---|
| 323 | my $infodb_file_path = &dbutil::get_infodb_file_path($self->{'collection'}, $textdir);
|
---|
[14930] | 324 |
|
---|
| 325 | print $outhandle "\n*** creating the info database and processing associated files\n"
|
---|
| 326 | if ($self->{'verbosity'} >= 1);
|
---|
| 327 | print STDERR "<Stage name='CreateInfoData'>\n" if $self->{'gli'};
|
---|
| 328 |
|
---|
| 329 | # init all the classifiers
|
---|
| 330 | &classify::init_classifiers ($self->{'classifiers'});
|
---|
| 331 |
|
---|
| 332 | my $reconstructed_docs = undef;
|
---|
| 333 | if ($self->{'keepold'}) {
|
---|
[15688] | 334 | # reconstruct doc_obj metadata from database for all docs
|
---|
[15710] | 335 | $reconstructed_docs = &classify::reconstruct_doc_objs_metadata($infodb_file_path);
|
---|
[14930] | 336 | }
|
---|
| 337 |
|
---|
| 338 | # set up the document processor
|
---|
[15700] | 339 | my ($infodb_handle);
|
---|
[14930] | 340 | if ($self->{'debug'}) {
|
---|
[15700] | 341 | $infodb_handle = *STDOUT;
|
---|
[15710] | 342 | }
|
---|
| 343 | else {
|
---|
[15711] | 344 | $infodb_handle = &dbutil::open_infodb_write_handle($infodb_file_path);
|
---|
| 345 | if (!defined($infodb_handle))
|
---|
| 346 | {
|
---|
[14930] | 347 | print STDERR "<FatalError name='NoRunText2DB'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[15711] | 348 | die "builder::make_infodatabase - couldn't open infodb write handle\n";
|
---|
[14930] | 349 | }
|
---|
| 350 | }
|
---|
| 351 |
|
---|
[15700] | 352 | $self->{'buildproc'}->set_output_handle ($infodb_handle);
|
---|
[14930] | 353 | $self->{'buildproc'}->set_mode ('infodb');
|
---|
| 354 | $self->{'buildproc'}->set_assocdir ($assocdir);
|
---|
[15688] | 355 | $self->{'buildproc'}->set_dontdb ($self->{'dontdb'});
|
---|
[14930] | 356 | $self->{'buildproc'}->set_classifiers ($self->{'classifiers'});
|
---|
| 357 | $self->{'buildproc'}->set_indexing_text (0);
|
---|
| 358 | $self->{'buildproc'}->set_store_text(1);
|
---|
| 359 |
|
---|
| 360 | # make_infodatabase needs full reset even for incremental build
|
---|
[15688] | 361 | # as incremental works by reconstructing all docs from the database and
|
---|
[14930] | 362 | # then adding in the new ones
|
---|
| 363 | $self->{'buildproc'}->zero_reset();
|
---|
| 364 |
|
---|
[14934] | 365 | $self->{'buildproc'}->{'mdprefix_fields'} = {};
|
---|
| 366 |
|
---|
[14930] | 367 | if ($self->{'keepold'}) {
|
---|
| 368 | # create flat classify structure, ready for new docs to be added
|
---|
| 369 | foreach my $doc_obj ( @$reconstructed_docs ) {
|
---|
| 370 | print $outhandle " Adding reconstructed ", $doc_obj->get_OID(), " into classify structures\n";
|
---|
| 371 | $self->{'buildproc'}->process($doc_obj,undef);
|
---|
| 372 | }
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 |
|
---|
[14934] | 376 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
| 377 | "", {}, $self->{'buildproc'}, $self->{'maxdocs'},0, $self->{'gli'});
|
---|
| 378 |
|
---|
[14930] | 379 | # this has changed to only output collection meta if its
|
---|
| 380 | # not in the config file
|
---|
[15700] | 381 | $self->output_collection_meta($infodb_handle);
|
---|
[14930] | 382 |
|
---|
| 383 | # output classification information
|
---|
[15700] | 384 | &classify::output_classify_info ($self->{'classifiers'}, $infodb_handle,
|
---|
[14930] | 385 | $self->{'remove_empty_classifications'},
|
---|
| 386 | $self->{'gli'});
|
---|
| 387 |
|
---|
| 388 | # Output classifier reverse lookup, used in incremental deletion
|
---|
[15700] | 389 | #&classify::print_reverse_lookup($infodb_handle);
|
---|
[14930] | 390 |
|
---|
[15700] | 391 | # output doclist
|
---|
| 392 | my @doc_list = $self->{'buildproc'}->get_doc_list();
|
---|
| 393 | &dbutil::write_infodb_entry($infodb_handle, "browselist", { 'hastxt' => [ "0" ],
|
---|
| 394 | 'childtype' => [ "VList" ],
|
---|
| 395 | 'numleafdocs' => [ scalar(@doc_list) ],
|
---|
| 396 | 'thistype' => [ "Invisible" ],
|
---|
| 397 | 'contains' => [ join(";", @doc_list) ] });
|
---|
[14930] | 398 |
|
---|
[15700] | 399 | close ($infodb_handle) if !$self->{'debug'};
|
---|
[14930] | 400 |
|
---|
| 401 | print STDERR "</Stage>\n" if $self->{'gli'};
|
---|
| 402 | }
|
---|
| 403 |
|
---|
| 404 | sub make_auxiliary_files {
|
---|
| 405 | my $self = shift (@_);
|
---|
| 406 | my ($index);
|
---|
| 407 | my $build_cfg = {};
|
---|
| 408 | # subclasses may have already defined stuff in here
|
---|
| 409 | if (defined $self->{'build_cfg'}) {
|
---|
| 410 | $build_cfg = $self->{'build_cfg'};
|
---|
| 411 | }
|
---|
| 412 |
|
---|
| 413 | my $outhandle = $self->{'outhandle'};
|
---|
| 414 |
|
---|
| 415 | print $outhandle "\n*** creating auxiliary files \n" if ($self->{'verbosity'} >= 1);
|
---|
| 416 | print STDERR "<Stage name='CreatingAuxilary'>\n" if $self->{'gli'};
|
---|
| 417 |
|
---|
| 418 | # get the text directory
|
---|
| 419 | &util::mk_all_dir ($self->{'build_dir'});
|
---|
| 420 |
|
---|
| 421 | # store the build date
|
---|
| 422 | $build_cfg->{'builddate'} = time;
|
---|
| 423 | $build_cfg->{'buildtype'} = $self->{'buildtype'};
|
---|
[15003] | 424 | $build_cfg->{'indexstem'} = &util::get_dirsep_tail($self->{'collection'});
|
---|
[14930] | 425 | $build_cfg->{'stemindexes'} = $self->{'stemindexes'};
|
---|
| 426 |
|
---|
| 427 | # store the number of documents and number of bytes
|
---|
| 428 | $build_cfg->{'numdocs'} = $self->{'buildproc'}->get_num_docs();
|
---|
| 429 | $build_cfg->{'numsections'} = $self->{'buildproc'}->get_num_sections();
|
---|
| 430 | $build_cfg->{'numbytes'} = $self->{'buildproc'}->get_num_bytes();
|
---|
| 431 |
|
---|
| 432 | # store the mapping between the index names and the directory names
|
---|
| 433 | # the index map is used to determine what indexes there are, so any that are not built should not be put into the map.
|
---|
| 434 | my @indexmap = ();
|
---|
| 435 | foreach my $index (@{$self->{'index_mapping'}->{'indexmaporder'}}) {
|
---|
| 436 | if (not defined ($self->{'notbuilt'}->{$index})) {
|
---|
| 437 | push (@indexmap, "$index\-\>$self->{'index_mapping'}->{'indexmap'}->{$index}");
|
---|
| 438 | }
|
---|
| 439 | }
|
---|
| 440 | $build_cfg->{'indexmap'} = \@indexmap if scalar (@indexmap);
|
---|
| 441 |
|
---|
| 442 | my @subcollectionmap = ();
|
---|
| 443 | foreach my $subcollection (@{$self->{'index_mapping'}->{'subcollectionmaporder'}}) {
|
---|
| 444 | push (@subcollectionmap, "$subcollection\-\>" .
|
---|
| 445 | $self->{'index_mapping'}->{'subcollectionmap'}->{$subcollection});
|
---|
| 446 | }
|
---|
| 447 | $build_cfg->{'subcollectionmap'} = \@subcollectionmap if scalar (@subcollectionmap);
|
---|
| 448 |
|
---|
| 449 | my @languagemap = ();
|
---|
| 450 | foreach my $language (@{$self->{'index_mapping'}->{'languagemaporder'}}) {
|
---|
| 451 | push (@languagemap, "$language\-\>" .
|
---|
| 452 | $self->{'index_mapping'}->{'languagemap'}->{$language});
|
---|
| 453 | }
|
---|
| 454 | $build_cfg->{'languagemap'} = \@languagemap if scalar (@languagemap);
|
---|
| 455 |
|
---|
| 456 | my @notbuilt = ();
|
---|
| 457 | foreach my $nb (keys %{$self->{'notbuilt'}}) {
|
---|
| 458 | push (@notbuilt, $nb);
|
---|
| 459 | }
|
---|
| 460 | $build_cfg->{'notbuilt'} = \@notbuilt if scalar (@notbuilt);
|
---|
| 461 |
|
---|
| 462 | $build_cfg->{'maxnumeric'} = $self->{'maxnumeric'};
|
---|
| 463 |
|
---|
| 464 | $self->build_cfg_extra($build_cfg);
|
---|
| 465 |
|
---|
| 466 | if ($gs_mode eq "gs2") {
|
---|
| 467 | &colcfg::write_build_cfg("$self->{'build_dir'}/build.cfg", $build_cfg);
|
---|
| 468 | }
|
---|
[14384] | 469 | if ($gs_mode eq "gs3") {
|
---|
[14930] | 470 |
|
---|
| 471 | &colcfg::write_build_cfg_xml("$self->{'build_dir'}/buildConfig.xml", $build_cfg, $self->{'collect_cfg_preserve'}, $self->{'disable_OAI'});
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | print STDERR "</Stage>\n" if $self->{'gli'};
|
---|
| 475 | }
|
---|
| 476 |
|
---|
| 477 | sub collect_specific {
|
---|
| 478 | my $self = shift (@_);
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | sub want_built {
|
---|
| 482 | my $self = shift (@_);
|
---|
| 483 | my ($index) = @_;
|
---|
| 484 |
|
---|
| 485 | if (defined ($self->{'collect_cfg'}->{'dontbuild'})) {
|
---|
| 486 | foreach my $checkstr (@{$self->{'collect_cfg'}->{'dontbuild'}}) {
|
---|
| 487 | if ($index =~ /^$checkstr$/) {
|
---|
| 488 | $self->{'notbuilt'}->{$index} = 1;
|
---|
| 489 | return 0;
|
---|
| 490 | }
|
---|
| 491 | }
|
---|
| 492 | }
|
---|
| 493 |
|
---|
| 494 | return 1;
|
---|
| 495 | }
|
---|
| 496 |
|
---|
| 497 | sub create_index_mapping {
|
---|
| 498 | my $self = shift (@_);
|
---|
| 499 | my ($indexes) = @_;
|
---|
| 500 |
|
---|
| 501 | print STDERR "create_index_mapping should be implemented in subclass\n";
|
---|
| 502 | my %mapping = ();
|
---|
| 503 | return \%mapping;
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | # returns a processed version of a field.
|
---|
| 507 | # if the field has only one component the processed
|
---|
| 508 | # version will contain the first character and next consonant
|
---|
| 509 | # of that componant - otherwise it will contain the first
|
---|
| 510 | # character of the first two components
|
---|
| 511 | # only uses letdig (\w) characters now
|
---|
| 512 | sub process_field {
|
---|
| 513 | my $self = shift (@_);
|
---|
| 514 | my ($field) = @_;
|
---|
| 515 |
|
---|
| 516 | return "" unless (defined ($field) && $field =~ /\S/);
|
---|
| 517 |
|
---|
| 518 | my ($a, $b);
|
---|
| 519 | my @components = split /,/, $field;
|
---|
| 520 | if (scalar @components >= 2) {
|
---|
| 521 | # pick the first letdig from the first two field names
|
---|
| 522 | ($a) = $components[0] =~ /^[^\w]*(\w)/;
|
---|
| 523 | ($b) = $components[1] =~ /^[^\w]*(\w)/;
|
---|
| 524 | } else {
|
---|
| 525 | # pick the first two letdig chars
|
---|
| 526 | ($a, $b) = $field =~ /^[^\w]*(\w)[^\w]*?(\w)/i;
|
---|
| 527 | }
|
---|
| 528 | # there may not have been any letdigs...
|
---|
| 529 | $a = 'a' unless defined $a;
|
---|
| 530 | $b = '0' unless defined $b;
|
---|
| 531 |
|
---|
| 532 | return "$a$b";
|
---|
| 533 |
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | sub get_next_version {
|
---|
| 537 | my $self = shift (@_);
|
---|
| 538 | my ($nameref) = @_;
|
---|
| 539 | my $num=0;
|
---|
| 540 | if ($$nameref =~ /(\d\d)$/) {
|
---|
| 541 | $num = $1; $num ++;
|
---|
| 542 | $$nameref =~ s/\d\d$/$num/;
|
---|
| 543 | } elsif ($$nameref =~ /(\d)$/) {
|
---|
| 544 | $num = $1;
|
---|
| 545 | if ($num == 9) {$$nameref =~ s/\d$/10/;}
|
---|
| 546 | else {$num ++; $$nameref =~ s/\d$/$num/;}
|
---|
| 547 | } else {
|
---|
| 548 | $$nameref =~ s/.$/0/;
|
---|
| 549 | }
|
---|
| 550 | }
|
---|
| 551 |
|
---|
| 552 | # implement this in subclass if want to add extra stuff to build.cfg
|
---|
| 553 | sub build_cfg_extra {
|
---|
| 554 | my $self = shift(@_);
|
---|
| 555 | my ($build_cfg) = @_;
|
---|
| 556 |
|
---|
| 557 | }
|
---|
| 558 |
|
---|
[14934] | 559 |
|
---|
[15709] | 560 | sub get_collection_meta_sets
|
---|
| 561 | {
|
---|
[14930] | 562 | my $self = shift(@_);
|
---|
[15709] | 563 | my $collection_infodb = shift(@_);
|
---|
[14930] | 564 |
|
---|
[14934] | 565 | my $mdprefix_fields = $self->{'buildproc'}->{'mdprefix_fields'};
|
---|
| 566 | foreach my $prefix (keys %$mdprefix_fields)
|
---|
| 567 | {
|
---|
[15709] | 568 | push(@{$collection_infodb->{"metadataset"}}, $prefix);
|
---|
[14934] | 569 |
|
---|
| 570 | foreach my $field (keys %{$mdprefix_fields->{$prefix}})
|
---|
| 571 | {
|
---|
[15709] | 572 | push(@{$collection_infodb->{"metadatalist-$prefix"}}, $field);
|
---|
| 573 |
|
---|
[14934] | 574 | my $val = $mdprefix_fields->{$prefix}->{$field};
|
---|
[15709] | 575 | push(@{$collection_infodb->{"metadatafreq-$prefix-$field"}}, $val);
|
---|
[14934] | 576 | }
|
---|
| 577 | }
|
---|
[15709] | 578 | }
|
---|
[14934] | 579 |
|
---|
| 580 |
|
---|
| 581 | # default is to output the metadata sets (prefixes) used in collection
|
---|
[15709] | 582 | sub output_collection_meta
|
---|
| 583 | {
|
---|
[14934] | 584 | my $self = shift(@_);
|
---|
[15709] | 585 | my $infodb_handle = shift(@_);
|
---|
[14934] | 586 |
|
---|
[15709] | 587 | my %collection_infodb = ();
|
---|
| 588 | $self->get_collection_meta_sets(\%collection_infodb);
|
---|
| 589 | &dbutil::write_infodb_entry($infodb_handle, "collection", \%collection_infodb);
|
---|
| 590 | }
|
---|
[14934] | 591 |
|
---|
| 592 |
|
---|
[14930] | 593 | sub print_stats {
|
---|
| 594 | my $self = shift (@_);
|
---|
| 595 |
|
---|
| 596 | my $outhandle = $self->{'outhandle'};
|
---|
| 597 | my $indexing_text = $self->{'buildproc'}->get_indexing_text();
|
---|
| 598 | my $index = $self->{'buildproc'}->get_index();
|
---|
| 599 | my $num_bytes = $self->{'buildproc'}->get_num_bytes();
|
---|
| 600 | my $num_processed_bytes = $self->{'buildproc'}->get_num_processed_bytes();
|
---|
| 601 |
|
---|
| 602 | if ($indexing_text) {
|
---|
| 603 | print $outhandle "Stats (Creating index $index)\n";
|
---|
| 604 | } else {
|
---|
| 605 | print $outhandle "Stats (Compressing text from $index)\n";
|
---|
| 606 | }
|
---|
| 607 | print $outhandle "Total bytes in collection: $num_bytes\n";
|
---|
| 608 | print $outhandle "Total bytes in $index: $num_processed_bytes\n";
|
---|
| 609 |
|
---|
| 610 | if ($num_processed_bytes < 50 && ($indexing_text || !$self->{'no_text'})) {
|
---|
| 611 |
|
---|
| 612 | if ($self->{'keepold'}) {
|
---|
| 613 | if ($num_processed_bytes == 0) {
|
---|
| 614 | if ($indexing_text) {
|
---|
| 615 | print $outhandle "No additional text was added to $index\n";
|
---|
| 616 | } elsif (!$self->{'no_text'}) {
|
---|
| 617 | print $outhandle "No additional text was compressed\n";
|
---|
| 618 | }
|
---|
| 619 | }
|
---|
| 620 | }
|
---|
| 621 | else {
|
---|
| 622 | print $outhandle "***************\n";
|
---|
| 623 | if ($indexing_text) {
|
---|
| 624 | print $outhandle "WARNING: There is very little or no text to process for $index\n";
|
---|
| 625 | } elsif (!$self->{'no_text'}) {
|
---|
| 626 | print $outhandle "WARNING: There is very little or no text to compress\n";
|
---|
| 627 | }
|
---|
| 628 | print $outhandle " Was this your intention?\n";
|
---|
| 629 | print $outhandle "***************\n";
|
---|
| 630 | }
|
---|
| 631 |
|
---|
| 632 | }
|
---|
| 633 |
|
---|
| 634 | }
|
---|
| 635 |
|
---|
| 636 |
|
---|
| 637 | 1;
|
---|
| 638 |
|
---|