[9919] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # basebuildproc.pm --
|
---|
| 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 | # This document processor outputs a document for indexing (should be
|
---|
[15688] | 27 | # implemented by subclass) and storing in the database
|
---|
[9919] | 28 |
|
---|
| 29 | package basebuildproc;
|
---|
| 30 |
|
---|
| 31 | eval {require bytes};
|
---|
| 32 |
|
---|
| 33 | use classify;
|
---|
[15699] | 34 | use dbutil;
|
---|
[9919] | 35 | use doc;
|
---|
| 36 | use docproc;
|
---|
[15696] | 37 | use strict; no strict 'subs';
|
---|
[9919] | 38 | use util;
|
---|
| 39 |
|
---|
| 40 | BEGIN {
|
---|
| 41 | @basebuildproc::ISA = ('docproc');
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[12844] | 44 | sub new()
|
---|
| 45 | {
|
---|
| 46 | my ($class, $collection, $source_dir, $build_dir, $keepold, $verbosity, $outhandle) = @_;
|
---|
[9919] | 47 | my $self = new docproc ();
|
---|
| 48 |
|
---|
| 49 | # outhandle is where all the debugging info goes
|
---|
| 50 | # output_handle is where the output of the plugins is piped
|
---|
[15688] | 51 | # to (i.e. mg, database etc.)
|
---|
[9919] | 52 | $outhandle = STDERR unless defined $outhandle;
|
---|
| 53 |
|
---|
| 54 | $self->{'collection'} = $collection;
|
---|
| 55 | $self->{'source_dir'} = $source_dir;
|
---|
[10159] | 56 | $self->{'build_dir'} = $build_dir;
|
---|
| 57 | $self->{'keepold'} = $keepold;
|
---|
| 58 | $self->{'verbosity'} = $verbosity;
|
---|
| 59 | $self->{'outhandle'} = $outhandle;
|
---|
[9919] | 60 |
|
---|
| 61 | $self->{'classifiers'} = [];
|
---|
| 62 | $self->{'mode'} = "text";
|
---|
| 63 | $self->{'assocdir'} = $build_dir;
|
---|
[15688] | 64 | $self->{'dontdb'} = {};
|
---|
[9919] | 65 |
|
---|
| 66 | $self->{'index'} = "section:text";
|
---|
| 67 | $self->{'indexexparr'} = [];
|
---|
| 68 |
|
---|
[10159] | 69 | my $found_num_data = 0;
|
---|
| 70 | my $buildconfigfile = undef;
|
---|
| 71 |
|
---|
| 72 | if ($keepold) {
|
---|
| 73 | # For incremental building need to seed num_docs etc from values
|
---|
| 74 | # stored in build.cfg (if present)
|
---|
[12844] | 75 | print STDERR "Keepold!\n";
|
---|
[10159] | 76 | $buildconfigfile = &util::filename_cat($build_dir, "build.cfg");
|
---|
[12844] | 77 | print STDERR "Build cfg: $buildconfigfile\n";
|
---|
[10159] | 78 | if (-e $buildconfigfile) {
|
---|
| 79 | $found_num_data = 1;
|
---|
| 80 | }
|
---|
| 81 | else {
|
---|
| 82 | # try the index dir
|
---|
| 83 | $buildconfigfile = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},
|
---|
| 84 | "index", "build.cfg");
|
---|
[12844] | 85 | print STDERR "Index cfg: $buildconfigfile\n";
|
---|
[10159] | 86 | if (-e $buildconfigfile) {
|
---|
| 87 | $found_num_data = 1;
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[12844] | 91 | }
|
---|
| 92 | #else
|
---|
| 93 | # {
|
---|
| 94 | # print STDERR "Removeold!\n";
|
---|
| 95 | # }
|
---|
[10159] | 96 |
|
---|
[12844] | 97 | if ($found_num_data)
|
---|
| 98 | {
|
---|
| 99 | #print STDERR "Found_Num_Data!\n";
|
---|
[10159] | 100 | my $buildcfg = &colcfg::read_build_cfg($buildconfigfile);
|
---|
| 101 | $self->{'starting_num_docs'} = $buildcfg->{'numdocs'};
|
---|
[12844] | 102 | #print STDERR "- num_docs: $self->{'starting_num_docs'}\n";
|
---|
[10159] | 103 | $self->{'starting_num_sections'} = $buildcfg->{'numsections'};
|
---|
[12844] | 104 | #print STDERR "- num_sections: $self->{'starting_num_sections'}\n";
|
---|
[10159] | 105 | $self->{'starting_num_bytes'} = $buildcfg->{'numbytes'};
|
---|
[12844] | 106 | #print STDERR "- num_bytes: $self->{'starting_num_bytes'}\n";
|
---|
[10159] | 107 | }
|
---|
[12844] | 108 | else
|
---|
| 109 | {
|
---|
| 110 | #print STDERR "NOT Found_Num_Data!\n";
|
---|
| 111 | $self->{'starting_num_docs'} = 0;
|
---|
[10159] | 112 | $self->{'starting_num_sections'} = 0;
|
---|
| 113 | $self->{'starting_num_bytes'} = 0;
|
---|
[12844] | 114 | }
|
---|
[10159] | 115 |
|
---|
[9919] | 116 | $self->{'output_handle'} = "STDOUT";
|
---|
[10159] | 117 | $self->{'num_docs'} = $self->{'starting_num_docs'};
|
---|
| 118 | $self->{'num_sections'} = $self->{'starting_num_sections'};
|
---|
| 119 | $self->{'num_bytes'} = $self->{'starting_num_bytes'};
|
---|
| 120 |
|
---|
[9919] | 121 | $self->{'num_processed_bytes'} = 0;
|
---|
| 122 | $self->{'store_text'} = 1;
|
---|
| 123 |
|
---|
[15685] | 124 | # what level (section/document) the database - indexer intersection is
|
---|
| 125 | $self->{'db_level'} = "section";
|
---|
[9919] | 126 | #used by browse interface
|
---|
| 127 | $self->{'doclist'} = [];
|
---|
| 128 |
|
---|
| 129 | $self->{'indexing_text'} = 0;
|
---|
| 130 |
|
---|
| 131 | return bless $self, $class;
|
---|
| 132 |
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | sub reset {
|
---|
| 136 | my $self = shift (@_);
|
---|
[10159] | 137 |
|
---|
| 138 | $self->{'num_docs'} = $self->{'starting_num_docs'};
|
---|
| 139 | $self->{'num_sections'} = $self->{'starting_num_sections'};
|
---|
| 140 | $self->{'num_bytes'} = $self->{'starting_num_bytes'};
|
---|
[9919] | 141 |
|
---|
| 142 | $self->{'num_processed_bytes'} = 0;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[10159] | 145 | sub zero_reset {
|
---|
| 146 | my $self = shift (@_);
|
---|
| 147 |
|
---|
| 148 | $self->{'num_docs'} = 0;
|
---|
| 149 | $self->{'num_sections'} = 0;
|
---|
| 150 | $self->{'num_bytes'} = 0;
|
---|
| 151 |
|
---|
| 152 | $self->{'num_processed_bytes'} = 0;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[10419] | 155 | sub is_incremental_capable
|
---|
[10304] | 156 | {
|
---|
| 157 | # By default we return 'no' as the answer
|
---|
| 158 | # Safer to assume non-incremental to start with, and then override in
|
---|
| 159 | # inherited classes that are.
|
---|
| 160 |
|
---|
| 161 | return 0;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
[9919] | 164 | sub get_num_docs {
|
---|
| 165 | my $self = shift (@_);
|
---|
| 166 |
|
---|
| 167 | return $self->{'num_docs'};
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | sub get_num_sections {
|
---|
| 171 | my $self = shift (@_);
|
---|
| 172 |
|
---|
| 173 | return $self->{'num_sections'};
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | # num_bytes is the actual number of bytes in the collection
|
---|
| 177 | # this is normally the same as what's processed during text compression
|
---|
| 178 | sub get_num_bytes {
|
---|
| 179 | my $self = shift (@_);
|
---|
| 180 |
|
---|
| 181 | return $self->{'num_bytes'};
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | # num_processed_bytes is the number of bytes actually passed
|
---|
| 185 | # to mg for the current index
|
---|
| 186 | sub get_num_processed_bytes {
|
---|
| 187 | my $self = shift (@_);
|
---|
| 188 |
|
---|
| 189 | return $self->{'num_processed_bytes'};
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | sub set_output_handle {
|
---|
| 193 | my $self = shift (@_);
|
---|
| 194 | my ($handle) = @_;
|
---|
| 195 |
|
---|
| 196 | $self->{'output_handle'} = $handle;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 | sub set_mode {
|
---|
| 201 | my $self = shift (@_);
|
---|
| 202 | my ($mode) = @_;
|
---|
| 203 |
|
---|
| 204 | $self->{'mode'} = $mode;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
[10159] | 207 | sub get_mode {
|
---|
| 208 | my $self = shift (@_);
|
---|
| 209 |
|
---|
| 210 | return $self->{'mode'};
|
---|
| 211 | }
|
---|
| 212 |
|
---|
[9919] | 213 | sub set_assocdir {
|
---|
| 214 | my $self = shift (@_);
|
---|
| 215 | my ($assocdir) = @_;
|
---|
| 216 |
|
---|
| 217 | $self->{'assocdir'} = $assocdir;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
[15688] | 220 | sub set_dontdb {
|
---|
[9919] | 221 | my $self = shift (@_);
|
---|
[15688] | 222 | my ($dontdb) = @_;
|
---|
[9919] | 223 |
|
---|
[15688] | 224 | $self->{'dontdb'} = $dontdb;
|
---|
[9919] | 225 | }
|
---|
| 226 |
|
---|
[15725] | 227 | sub set_infodbtype
|
---|
| 228 | {
|
---|
| 229 | my $self = shift(@_);
|
---|
| 230 | my $infodbtype = shift(@_);
|
---|
| 231 | $self->{'infodbtype'} = $infodbtype;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[9919] | 234 | sub set_index {
|
---|
| 235 | my $self = shift (@_);
|
---|
| 236 | my ($index, $indexexparr) = @_;
|
---|
| 237 |
|
---|
| 238 | $self->{'index'} = $index;
|
---|
| 239 | $self->{'indexexparr'} = $indexexparr if defined $indexexparr;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | sub set_index_languages {
|
---|
| 243 | my $self = shift (@_);
|
---|
| 244 | my ($lang_meta, $langarr) = @_;
|
---|
| 245 | $self->{'lang_meta'} = $lang_meta;
|
---|
| 246 | $self->{'langarr'} = $langarr;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | sub get_index {
|
---|
| 250 | my $self = shift (@_);
|
---|
| 251 |
|
---|
| 252 | return $self->{'index'};
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | sub set_classifiers {
|
---|
| 256 | my $self = shift (@_);
|
---|
| 257 | my ($classifiers) = @_;
|
---|
| 258 |
|
---|
| 259 | $self->{'classifiers'} = $classifiers;
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | sub set_indexing_text {
|
---|
| 263 | my $self = shift (@_);
|
---|
| 264 | my ($indexing_text) = @_;
|
---|
| 265 |
|
---|
| 266 | $self->{'indexing_text'} = $indexing_text;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | sub get_indexing_text {
|
---|
| 270 | my $self = shift (@_);
|
---|
| 271 |
|
---|
| 272 | return $self->{'indexing_text'};
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | sub set_store_text {
|
---|
| 276 | my $self = shift (@_);
|
---|
| 277 | my ($store_text) = @_;
|
---|
| 278 |
|
---|
| 279 | $self->{'store_text'} = $store_text;
|
---|
| 280 | }
|
---|
| 281 | sub get_doc_list {
|
---|
| 282 | my $self = shift(@_);
|
---|
| 283 |
|
---|
| 284 | return @{$self->{'doclist'}};
|
---|
| 285 | }
|
---|
| 286 |
|
---|
[15685] | 287 | # the standard database level is section, but you may want to change it to document
|
---|
| 288 | sub set_db_level {
|
---|
[9919] | 289 | my $self= shift (@_);
|
---|
[15685] | 290 | my ($db_level) = @_;
|
---|
[9919] | 291 |
|
---|
[15685] | 292 | $self->{'db_level'} = $db_level;
|
---|
[9919] | 293 | }
|
---|
| 294 |
|
---|
[10469] | 295 | sub set_sections_index_document_metadata {
|
---|
| 296 | my $self= shift (@_);
|
---|
| 297 | my ($index_type) = @_;
|
---|
| 298 |
|
---|
| 299 | $self->{'sections_index_document_metadata'} = $index_type;
|
---|
| 300 | }
|
---|
[9919] | 301 | sub process {
|
---|
| 302 | my $self = shift (@_);
|
---|
| 303 | my $method = $self->{'mode'};
|
---|
| 304 |
|
---|
| 305 | $self->$method(@_);
|
---|
| 306 | }
|
---|
| 307 |
|
---|
[14934] | 308 |
|
---|
| 309 |
|
---|
| 310 | sub infodb_metadata_stats
|
---|
| 311 | {
|
---|
| 312 | my $self = shift (@_);
|
---|
| 313 | my ($field) = @_;
|
---|
| 314 |
|
---|
| 315 | # Keep some statistics relating to metadata sets used and
|
---|
| 316 | # frequency of particular metadata fields within each set
|
---|
| 317 |
|
---|
| 318 | # Union of metadata prefixes and frequency of fields
|
---|
| 319 | # (both scoped for this document alone, and across whole collection)
|
---|
| 320 |
|
---|
| 321 | if ($field =~ m/^(.+)\.(.*)$/) {
|
---|
| 322 | my $prefix = $1;
|
---|
| 323 | my $core_field = $2;
|
---|
| 324 |
|
---|
| 325 | $self->{'doc_mdprefix_fields'}->{$prefix}->{$core_field}++;
|
---|
| 326 | $self->{'mdprefix_fields'}->{$prefix}->{$core_field}++;
|
---|
| 327 | }
|
---|
| 328 | elsif ($field =~ m/^[[:upper:]]/) {
|
---|
| 329 | # implicit 'ex' metadata set
|
---|
| 330 |
|
---|
| 331 | $self->{'doc_mdprefix_fields'}->{'ex'}->{$field}++;
|
---|
| 332 | $self->{'mdprefix_fields'}->{'ex'}->{$field}++;
|
---|
| 333 | }
|
---|
| 334 |
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 |
|
---|
[9919] | 338 | sub infodb {
|
---|
| 339 | my $self = shift (@_);
|
---|
| 340 | my ($doc_obj, $filename) = @_;
|
---|
| 341 |
|
---|
[15696] | 342 | # only output this document if it is a "indexed_doc" or "info_doc" (database only) document
|
---|
[9919] | 343 | my $doctype = $doc_obj->get_doc_type();
|
---|
[11793] | 344 | return if ($doctype ne "indexed_doc" && $doctype ne "info_doc");
|
---|
[9919] | 345 |
|
---|
[11994] | 346 | my $archivedir = "";
|
---|
| 347 | if (defined $filename)
|
---|
| 348 | {
|
---|
| 349 | # doc_obj derived directly from file
|
---|
| 350 | my ($dir) = $filename =~ /^(.*?)(?:\/|\\)[^\/\\]*$/;
|
---|
| 351 | $dir = "" unless defined $dir;
|
---|
| 352 | $dir =~ s/\\/\//g;
|
---|
| 353 | $dir =~ s/^\/+//;
|
---|
| 354 | $dir =~ s/\/+$//;
|
---|
| 355 |
|
---|
| 356 | $archivedir = $dir;
|
---|
| 357 |
|
---|
| 358 | # resolve the final filenames of the files associated with this document
|
---|
| 359 | $self->assoc_files ($doc_obj, $archivedir);
|
---|
| 360 | }
|
---|
| 361 | else
|
---|
| 362 | {
|
---|
[15688] | 363 | # doc_obj reconstructed from database (has metadata, doc structure but no text)
|
---|
[11994] | 364 | my $top_section = $doc_obj->get_top_section();
|
---|
| 365 | $archivedir = $doc_obj->get_metadata_element($top_section,"archivedir");
|
---|
| 366 | }
|
---|
| 367 |
|
---|
[9919] | 368 | #add this document to the browse structure
|
---|
| 369 | push(@{$self->{'doclist'}},$doc_obj->get_OID())
|
---|
| 370 | unless ($doctype eq "classification");
|
---|
| 371 |
|
---|
| 372 | # classify this document
|
---|
| 373 | &classify::classify_doc ($self->{'classifiers'}, $doc_obj);
|
---|
| 374 |
|
---|
| 375 | # this is another document
|
---|
| 376 | $self->{'num_docs'} += 1 unless ($doctype eq "classification");
|
---|
| 377 |
|
---|
| 378 | # is this a paged or a hierarchical document
|
---|
| 379 | my ($thistype, $childtype) = $self->get_document_type ($doc_obj);
|
---|
| 380 |
|
---|
| 381 | my $section = $doc_obj->get_top_section ();
|
---|
| 382 | my $doc_OID = $doc_obj->get_OID();
|
---|
| 383 | my $first = 1;
|
---|
[15699] | 384 | my $infodb_handle = $self->{'output_handle'};
|
---|
[14934] | 385 |
|
---|
| 386 | $self->{'doc_mdprefix_fields'} = {};
|
---|
| 387 |
|
---|
[15695] | 388 | while (defined $section)
|
---|
| 389 | {
|
---|
| 390 | my $section_OID = $doc_OID;
|
---|
| 391 | if ($section ne "")
|
---|
| 392 | {
|
---|
| 393 | $section_OID = $doc_OID . "." . $section;
|
---|
| 394 | }
|
---|
[15696] | 395 | my %section_infodb = ();
|
---|
[15695] | 396 |
|
---|
[9919] | 397 | # update a few statistics
|
---|
| 398 | $self->{'num_bytes'} += $doc_obj->get_text_length ($section);
|
---|
| 399 | $self->{'num_sections'} += 1 unless ($doctype eq "classification");
|
---|
| 400 |
|
---|
| 401 | # output the fact that this document is a document (unless doctype
|
---|
| 402 | # has been set to something else from within a plugin
|
---|
| 403 | my $dtype = $doc_obj->get_metadata_element ($section, "doctype");
|
---|
| 404 | if (!defined $dtype || $dtype !~ /\w/) {
|
---|
[15697] | 405 | $section_infodb{"doctype"} = [ "doc" ];
|
---|
[9919] | 406 | }
|
---|
| 407 |
|
---|
[11994] | 408 | # Output whether this node contains text
|
---|
| 409 | #
|
---|
[15688] | 410 | # If doc_obj reconstructed from database file then no need to
|
---|
[11994] | 411 | # explicitly add <hastxt> as this is preserved as metadata when
|
---|
[15688] | 412 | # the database file is loaded in
|
---|
[11994] | 413 | if (defined $filename)
|
---|
| 414 | {
|
---|
| 415 | # doc_obj derived directly from file
|
---|
| 416 | if ($doc_obj->get_text_length($section) > 0) {
|
---|
[15697] | 417 | $section_infodb{"hastxt"} = [ "1" ];
|
---|
[11994] | 418 | } else {
|
---|
[15697] | 419 | $section_infodb{"hastxt"} = [ "0" ];
|
---|
[11994] | 420 | }
|
---|
[9919] | 421 | }
|
---|
| 422 |
|
---|
| 423 | # output all the section metadata
|
---|
| 424 | my $metadata = $doc_obj->get_all_metadata ($section);
|
---|
| 425 | foreach my $pair (@$metadata) {
|
---|
| 426 | my ($field, $value) = (@$pair);
|
---|
| 427 |
|
---|
| 428 | if ($field ne "Identifier" && $field !~ /^gsdl/ &&
|
---|
| 429 | defined $value && $value ne "") {
|
---|
| 430 |
|
---|
| 431 | # escape problematic stuff
|
---|
| 432 | $value =~ s/\\/\\\\/g;
|
---|
| 433 | $value =~ s/\n/\\n/g;
|
---|
| 434 | $value =~ s/\r/\\r/g;
|
---|
| 435 |
|
---|
| 436 | # special case for URL metadata
|
---|
| 437 | if ($field =~ /^URL$/i) {
|
---|
[15725] | 438 | &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $value, { 'section' => [ $section_OID ] });
|
---|
[9919] | 439 | }
|
---|
| 440 |
|
---|
[15688] | 441 | if (!defined $self->{'dontdb'}->{$field}) {
|
---|
[15697] | 442 | push(@{$section_infodb{$field}}, $value);
|
---|
[14934] | 443 |
|
---|
| 444 | if ($section eq "")
|
---|
| 445 | {
|
---|
| 446 | $self->infodb_metadata_stats($field);
|
---|
| 447 | }
|
---|
[9919] | 448 | }
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
| 451 |
|
---|
[14934] | 452 | if ($section eq "")
|
---|
| 453 | {
|
---|
| 454 | my $doc_mdprefix_fields = $self->{'doc_mdprefix_fields'};
|
---|
[11994] | 455 |
|
---|
[14934] | 456 | foreach my $prefix (keys %$doc_mdprefix_fields)
|
---|
| 457 | {
|
---|
[15697] | 458 | push(@{$section_infodb{"metadataset"}}, $prefix);
|
---|
[14934] | 459 |
|
---|
| 460 | foreach my $field (keys %{$doc_mdprefix_fields->{$prefix}})
|
---|
| 461 | {
|
---|
[15708] | 462 | push(@{$section_infodb{"metadatalist-$prefix"}}, $field);
|
---|
| 463 |
|
---|
[14934] | 464 | my $val = $doc_mdprefix_fields->{$prefix}->{$field};
|
---|
[15697] | 465 | push(@{$section_infodb{"metadatafreq-$prefix-$field"}}, $val);
|
---|
[14934] | 466 | }
|
---|
| 467 | }
|
---|
| 468 | }
|
---|
| 469 |
|
---|
[15688] | 470 | # If doc_obj reconstructed from database file then no need to
|
---|
[11994] | 471 | # explicitly add <archivedir> as this is preserved as metadata when
|
---|
[15688] | 472 | # the database file is loaded in
|
---|
[11994] | 473 | if (defined $filename)
|
---|
| 474 | {
|
---|
| 475 | # output archivedir if at top level
|
---|
| 476 | if ($section eq $doc_obj->get_top_section()) {
|
---|
[15697] | 477 | $section_infodb{"archivedir"} = [ $archivedir ];
|
---|
[11994] | 478 | }
|
---|
[9919] | 479 | }
|
---|
| 480 |
|
---|
| 481 | # output document display type
|
---|
| 482 | if ($first) {
|
---|
[15697] | 483 | $section_infodb{"thistype"} = [ $thistype ];
|
---|
[9919] | 484 | }
|
---|
| 485 |
|
---|
[15685] | 486 | if ($self->{'db_level'} eq "document") {
|
---|
[9919] | 487 | # doc num is num_docs not num_sections
|
---|
| 488 | # output the matching document number
|
---|
[15697] | 489 | $section_infodb{"docnum"} = [ $self->{'num_docs'} ];
|
---|
[15696] | 490 | }
|
---|
| 491 | else {
|
---|
[9919] | 492 | # output a list of children
|
---|
| 493 | my $children = $doc_obj->get_children ($section);
|
---|
| 494 | if (scalar(@$children) > 0) {
|
---|
[15697] | 495 | $section_infodb{"childtype"} = [ $childtype ];
|
---|
[15696] | 496 | my $contains = "";
|
---|
| 497 | foreach my $child (@$children)
|
---|
| 498 | {
|
---|
| 499 | $contains .= ";" unless ($contains eq "");
|
---|
| 500 | if ($child =~ /^.*?\.(\d+)$/)
|
---|
| 501 | {
|
---|
| 502 | $contains .= "\".$1";
|
---|
[9919] | 503 | }
|
---|
[15698] | 504 | else
|
---|
| 505 | {
|
---|
[15696] | 506 | $contains .= "\".$child";
|
---|
| 507 | }
|
---|
[9919] | 508 | }
|
---|
[15697] | 509 | $section_infodb{"contains"} = [ $contains ];
|
---|
[9919] | 510 | }
|
---|
[15696] | 511 | # output the matching doc number
|
---|
[15697] | 512 | $section_infodb{"docnum"} = [ $self->{'num_sections'} ];
|
---|
[9919] | 513 | }
|
---|
| 514 |
|
---|
[15725] | 515 | &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $section_OID, \%section_infodb);
|
---|
[9919] | 516 |
|
---|
| 517 | # output a database entry for the document number
|
---|
[15685] | 518 | if ($self->{'db_level'} eq "document") {
|
---|
[15725] | 519 | &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_docs'}, { 'section' => [ $doc_OID ] });
|
---|
[9919] | 520 | }
|
---|
| 521 | else {
|
---|
[15725] | 522 | &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_sections'}, { 'section' => [ $section_OID ] });
|
---|
[9919] | 523 | }
|
---|
| 524 |
|
---|
| 525 | $first = 0;
|
---|
| 526 | $section = $doc_obj->get_next_section($section);
|
---|
[15685] | 527 | last if ($self->{'db_level'} eq "document"); # if no sections wanted, only add the docs
|
---|
[9919] | 528 | }
|
---|
[15696] | 529 | }
|
---|
[9919] | 530 |
|
---|
[15696] | 531 |
|
---|
[9919] | 532 | sub text {
|
---|
| 533 | my $self = shift (@_);
|
---|
| 534 | my ($doc_obj) = @_;
|
---|
| 535 |
|
---|
| 536 | my $handle = $self->{'outhandle'};
|
---|
| 537 | print $handle "basebuildproc::text function must be implemented in sub classes\n";
|
---|
| 538 | die "\n";
|
---|
| 539 | }
|
---|
| 540 |
|
---|
| 541 | # should the document be indexed - according to the subcollection and language
|
---|
| 542 | # specification.
|
---|
| 543 | sub is_subcollection_doc {
|
---|
| 544 | my $self = shift (@_);
|
---|
| 545 | my ($doc_obj) = @_;
|
---|
| 546 |
|
---|
| 547 | my $indexed_doc = 1;
|
---|
| 548 | foreach my $indexexp (@{$self->{'indexexparr'}}) {
|
---|
| 549 | $indexed_doc = 0;
|
---|
| 550 | my ($field, $exp, $options) = split /\//, $indexexp;
|
---|
| 551 | if (defined ($field) && defined ($exp)) {
|
---|
| 552 | my ($bool) = $field =~ /^(.)/;
|
---|
| 553 | $field =~ s/^.// if $bool eq '!';
|
---|
[10028] | 554 | my @metadata_values;
|
---|
[9919] | 555 | if ($field =~ /^filename$/i) {
|
---|
[10028] | 556 | push(@metadata_values, $doc_obj->get_source_filename());
|
---|
[9919] | 557 | }
|
---|
[10028] | 558 | else {
|
---|
| 559 | @metadata_values = @{$doc_obj->get_metadata($doc_obj->get_top_section(), $field)};
|
---|
| 560 | }
|
---|
| 561 | next unless @metadata_values;
|
---|
| 562 | foreach my $metadata_value (@metadata_values) {
|
---|
| 563 | if ($bool eq '!') {
|
---|
| 564 | if ($options =~ /^i$/i) {
|
---|
| 565 | if ($metadata_value !~ /$exp/i) {$indexed_doc = 1; last;}
|
---|
| 566 | } else {
|
---|
| 567 | if ($metadata_value !~ /$exp/) {$indexed_doc = 1; last;}
|
---|
| 568 | }
|
---|
[9919] | 569 | } else {
|
---|
[10028] | 570 | if ($options =~ /^i$/i) {
|
---|
| 571 | if ($metadata_value =~ /$exp/i) {$indexed_doc = 1; last;}
|
---|
| 572 | } else {
|
---|
| 573 | if ($metadata_value =~ /$exp/) {$indexed_doc = 1; last;}
|
---|
| 574 | }
|
---|
[9919] | 575 | }
|
---|
| 576 | }
|
---|
[10028] | 577 |
|
---|
| 578 | last if ($indexed_doc == 1);
|
---|
[9919] | 579 | }
|
---|
| 580 | }
|
---|
| 581 |
|
---|
| 582 | # if this doc is so far in the sub collection, and we have lang info,
|
---|
| 583 | # now we check the languages to see if it matches
|
---|
| 584 | if($indexed_doc && defined $self->{'lang_meta'}) {
|
---|
| 585 | $indexed_doc = 0;
|
---|
| 586 | my $field = $doc_obj->get_metadata_element($doc_obj->get_top_section(), $self->{'lang_meta'});
|
---|
| 587 | if (defined $field) {
|
---|
| 588 | foreach my $lang (@{$self->{'langarr'}}) {
|
---|
| 589 | my ($bool) = $lang =~ /^(.)/;
|
---|
| 590 | if ($bool eq '!') {
|
---|
| 591 | $lang =~ s/^.//;
|
---|
| 592 | if ($field !~ /$lang/) {
|
---|
| 593 | $indexed_doc = 1; last;
|
---|
| 594 | }
|
---|
| 595 | } else {
|
---|
| 596 | if ($field =~ /$lang/) {
|
---|
| 597 | $indexed_doc = 1; last;
|
---|
| 598 | }
|
---|
| 599 | }
|
---|
| 600 | }
|
---|
| 601 | }
|
---|
| 602 | }
|
---|
| 603 | return $indexed_doc;
|
---|
| 604 |
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | # use 'Paged' if document has no more than 2 levels
|
---|
| 608 | # and each section at second level has a number for
|
---|
| 609 | # Title metadata
|
---|
| 610 | # also use Paged if gsdlthistype metadata is set to Paged
|
---|
| 611 | sub get_document_type {
|
---|
| 612 | my $self = shift (@_);
|
---|
| 613 | my ($doc_obj) = @_;
|
---|
| 614 |
|
---|
| 615 | my $thistype = "VList";
|
---|
| 616 | my $childtype = "VList";
|
---|
| 617 | my $title;
|
---|
| 618 | my @tmp = ();
|
---|
| 619 |
|
---|
| 620 | my $section = $doc_obj->get_top_section ();
|
---|
| 621 |
|
---|
| 622 | my $gsdlthistype = $doc_obj->get_metadata_element ($section, "gsdlthistype");
|
---|
| 623 | if (defined $gsdlthistype) {
|
---|
| 624 | if ($gsdlthistype eq "Paged") {
|
---|
| 625 | $childtype = "Paged";
|
---|
| 626 | if ($doc_obj->get_text_length ($doc_obj->get_top_section())) {
|
---|
| 627 | $thistype = "Paged";
|
---|
| 628 | } else {
|
---|
| 629 | $thistype = "Invisible";
|
---|
| 630 | }
|
---|
| 631 |
|
---|
| 632 | return ($thistype, $childtype);
|
---|
| 633 | } elsif ($gsdlthistype eq "Hierarchy") {
|
---|
| 634 | return ($thistype, $childtype); # use VList, VList
|
---|
| 635 | }
|
---|
| 636 | }
|
---|
| 637 | my $first = 1;
|
---|
| 638 | while (defined $section) {
|
---|
| 639 | @tmp = split /\./, $section;
|
---|
| 640 | if (scalar(@tmp) > 1) {
|
---|
| 641 | return ($thistype, $childtype);
|
---|
| 642 | }
|
---|
| 643 | if (!$first) {
|
---|
| 644 | $title = $doc_obj->get_metadata_element ($section, "Title");
|
---|
| 645 | if (!defined $title || $title !~ /^\d+$/) {
|
---|
| 646 | return ($thistype, $childtype);
|
---|
| 647 | }
|
---|
| 648 | }
|
---|
| 649 | $first = 0;
|
---|
| 650 | $section = $doc_obj->get_next_section($section);
|
---|
| 651 | }
|
---|
| 652 | if ($doc_obj->get_text_length ($doc_obj->get_top_section())) {
|
---|
| 653 | $thistype = "Paged";
|
---|
| 654 | } else {
|
---|
| 655 | $thistype = "Invisible";
|
---|
| 656 | }
|
---|
| 657 | $childtype = "Paged";
|
---|
| 658 | return ($thistype, $childtype);
|
---|
| 659 | }
|
---|
| 660 |
|
---|
[12844] | 661 | sub assoc_files() {
|
---|
[9919] | 662 | my $self = shift (@_);
|
---|
| 663 | my ($doc_obj, $archivedir) = @_;
|
---|
| 664 | my ($afile);
|
---|
| 665 |
|
---|
| 666 | foreach my $assoc_file (@{$doc_obj->get_assoc_files()}) {
|
---|
[12844] | 667 | #rint STDERR "Processing associated file - copy " . $assoc_file->[0] . " to " . $assoc_file->[1] . "\n";
|
---|
[9919] | 668 | # if assoc file starts with a slash, we put it relative to the assoc
|
---|
| 669 | # dir, otherwise it is relative to the HASH... directory
|
---|
| 670 | if ($assoc_file->[1] =~ m@^[/\\]@) {
|
---|
[12844] | 671 | $afile = &util::filename_cat($self->{'assocdir'}, $assoc_file->[1]);
|
---|
[9919] | 672 | } else {
|
---|
| 673 | $afile = &util::filename_cat($self->{'assocdir'}, $archivedir, $assoc_file->[1]);
|
---|
| 674 | }
|
---|
| 675 | &util::hard_link ($assoc_file->[0], $afile);
|
---|
| 676 | }
|
---|
| 677 | }
|
---|
| 678 |
|
---|