source: main/trunk/greenstone2/perllib/basebuildproc.pm@ 36057

Last change on this file since 36057 was 35832, checked in by davidb, 2 years ago

Addition on used debug print statement (comment out)

  • Property svn:keywords set to Author Date Id Revision
File size: 23.6 KB
RevLine 
[18508]1##########################################################################
[9919]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
29package basebuildproc;
30
31eval {require bytes};
32
33use classify;
[15699]34use dbutil;
[9919]35use doc;
36use docproc;
[18456]37use strict;
38no strict 'subs';
39no strict 'refs';
[9919]40use util;
[27306]41use FileUtils;
[9919]42
43BEGIN {
44 @basebuildproc::ISA = ('docproc');
45}
46
[12844]47sub new()
48 {
49 my ($class, $collection, $source_dir, $build_dir, $keepold, $verbosity, $outhandle) = @_;
[9919]50 my $self = new docproc ();
51
52 # outhandle is where all the debugging info goes
53 # output_handle is where the output of the plugins is piped
[15688]54 # to (i.e. mg, database etc.)
[9919]55 $outhandle = STDERR unless defined $outhandle;
56
57 $self->{'collection'} = $collection;
58 $self->{'source_dir'} = $source_dir;
[10159]59 $self->{'build_dir'} = $build_dir;
60 $self->{'keepold'} = $keepold;
61 $self->{'verbosity'} = $verbosity;
62 $self->{'outhandle'} = $outhandle;
[9919]63
64 $self->{'classifiers'} = [];
65 $self->{'mode'} = "text";
66 $self->{'assocdir'} = $build_dir;
[15688]67 $self->{'dontdb'} = {};
[16222]68 $self->{'store_metadata_coverage'} = "false";
[9919]69
70 $self->{'index'} = "section:text";
71 $self->{'indexexparr'} = [];
72
[17110]73 $self->{'separate_cjk'} = 0;
74
[10159]75 my $found_num_data = 0;
76 my $buildconfigfile = undef;
77
78 if ($keepold) {
79 # For incremental building need to seed num_docs etc from values
80 # stored in build.cfg (if present)
[27306]81 $buildconfigfile = &FileUtils::filenameConcatenate($build_dir, "build.cfg");
[10159]82 if (-e $buildconfigfile) {
83 $found_num_data = 1;
84 }
85 else {
86 # try the index dir
[27306]87 $buildconfigfile = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'},
[10159]88 "index", "build.cfg");
89 if (-e $buildconfigfile) {
90 $found_num_data = 1;
91 }
92 }
93
[12844]94 }
[10159]95
[12844]96 if ($found_num_data)
97 {
98 #print STDERR "Found_Num_Data!\n";
[10159]99 my $buildcfg = &colcfg::read_build_cfg($buildconfigfile);
100 $self->{'starting_num_docs'} = $buildcfg->{'numdocs'};
[12844]101 #print STDERR "- num_docs: $self->{'starting_num_docs'}\n";
[10159]102 $self->{'starting_num_sections'} = $buildcfg->{'numsections'};
[12844]103 #print STDERR "- num_sections: $self->{'starting_num_sections'}\n";
[10159]104 $self->{'starting_num_bytes'} = $buildcfg->{'numbytes'};
[12844]105 #print STDERR "- num_bytes: $self->{'starting_num_bytes'}\n";
[10159]106 }
[12844]107 else
108 {
109 #print STDERR "NOT Found_Num_Data!\n";
110 $self->{'starting_num_docs'} = 0;
[10159]111 $self->{'starting_num_sections'} = 0;
112 $self->{'starting_num_bytes'} = 0;
[12844]113 }
[10159]114
[9919]115 $self->{'output_handle'} = "STDOUT";
[10159]116 $self->{'num_docs'} = $self->{'starting_num_docs'};
117 $self->{'num_sections'} = $self->{'starting_num_sections'};
118 $self->{'num_bytes'} = $self->{'starting_num_bytes'};
119
[9919]120 $self->{'num_processed_bytes'} = 0;
121 $self->{'store_text'} = 1;
122
[15685]123 # what level (section/document) the database - indexer intersection is
124 $self->{'db_level'} = "section";
[9919]125 #used by browse interface
126 $self->{'doclist'} = [];
127
128 $self->{'indexing_text'} = 0;
129
130 return bless $self, $class;
131
132}
133
134sub reset {
135 my $self = shift (@_);
[10159]136
137 $self->{'num_docs'} = $self->{'starting_num_docs'};
138 $self->{'num_sections'} = $self->{'starting_num_sections'};
139 $self->{'num_bytes'} = $self->{'starting_num_bytes'};
[9919]140
141 $self->{'num_processed_bytes'} = 0;
142}
143
[10159]144sub zero_reset {
145 my $self = shift (@_);
146
147 $self->{'num_docs'} = 0;
148 $self->{'num_sections'} = 0;
[17564]149 # reconstructed docs have no text, just metadata, so we need to
150 # remember how many bytes we had initially
[23133]151 #$self->{'num_bytes'} = $self->{'starting_num_bytes'};
152 $self->{'num_bytes'} = 0; # we'll store num bytes in db for reconstructed docs.
[10159]153 $self->{'num_processed_bytes'} = 0;
154}
155
[10419]156sub is_incremental_capable
[10304]157{
158 # By default we return 'no' as the answer
159 # Safer to assume non-incremental to start with, and then override in
160 # inherited classes that are.
161
162 return 0;
163}
164
[9919]165sub get_num_docs {
166 my $self = shift (@_);
167
168 return $self->{'num_docs'};
169}
170
171sub get_num_sections {
172 my $self = shift (@_);
173
174 return $self->{'num_sections'};
175}
176
177# num_bytes is the actual number of bytes in the collection
178# this is normally the same as what's processed during text compression
179sub get_num_bytes {
180 my $self = shift (@_);
181
182 return $self->{'num_bytes'};
183}
184
185# num_processed_bytes is the number of bytes actually passed
186# to mg for the current index
187sub get_num_processed_bytes {
188 my $self = shift (@_);
189
190 return $self->{'num_processed_bytes'};
191}
192
193sub set_output_handle {
194 my $self = shift (@_);
195 my ($handle) = @_;
196
197 $self->{'output_handle'} = $handle;
[25411]198 # The output handle isn't always an actual handle. In a couple of the
199 # database drivers (MSSQL and GDBMServer) it's actually a reference
200 # to an object. Thus we need to test the type before setting binmode.
201 # [jmt12]
202 if (ref $handle eq "GLOB")
203 {
204 binmode($handle,":utf8");
205 }
[9919]206}
207
208
209sub set_mode {
210 my $self = shift (@_);
211 my ($mode) = @_;
212
213 $self->{'mode'} = $mode;
[33302]214 $doc::processor_mode = $mode; # doc.pm needs to know what buildcol pass we're at
[9919]215}
216
[10159]217sub get_mode {
218 my $self = shift (@_);
219
220 return $self->{'mode'};
221}
222
[9919]223sub set_assocdir {
224 my $self = shift (@_);
225 my ($assocdir) = @_;
226
227 $self->{'assocdir'} = $assocdir;
228}
229
[15688]230sub set_dontdb {
[9919]231 my $self = shift (@_);
[15688]232 my ($dontdb) = @_;
[9919]233
[15688]234 $self->{'dontdb'} = $dontdb;
[9919]235}
236
[15725]237sub set_infodbtype
238{
239 my $self = shift(@_);
240 my $infodbtype = shift(@_);
241 $self->{'infodbtype'} = $infodbtype;
242}
243
[9919]244sub set_index {
245 my $self = shift (@_);
246 my ($index, $indexexparr) = @_;
247
248 $self->{'index'} = $index;
249 $self->{'indexexparr'} = $indexexparr if defined $indexexparr;
250}
251
252sub set_index_languages {
253 my $self = shift (@_);
254 my ($lang_meta, $langarr) = @_;
[24404]255 $lang_meta =~ s/^ex\.([^.]+)$/$1/; # strip any ex. namespace iff it's the only namespace prefix (will leave ex.dc.* intact)
256
[9919]257 $self->{'lang_meta'} = $lang_meta;
258 $self->{'langarr'} = $langarr;
259}
260
261sub get_index {
262 my $self = shift (@_);
263
264 return $self->{'index'};
265}
266
267sub set_classifiers {
268 my $self = shift (@_);
269 my ($classifiers) = @_;
270
271 $self->{'classifiers'} = $classifiers;
272}
273
274sub set_indexing_text {
275 my $self = shift (@_);
276 my ($indexing_text) = @_;
277
278 $self->{'indexing_text'} = $indexing_text;
279}
280
281sub get_indexing_text {
282 my $self = shift (@_);
283
284 return $self->{'indexing_text'};
285}
286
287sub set_store_text {
288 my $self = shift (@_);
289 my ($store_text) = @_;
290
291 $self->{'store_text'} = $store_text;
292}
[16222]293
294sub set_store_metadata_coverage {
295 my $self = shift (@_);
296 my ($store_metadata_coverage) = @_;
297
298 $self->{'store_metadata_coverage'} = $store_metadata_coverage || "";
299}
300
[9919]301sub get_doc_list {
302 my $self = shift(@_);
303
304 return @{$self->{'doclist'}};
305}
306
[15685]307# the standard database level is section, but you may want to change it to document
308sub set_db_level {
[9919]309 my $self= shift (@_);
[15685]310 my ($db_level) = @_;
[9919]311
[15685]312 $self->{'db_level'} = $db_level;
[9919]313}
314
[10469]315sub set_sections_index_document_metadata {
316 my $self= shift (@_);
317 my ($index_type) = @_;
318
319 $self->{'sections_index_document_metadata'} = $index_type;
320}
[17110]321
322sub set_separate_cjk {
323 my $self = shift (@_);
324 my ($sep_cjk) = @_;
325
326 $self->{'separate_cjk'} = $sep_cjk;
327}
328
[9919]329sub process {
330 my $self = shift (@_);
331 my $method = $self->{'mode'};
332
333 $self->$method(@_);
334}
335
[17110]336# post process text depending on field. Currently don't do anything here
[17111]337# except cjk separation, and only for indexing
338# should only do this for indexed text (if $self->{'indexing_text'}),
339# but currently search term highlighting doesn't work if you do that.
340# once thats fixed up, then fix this.
[17110]341sub filter_text {
342 my $self = shift (@_);
343 my ($field, $text) = @_;
[14934]344
[17110]345 # lets do cjk seg here
346 my $new_text =$text;
347 if ($self->{'separate_cjk'}) {
348 $new_text = &cnseg::segment($text);
349 }
350 return $new_text;
351}
[14934]352
[17110]353
[14934]354sub infodb_metadata_stats
355{
356 my $self = shift (@_);
[18469]357 my ($field,$edit_mode) = @_;
[14934]358
359 # Keep some statistics relating to metadata sets used and
360 # frequency of particular metadata fields within each set
361
362 # Union of metadata prefixes and frequency of fields
363 # (both scoped for this document alone, and across whole collection)
364
365 if ($field =~ m/^(.+)\.(.*)$/) {
366 my $prefix = $1;
367 my $core_field = $2;
368
[18471]369 if (($edit_mode eq "add") || ($edit_mode eq "update")) {
[18469]370 $self->{'doc_mdprefix_fields'}->{$prefix}->{$core_field}++;
371 $self->{'mdprefix_fields'}->{$prefix}->{$core_field}++;
372 }
373 else {
374 # delete
375 $self->{'doc_mdprefix_fields'}->{$prefix}->{$core_field}--;
376 $self->{'mdprefix_fields'}->{$prefix}->{$core_field}--;
377 }
378
[14934]379 }
380 elsif ($field =~ m/^[[:upper:]]/) {
381 # implicit 'ex' metadata set
382
[18471]383 if (($edit_mode eq "add") || ($edit_mode eq "update")) {
[18469]384
385 $self->{'doc_mdprefix_fields'}->{'ex'}->{$field}++;
386 $self->{'mdprefix_fields'}->{'ex'}->{$field}++;
387 }
388 else {
389 # delete
390 $self->{'doc_mdprefix_fields'}->{'ex'}->{$field}--;
391 $self->{'mdprefix_fields'}->{'ex'}->{$field}--;
392 }
[14934]393 }
394
395}
396
397
[18456]398sub infodbedit {
[9919]399 my $self = shift (@_);
[18456]400 my ($doc_obj, $filename, $edit_mode) = @_;
[35832]401
402 # print STDERR "**** basebuildproc::infodbedit(): $filename, $edit_mode\n";
[23133]403
[15696]404 # only output this document if it is a "indexed_doc" or "info_doc" (database only) document
[9919]405 my $doctype = $doc_obj->get_doc_type();
[11793]406 return if ($doctype ne "indexed_doc" && $doctype ne "info_doc");
[23165]407
[11994]408 my $archivedir = "";
409 if (defined $filename)
410 {
411 # doc_obj derived directly from file
412 my ($dir) = $filename =~ /^(.*?)(?:\/|\\)[^\/\\]*$/;
413 $dir = "" unless defined $dir;
414 $dir =~ s/\\/\//g;
415 $dir =~ s/^\/+//;
416 $dir =~ s/\/+$//;
417
418 $archivedir = $dir;
419
[23182]420 if ($edit_mode eq "delete") {
421 # record this doc so we don't process the reconstructed doc later
422 $self->{'dont_process_reconstructed'}->{$doc_obj->get_OID()} = 1;
423 # we don't need to do anything else for the info database for a deleted document. The infodb starts from scratch each time, so no deletion is necessary
424 $self->delete_assoc_files ($archivedir, "delete");
425 return;
426 }
427 if ($edit_mode eq "update") {
428 # we don't want to process the reconstructed doc later, but we will process this version now.
429 $self->{'dont_process_reconstructed'}->{$doc_obj->get_OID()} = 1;
430 # delete the old assoc files as they may have changed
431 $self->delete_assoc_files ($archivedir, "update");
432 }
433
[11994]434 # resolve the final filenames of the files associated with this document
[23182]435 # now save the new assoc files for an update/new doc.
[11994]436 $self->assoc_files ($doc_obj, $archivedir);
437 }
438 else
439 {
[15688]440 # doc_obj reconstructed from database (has metadata, doc structure but no text)
[11994]441 my $top_section = $doc_obj->get_top_section();
442 $archivedir = $doc_obj->get_metadata_element($top_section,"archivedir");
443 }
444
[23133]445 # rest of code used for add and update. In both cases, we add to the classifiers and to the info database.
446
447 #add this document to the browse structure
448 push(@{$self->{'doclist'}},$doc_obj->get_OID())
449 unless ($doctype eq "classification");
450 $self->{'num_docs'} += 1 unless ($doctype eq "classification");
451
452 if (!defined $filename) {
453 # a reconstructed doc
[23160]454 my $num_reconstructed_bytes = $doc_obj->get_metadata_element ($doc_obj->get_top_section (), "total_numbytes");
455 if (defined $num_reconstructed_bytes) {
456 $self->{'num_bytes'} += $num_reconstructed_bytes;
457 }
[23133]458 }
459 # classify the document
460 &classify::classify_doc ($self->{'classifiers'}, $doc_obj);
461
[23160]462 # now add all the sections to the infodb.
[23133]463
[9919]464 # is this a paged or a hierarchical document
465 my ($thistype, $childtype) = $self->get_document_type ($doc_obj);
466
467 my $section = $doc_obj->get_top_section ();
468 my $doc_OID = $doc_obj->get_OID();
469 my $first = 1;
[15699]470 my $infodb_handle = $self->{'output_handle'};
[14934]471
472 $self->{'doc_mdprefix_fields'} = {};
473
[15695]474 while (defined $section)
475 {
476 my $section_OID = $doc_OID;
477 if ($section ne "")
478 {
479 $section_OID = $doc_OID . "." . $section;
480 }
[15696]481 my %section_infodb = ();
[15695]482
[23133]483 # update a few statistics
484 $self->{'num_bytes'} += $doc_obj->get_text_length ($section);
485 $self->{'num_sections'} += 1 unless ($doctype eq "classification");
486
[9919]487 # output the fact that this document is a document (unless doctype
488 # has been set to something else from within a plugin
489 my $dtype = $doc_obj->get_metadata_element ($section, "doctype");
490 if (!defined $dtype || $dtype !~ /\w/) {
[15697]491 $section_infodb{"doctype"} = [ "doc" ];
[9919]492 }
493
[23133]494 if ($first && defined $filename) {
495 # if we are at the top level of the document, and we are not a reconstructed document, set the total_text_length - used to count bytes when we reconstruct later
496 my $length = $doc_obj->get_total_text_length();
497 $section_infodb{"total_numbytes"} = [ $length ];
498 }
[11994]499 # Output whether this node contains text
500 #
[15688]501 # If doc_obj reconstructed from database file then no need to
[11994]502 # explicitly add <hastxt> as this is preserved as metadata when
[15688]503 # the database file is loaded in
[11994]504 if (defined $filename)
505 {
506 # doc_obj derived directly from file
507 if ($doc_obj->get_text_length($section) > 0) {
[15697]508 $section_infodb{"hastxt"} = [ "1" ];
[11994]509 } else {
[15697]510 $section_infodb{"hastxt"} = [ "0" ];
[11994]511 }
[9919]512 }
513
514 # output all the section metadata
515 my $metadata = $doc_obj->get_all_metadata ($section);
516 foreach my $pair (@$metadata) {
517 my ($field, $value) = (@$pair);
518
519 if ($field ne "Identifier" && $field !~ /^gsdl/ &&
520 defined $value && $value ne "") {
521
522 # escape problematic stuff
[22590]523 $value =~ s/([^\\])\\([^\\])/$1\\\\$2/g;
[9919]524 $value =~ s/\n/\\n/g;
525 $value =~ s/\r/\\r/g;
[24404]526 # remove any ex. iff it's the only namespace prefix (will leave ex.dc.* intact)
527 $field =~ s/^ex\.([^.]+)$/$1/; # $field =~ s/^ex\.//;
[9919]528
[23387]529 # special case for UTF8URL metadata
530 if ($field =~ m/^UTF8URL$/i) {
[23371]531 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle,
532 $value, { 'section' => [ $section_OID ] });
[9919]533 }
[23133]534
[15688]535 if (!defined $self->{'dontdb'}->{$field}) {
[15697]536 push(@{$section_infodb{$field}}, $value);
[14934]537
[24754]538 if ($section eq ""
539 && (($self->{'store_metadata_coverage'} =~ /^true$/i)
540 || $self->{'store_metadata_coverage'} eq "1"))
[14934]541 {
[18469]542 $self->infodb_metadata_stats($field,$edit_mode);
[14934]543 }
[9919]544 }
545 }
546 }
547
[14934]548 if ($section eq "")
549 {
550 my $doc_mdprefix_fields = $self->{'doc_mdprefix_fields'};
[11994]551
[14934]552 foreach my $prefix (keys %$doc_mdprefix_fields)
553 {
[15697]554 push(@{$section_infodb{"metadataset"}}, $prefix);
[14934]555
556 foreach my $field (keys %{$doc_mdprefix_fields->{$prefix}})
557 {
[15708]558 push(@{$section_infodb{"metadatalist-$prefix"}}, $field);
559
[14934]560 my $val = $doc_mdprefix_fields->{$prefix}->{$field};
[15697]561 push(@{$section_infodb{"metadatafreq-$prefix-$field"}}, $val);
[14934]562 }
563 }
564 }
565
[15688]566 # If doc_obj reconstructed from database file then no need to
[11994]567 # explicitly add <archivedir> as this is preserved as metadata when
[15688]568 # the database file is loaded in
[11994]569 if (defined $filename)
570 {
571 # output archivedir if at top level
572 if ($section eq $doc_obj->get_top_section()) {
[15697]573 $section_infodb{"archivedir"} = [ $archivedir ];
[11994]574 }
[9919]575 }
576
577 # output document display type
578 if ($first) {
[15697]579 $section_infodb{"thistype"} = [ $thistype ];
[9919]580 }
581
[15685]582 if ($self->{'db_level'} eq "document") {
[9919]583 # doc num is num_docs not num_sections
584 # output the matching document number
[15697]585 $section_infodb{"docnum"} = [ $self->{'num_docs'} ];
[15696]586 }
587 else {
[9919]588 # output a list of children
589 my $children = $doc_obj->get_children ($section);
590 if (scalar(@$children) > 0) {
[15697]591 $section_infodb{"childtype"} = [ $childtype ];
[15696]592 my $contains = "";
593 foreach my $child (@$children)
594 {
595 $contains .= ";" unless ($contains eq "");
596 if ($child =~ /^.*?\.(\d+)$/)
597 {
598 $contains .= "\".$1";
[9919]599 }
[15698]600 else
601 {
[15696]602 $contains .= "\".$child";
603 }
[9919]604 }
[15697]605 $section_infodb{"contains"} = [ $contains ];
[9919]606 }
[15696]607 # output the matching doc number
[15697]608 $section_infodb{"docnum"} = [ $self->{'num_sections'} ];
[9919]609 }
610
[25556]611 if(defined $section_infodb{'assocfilepath'})
612 {
613 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $section_infodb{'assocfilepath'}[0], { 'contains' => [ $section_OID ]});
614 }
[23133]615 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $section_OID, \%section_infodb);
616
617 # output a database entry for the document number, unless we are incremental
618 unless ($self->is_incremental_capable())
[17106]619 {
[23133]620 if ($self->{'db_level'} eq "document") {
621 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_docs'}, { 'section' => [ $doc_OID ] });
[17106]622 }
623 else {
[23133]624 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_sections'}, { 'section' => [ $section_OID ] });
[17106]625 }
[9919]626 }
[23133]627
[9919]628 $first = 0;
629 $section = $doc_obj->get_next_section($section);
[15685]630 last if ($self->{'db_level'} eq "document"); # if no sections wanted, only add the docs
[23133]631 } # while defined section
632
[15696]633}
[9919]634
[15696]635
[18456]636
637
638sub infodb {
639 my $self = shift (@_);
640 my ($doc_obj, $filename) = @_;
641
642 $self->infodbedit($doc_obj,$filename,"add");
643}
644
645sub infodbreindex {
646 my $self = shift (@_);
647 my ($doc_obj, $filename) = @_;
648
[18471]649 $self->infodbedit($doc_obj,$filename,"update");
[18456]650}
651
652sub infodbdelete {
653 my $self = shift (@_);
654 my ($doc_obj, $filename) = @_;
655
656 $self->infodbedit($doc_obj,$filename,"delete");
657}
658
659
[9919]660sub text {
661 my $self = shift (@_);
662 my ($doc_obj) = @_;
663
664 my $handle = $self->{'outhandle'};
665 print $handle "basebuildproc::text function must be implemented in sub classes\n";
666 die "\n";
667}
668
[18456]669sub textreindex
670{
671 my $self = shift @_;
672
673 my $outhandle = $self->{'outhandle'};
674 print $outhandle "basebuildproc::textreindex function must be implemented in sub classes\n";
675 if (!$self->is_incremental_capable()) {
676
677 print $outhandle " This operation is only possible with indexing tools with that support\n";
678 print $outhandle " incremental building\n";
679 }
680 die "\n";
681}
682
683sub textdelete
684{
685 my $self = shift @_;
686
687 my $outhandle = $self->{'outhandle'};
688 print $outhandle "basebuildproc::textdelete function must be implemented in sub classes\n";
689 if (!$self->is_incremental_capable()) {
690
691 print $outhandle " This operation is only possible with indexing tools with that support\n";
692 print $outhandle " incremental building\n";
693 }
694 die "\n";
695}
696
697
[9919]698# should the document be indexed - according to the subcollection and language
699# specification.
700sub is_subcollection_doc {
701 my $self = shift (@_);
702 my ($doc_obj) = @_;
703
704 my $indexed_doc = 1;
705 foreach my $indexexp (@{$self->{'indexexparr'}}) {
706 $indexed_doc = 0;
707 my ($field, $exp, $options) = split /\//, $indexexp;
708 if (defined ($field) && defined ($exp)) {
709 my ($bool) = $field =~ /^(.)/;
710 $field =~ s/^.// if $bool eq '!';
[10028]711 my @metadata_values;
[9919]712 if ($field =~ /^filename$/i) {
[10028]713 push(@metadata_values, $doc_obj->get_source_filename());
[9919]714 }
[10028]715 else {
[24404]716 $field =~ s/^ex\.([^.]+)$/$1/; # remove any ex. iff it's the only namespace prefix (will leave ex.dc.* intact)
[10028]717 @metadata_values = @{$doc_obj->get_metadata($doc_obj->get_top_section(), $field)};
718 }
719 next unless @metadata_values;
720 foreach my $metadata_value (@metadata_values) {
721 if ($bool eq '!') {
[27917]722 if (defined $options && $options =~ /^i$/i) {
[10028]723 if ($metadata_value !~ /$exp/i) {$indexed_doc = 1; last;}
724 } else {
725 if ($metadata_value !~ /$exp/) {$indexed_doc = 1; last;}
726 }
[9919]727 } else {
[27917]728 if (defined $options && $options =~ /^i$/i) {
[10028]729 if ($metadata_value =~ /$exp/i) {$indexed_doc = 1; last;}
730 } else {
731 if ($metadata_value =~ /$exp/) {$indexed_doc = 1; last;}
732 }
[9919]733 }
734 }
[10028]735
736 last if ($indexed_doc == 1);
[9919]737 }
738 }
739
740 # if this doc is so far in the sub collection, and we have lang info,
741 # now we check the languages to see if it matches
742 if($indexed_doc && defined $self->{'lang_meta'}) {
743 $indexed_doc = 0;
744 my $field = $doc_obj->get_metadata_element($doc_obj->get_top_section(), $self->{'lang_meta'});
745 if (defined $field) {
746 foreach my $lang (@{$self->{'langarr'}}) {
747 my ($bool) = $lang =~ /^(.)/;
748 if ($bool eq '!') {
749 $lang =~ s/^.//;
750 if ($field !~ /$lang/) {
751 $indexed_doc = 1; last;
752 }
753 } else {
754 if ($field =~ /$lang/) {
755 $indexed_doc = 1; last;
756 }
757 }
758 }
759 }
760 }
761 return $indexed_doc;
762
763}
764
765# use 'Paged' if document has no more than 2 levels
766# and each section at second level has a number for
767# Title metadata
768# also use Paged if gsdlthistype metadata is set to Paged
769sub get_document_type {
770 my $self = shift (@_);
771 my ($doc_obj) = @_;
772
773 my $thistype = "VList";
774 my $childtype = "VList";
775 my $title;
776 my @tmp = ();
777
778 my $section = $doc_obj->get_top_section ();
779
780 my $gsdlthistype = $doc_obj->get_metadata_element ($section, "gsdlthistype");
781 if (defined $gsdlthistype) {
[25959]782 if ($gsdlthistype =~ /^paged$/i) {
[9919]783 $childtype = "Paged";
784 if ($doc_obj->get_text_length ($doc_obj->get_top_section())) {
785 $thistype = "Paged";
786 } else {
787 $thistype = "Invisible";
788 }
789
790 return ($thistype, $childtype);
[25959]791 }
792 # gs3 pagedhierarchy option
793 elsif ($gsdlthistype =~ /^pagedhierarchy$/i) {
794 $childtype = "PagedHierarchy";
795 if ($doc_obj->get_text_length ($doc_obj->get_top_section())) {
796 $thistype = "PagedHierarchy";
797 } else {
798 $thistype = "Invisible";
799 }
800
801 return ($thistype, $childtype);
802 } elsif ($gsdlthistype =~ /^hierarchy$/i) {
[9919]803 return ($thistype, $childtype); # use VList, VList
804 }
805 }
806 my $first = 1;
807 while (defined $section) {
808 @tmp = split /\./, $section;
809 if (scalar(@tmp) > 1) {
810 return ($thistype, $childtype);
811 }
812 if (!$first) {
813 $title = $doc_obj->get_metadata_element ($section, "Title");
814 if (!defined $title || $title !~ /^\d+$/) {
815 return ($thistype, $childtype);
816 }
817 }
818 $first = 0;
819 $section = $doc_obj->get_next_section($section);
820 }
821 if ($doc_obj->get_text_length ($doc_obj->get_top_section())) {
822 $thistype = "Paged";
823 } else {
824 $thistype = "Invisible";
825 }
826 $childtype = "Paged";
827 return ($thistype, $childtype);
828}
829
[18456]830sub assoc_files
831{
[9919]832 my $self = shift (@_);
833 my ($doc_obj, $archivedir) = @_;
834 my ($afile);
835
836 foreach my $assoc_file (@{$doc_obj->get_assoc_files()}) {
[12844]837 #rint STDERR "Processing associated file - copy " . $assoc_file->[0] . " to " . $assoc_file->[1] . "\n";
[9919]838 # if assoc file starts with a slash, we put it relative to the assoc
839 # dir, otherwise it is relative to the HASH... directory
840 if ($assoc_file->[1] =~ m@^[/\\]@) {
[27306]841 $afile = &FileUtils::filenameConcatenate($self->{'assocdir'}, $assoc_file->[1]);
[9919]842 } else {
[27306]843 $afile = &FileUtils::filenameConcatenate($self->{'assocdir'}, $archivedir, $assoc_file->[1]);
[9919]844 }
[25556]845
[27306]846 &FileUtils::hardLink($assoc_file->[0], $afile, $self->{'verbosity'});
[9919]847 }
848}
849
[23176]850sub delete_assoc_files
851{
852 my $self = shift (@_);
[23182]853 my ($archivedir, $edit_mode) = @_;
[23176]854
[27306]855 my $assoc_dir = &FileUtils::filenameConcatenate($self->{'assocdir'}, $archivedir);
[23176]856 if (-d $assoc_dir) {
[27306]857 &FileUtils::removeFilesRecursive($assoc_dir);
[23176]858 }
859}
Note: See TracBrowser for help on using the repository browser.