source: trunk/gsdl/perllib/plugins/BasPlug.pm@ 2755

Last change on this file since 2755 was 2755, checked in by jrm21, 23 years ago

import.pl now takes an option for saving file conversion failures to a log.
By default, import.pl will use <collectdir>/etc/fail.log. Currently only
the plugins based on ConvertToPlug will do this. Not yet tested on Win9X.

  • Property svn:keywords set to Author Date Id Revision
File size: 23.9 KB
Line 
1###########################################################################
2#
3# BasPlug.pm -- base class for all the import plugins
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
26package BasPlug;
27
28# suppress the annoying "subroutine redefined" warning that various
29# plugins cause under perl 5.6
30$SIG{__WARN__} = sub {warn($_[0]) unless ($_[0] =~ /Subroutine\s+\S+\sredefined/)};
31
32use Kea;
33use parsargv;
34use multiread;
35use encodings;
36use cnseg;
37use acronym;
38use textcat;
39use doc;
40use diagnostics;
41use DateExtract;
42use ghtml;
43
44sub print_general_usage {
45 my ($plugin_name) = @_;
46
47 print STDERR "\n usage: plugin $plugin_name [options]\n\n";
48
49 print STDERR " -process_exp A perl regular expression to match against filenames.\n";
50 print STDERR " Matching filenames will be processed by this plugin.\n";
51 print STDERR " Each plugin has its own default process_exp. e.g HTMLPlug\n";
52 print STDERR " defaults to '(?i)\.html?\$' i.e. all documents ending in\n";
53 print STDERR " .htm or .html (case-insensitive).\n\n";
54
55 print STDERR " -block_exp Files matching this regular expression will be blocked from\n";
56 print STDERR " being passed to any later plugins in the list. This has no\n";
57 print STDERR " real effect other than to prevent lots of warning messages\n";
58 print STDERR " about input files you don't care about. Each plugin might\n";
59 print STDERR " have a default block_exp. e.g. by default HTMLPlug blocks\n";
60 print STDERR " any files with .gif, .jpg, .jpeg, .png or .css\n";
61 print STDERR " file extensions.\n\n";
62
63
64 print STDERR " -input_encoding The encoding of the source documents. Documents will be\n";
65 print STDERR " converted from these encodings and stored internally as\n";
66 print STDERR " utf8. The default input_encoding is 'auto'. Accepted values\n";
67 print STDERR " are:\n";
68
69 print STDERR " auto: Use text categorization algorithm to automatically\n";
70 print STDERR " identify the encoding of each source document. This\n";
71 print STDERR " will be slower than explicitly setting the encoding\n";
72 print STDERR " but will work where more than one encoding is used\n";
73 print STDERR " within the same collection.\n";
74
75 print STDERR " ascii: Plain 7 bit ascii. This may be a bit faster than\n";
76 print STDERR " using iso_8859_1. Beware of using this on a collection\n";
77 print STDERR " of documents that may contain characters outside the\n";
78 print STDERR " plain 7 bit ascii set though (e.g. German or French\n";
79 print STDERR " documents containing accents), use iso_8859_1 instead.\n";
80
81 print STDERR " utf8: either utf8 or unicode -- automatically detected\n";
82 print STDERR " unicode: just unicode\n";
83
84 my $e = $encodings::encodings;
85 foreach my $enc (sort {$e->{$a}->{'name'} cmp $e->{$b}->{'name'}} keys (%$e)) {
86 print STDERR " $enc: $e->{$enc}->{'name'}\n";
87 }
88 print STDERR "\n";
89 print STDERR " -default_encoding Use this encoding if -input_encoding is set to 'auto' and\n";
90 print STDERR " the text categorization algorithm fails to extract the\n";
91 print STDERR " encoding or extracts an encoding unsupported by Greenstone.\n";
92 print STDERR " The default is iso_8859_1.\n\n";
93
94 print STDERR " -extract_language Identify the language of each document and set 'Language'\n";
95 print STDERR " metadata. Note that this will be done automatically if\n";
96 print STDERR " -input_encoding is 'auto'.\n\n";
97 print STDERR " -default_language If Greenstone fails to work out what language a document is\n";
98 print STDERR " the 'Language' metadata element will be set to this value.\n";
99 print STDERR " The default is 'en' (ISO 639 language symbols are used:\n";
100 print STDERR " en = English). Note that if -input_encoding is not set to\n";
101 print STDERR " 'auto' and -extract_language is not set, all documents will\n";
102 print STDERR " have their 'Language' metadata set to this value.\n\n";
103
104 print STDERR " -extract_acronyms Extract acronyms from within text and set as metadata\n";
105
106 print STDERR " -markup_acronyms Add acronym metadata into document text\n\n";
107
108 print STDERR " -first Comma separated list of first sizes to extract from the\n";
109 print STDERR " text into a metadata field. The field is called 'FirstNNN'.\n\n";
110
111 print STDERR " -extract_email Extract email addresses as metadata\n\n";
112
113 print STDERR " -extract_date Extract dates pertaining to the content of documents about\n";
114 print STDERR " history\n";
115 print STDERR " -maximum_date The maximum historical date to be used as metadata (in a\n";
116 print STDERR " Common Era date, such as 1950)\n";
117 print STDERR " -maximum_century The maximum named century to be extracted as historical\n";
118 print STDERR " metadata (e.g. 14 will extract all references up to the\n";
119 print STDERR " 14th century)\n";
120 print STDERR " -no_bibliography Do not try and block bibliographic dates when extracting\n";
121 print STDERR " historical dates.\n\n";
122}
123
124# print_usage should be overridden for any sub-classes having
125# their own plugin specific options
126sub print_usage {
127 print STDERR "\nThis plugin has no plugin specific options\n\n";
128}
129
130sub new {
131 my $class = shift (@_);
132 my $plugin_name = shift (@_);
133 my $self = {};
134
135 my $enc = "^(";
136 map {$enc .= "$_|";} keys %$encodings::encodings;
137 my $denc = $enc . "ascii|utf8|unicode)\$";
138 $enc .= "ascii|utf8|unicode|auto)\$";
139
140 $self->{'outhandle'} = STDERR;
141 my $year = (localtime)[5]+1900;
142
143 $self->{'textcat'} = new textcat();
144
145 # general options available to all plugins
146 if (!parsargv::parse(\@_,
147 q^process_exp/.*/^, \$self->{'process_exp'},
148 q^block_exp/.*/^, \$self->{'block_exp'},
149 q^extract_acronyms^, \$self->{'extract_acronyms'},
150 q^extract_keyphrases^, \$self->{'kea'}, #with extra options
151 q^extract_keyphrase_options/.*/^, \$self->{'kea_options'}, #no extra options
152 qq^input_encoding/$enc/auto^, \$self->{'input_encoding'},
153 qq^default_encoding/$denc/iso_8859_1^, \$self->{'default_encoding'},
154 q^extract_email^, \$self->{'extract_email'},
155 q^markup_acronyms^, \$self->{'markup_acronyms'},
156 q^default_language/.{2}/en^, \$self->{'default_language'},
157 q^first/.*/^, \$self->{'first'},
158 q^extract_date^, \$self->{'date_extract'},
159 qq^maximum_date/\\d{4}/$year^, \$self->{'max_year'},
160 q^no_bibliography^, \$self->{'no_biblio'},
161 qq^maximum_century/-?\\d{1,2}( ?B\\.C\\.E\\.)?/-1^, \$self->{'max_century'},
162 "allow_extra_options")) {
163
164 print STDERR "\nThe $plugin_name plugin uses an incorrect general option (general options are those\n";
165 print STDERR "available to all plugins). Check your collect.cfg configuration file.\n";
166 &print_general_usage($plugin_name);
167 die "\n";
168 }
169
170 return bless $self, $class;
171}
172
173# initialize BasPlug options
174# if init() is overridden in a sub-class, remember to call BasPlug::init()
175sub init {
176 my $self = shift (@_);
177 my ($verbosity, $outhandle, $faillogname) = @_;
178
179 # verbosity is passed through from the processor
180 $self->{'verbosity'} = $verbosity;
181
182 # as is the outhandle ...
183 $self->{'outhandle'} = $outhandle if defined $outhandle;
184 $self->{'faillogname'} = $faillogname;
185
186 # set process_exp and block_exp to defaults unless they were
187 # explicitly set
188
189 if ((!$self->is_recursive()) and
190 (!defined $self->{'process_exp'}) || ($self->{'process_exp'} eq "")) {
191
192 $self->{'process_exp'} = $self->get_default_process_exp ();
193 if ($self->{'process_exp'} eq "") {
194 warn ref($self) . " Warning: Non-recursive plugin has no process_exp\n";
195 }
196 }
197
198 if ((!defined $self->{'block_exp'}) || ($self->{'block_exp'} eq "")) {
199 $self->{'block_exp'} = $self->get_default_block_exp ();
200 }
201}
202
203sub begin {
204 my $self = shift (@_);
205 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
206 $self->initialise_extractors();
207}
208
209sub end {
210 my ($self) = @_;
211 $self->finalise_extractors();
212}
213
214# this function should be overridden to return 1
215# in recursive plugins
216sub is_recursive {
217 my $self = shift (@_);
218
219 return 0;
220}
221
222sub get_default_block_exp {
223 my $self = shift (@_);
224
225 return "";
226}
227
228sub get_default_process_exp {
229 my $self = shift (@_);
230
231 return "";
232}
233
234# The BasPlug read() function. This function does all the right things
235# to make general options work for a given plugin. It calls the process()
236# function which does all the work specific to a plugin (like the old
237# read functions used to do). Most plugins should define their own
238# process() function and let this read() function keep control.
239#
240# recursive plugins (e.g. RecPlug) and specialized plugins like those
241# capable of processing many documents within a single file (e.g.
242# GMLPlug) should normally implement their own version of read()
243#
244# Return number of files processed, undef if can't process
245# Note that $base_dir might be "" and that $file might
246# include directories
247
248sub read {
249 my $self = shift (@_);
250
251 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs) = @_;
252
253 if ($self->is_recursive()) {
254 die "BasPlug::read function must be implemented in sub-class for recursive plugins\n";
255 }
256
257 my $outhandle = $self->{'outhandle'};
258
259 my $filename = &util::filename_cat($base_dir, $file);
260 return 0 if $self->{'block_exp'} ne "" && $filename =~ /$self->{'block_exp'}/;
261 if ($filename !~ /$self->{'process_exp'}/ || !-f $filename) {
262 return undef;
263 }
264 my $plugin_name = ref ($self);
265 $file =~ s/^[\/\\]+//; # $file often begins with / so we'll tidy it up
266
267 my ($language, $encoding);
268 if ($self->{'input_encoding'} eq "auto") {
269 # use textcat to automatically work out the input encoding and language
270 ($language, $encoding) = $self->get_language_encoding ($filename);
271
272 } elsif ($self->{'extract_language'}) {
273 # use textcat to get language metadata
274 ($language, $extracted_encoding) = $self->get_language_encoding ($filename);
275 $encoding = $self->{'input_encoding'};
276
277 if ($extracted_encoding ne $encoding && $self->{'verbosity'}) {
278 print $outhandle "$plugin_name: WARNING: $file was read using $encoding encoding but ";
279 print $outhandle "appears to be encoded as $extracted_encoding.\n";
280 }
281
282 } else {
283 $language = $self->{'default_language'};
284 $encoding = $self->{'input_encoding'};
285 }
286
287 # create a new document
288 my $doc_obj = new doc ($filename, "indexed_doc");
289 $doc_obj->set_OIDtype ($processor->{'OIDtype'});
290 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Language", $language);
291 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Encoding", $encoding);
292 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Source", &ghtml::dmsafe($file));
293
294 # read in file ($text will be in utf8)
295 my $text = "";
296 $self->read_file ($filename, $encoding, $language, \$text);
297
298 if (!length ($text)) {
299 print $outhandle "$plugin_name: ERROR: $file contains no text\n" if $self->{'verbosity'};
300 return 0;
301 }
302
303 # include any metadata passed in from previous plugins
304 # note that this metadata is associated with the top level section
305 $self->extra_metadata ($doc_obj, $doc_obj->get_top_section(), $metadata);
306
307 # do plugin specific processing of doc_obj
308 return undef unless defined ($self->process (\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj));
309
310 # do any automatic metadata extraction
311 $self->auto_extract_metadata ($doc_obj);
312
313 # add an OID
314 $doc_obj->set_OID();
315
316 # process the document
317 $processor->process($doc_obj);
318
319 return 1; # processed the file
320}
321
322# returns undef if file is rejected by the plugin
323sub process {
324 my $self = shift (@_);
325 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
326
327 die "Basplug::process function must be implemented in sub-class\n";
328
329 return undef; # never gets here
330}
331
332# uses the multiread package to read in the entire file pointed to
333# by filename and loads the resulting text into $$textref. Input text
334# may be in any of the encodings handled by multiread, output text
335# will be in utf8
336sub read_file {
337 my $self = shift (@_);
338 my ($filename, $encoding, $language, $textref) = @_;
339
340 if (!-r $filename)
341 {
342 my $outhandle = $self->{'outhandle'};
343 print $outhandle "Read permission denied for $filename\n" if $self->{'verbosity'};
344 return;
345 }
346
347 $$textref = "";
348
349 open (FILE, $filename) || die "BasPlug::read_file could not open $filename for reading ($!)\n";
350
351 if ($encoding eq "ascii") {
352 undef $/;
353 $$textref = <FILE>;
354 $/ = "\n";
355 } else {
356 my $reader = new multiread();
357 $reader->set_handle ('BasPlug::FILE');
358 $reader->set_encoding ($encoding);
359 $reader->read_file ($textref);
360
361 if ($language eq "zh") {
362 # segment the Chinese words
363 $$textref = &cnseg::segment($$textref);
364 }
365 }
366
367 close FILE;
368}
369
370# Uses textcat to work out the encoding and language of the text in
371# $filename. All html tags are removed before processing.
372# returns an array containing "language" and "encoding"
373sub get_language_encoding {
374 my $self = shift (@_);
375 my ($filename) = @_;
376 my $outhandle = $self->{'outhandle'};
377
378 # read in file
379 open (FILE, $filename) || die "BasPlug::get_language_encoding could not open $filename for reading ($!)\n";
380 undef $/;
381 my $text = <FILE>;
382 $/ = "\n";
383 close FILE;
384
385 # remove <title>stuff</title> -- as titles tend often to be in English
386 # for foreign language documents
387 $text =~ s/<title>.*?<\/title>//i;
388
389 # remove all HTML tags
390 $text =~ s/<[^>]*>//sg;
391
392 # get the language/encoding
393 my $results = $self->{'textcat'}->classify(\$text);
394
395 # if textcat returns 3 or less possibilities we'll use the
396 # first one in the list - otherwise use the defaults
397 if (scalar @$results > 3) {
398
399 if ($self->{'input_encoding'} ne 'auto') {
400 if ($self->{'extract_language'} && $self->{'verbosity'}) {
401 print $outhandle "BasPlug: WARNING: language could not be extracted from $filename - ";
402 print $outhandle "defaulting to $self->{'default_language'}\n";
403 }
404 return ($self->{'default_language'}, $self->{'input_encoding'});
405
406 } else {
407 if ($self->{'verbosity'}) {
408 print $outhandle "BASPlug: WARNING: language/encoding could not be extracted from $filename - ";
409 print $outhandle "defaulting to $self->{'default_language'}/$self->{'default_encoding'}\n";
410 }
411 return ($self->{'default_language'}, $self->{'default_encoding'});
412 }
413 }
414
415 # format language/encoding
416 my ($language, $encoding) = $results->[0] =~ /^([^-]*)(?:-(.*))?$/;
417 if (!defined $language) {
418 if ($self->{'verbosity'}) {
419 print $outhandle "BasPlug: WARNING: language could not be extracted from $filename - ";
420 print $outhandle "defaulting to $self->{'default_language'}\n";
421 }
422 $language = $self->{'default_language'};
423 }
424 if (!defined $encoding) {
425 if ($self->{'verbosity'}) {
426 print $outhandle "BasPlug: WARNING: encoding could not be extracted from $filename - ";
427 print $outhandle "defaulting to $self->{'default_encoding'}\n";
428 }
429 $encoding = $self->{'default_encoding'};
430 }
431
432 if ($encoding !~ /^(ascii|utf8|unicode)$/ &&
433 !defined $encodings::encodings->{$encoding}) {
434 if ($self->{'verbosity'}) {
435 print $outhandle "BasPlug: WARNING: $filename appears to be encoded in an unsupported encoding ($encoding) - ";
436 print $outhandle "using $self->{'default_encoding'}\n";
437 }
438 $encoding = $self->{'default_encoding'};
439 }
440
441 return ($language, $encoding);
442}
443
444# add any extra metadata that's been passed around from one
445# plugin to another.
446# extra_metadata uses add_utf8_metadata so it expects metadata values
447# to already be in utf8
448sub extra_metadata {
449 my $self = shift (@_);
450 my ($doc_obj, $cursection, $metadata) = @_;
451
452 foreach my $field (keys(%$metadata)) {
453 # $metadata->{$field} may be an array reference
454 if (ref ($metadata->{$field}) eq "ARRAY") {
455 map {
456 $doc_obj->add_utf8_metadata ($cursection, $field, $_);
457 } @{$metadata->{$field}};
458 } else {
459 $doc_obj->add_utf8_metadata ($cursection, $field, $metadata->{$field});
460 }
461 }
462}
463
464# initialise metadata extractors
465sub initialise_extractors {
466 my $self = shift (@_);
467
468 if ($self->{'extract_acronyms'} || $self->{'markup_acronyms'}) {
469 &acronym::initialise_acronyms();
470 }
471}
472
473# finalise metadata extractors
474sub finalise_extractors {
475 my $self = shift (@_);
476
477 if ($self->{'extract_acronyms'} || $self->{'markup_acronyms'}) {
478 &acronym::finalise_acronyms();
479 }
480}
481
482# FIRSTNNN: extract the first NNN characters as metadata
483sub extract_first_NNNN_characters {
484 my $self = shift (@_);
485 my ($textref, $doc_obj, $thissection) = @_;
486
487 foreach my $size (split /,/, $self->{'first'}) {
488 my $tmptext = $$textref;
489 $tmptext =~ s/^\s+//;
490 $tmptext =~ s/\s+$//;
491 $tmptext =~ s/\s+/ /gs;
492 $tmptext = substr ($tmptext, 0, $size);
493 $tmptext =~ s/\s\S*$/&#8230;/;
494 $doc_obj->add_utf8_metadata ($thissection, "First$size", $tmptext);
495 }
496}
497
498sub extract_email {
499 my $self = shift (@_);
500 my ($textref, $doc_obj, $thissection) = @_;
501 my $outhandle = $self->{'outhandle'};
502
503 print $outhandle " extracting email addresses ...\n"
504 if ($self->{'verbosity'} > 2);
505
506 my @email = ($$textref =~ m/([-a-z0-9\.@+_=]+@(?:[-a-z0-9]+\.)+(?:com|org|edu|mil|int|net|[a-z][a-z]))/g);
507 @email = sort @email;
508
509 my @email2 = ();
510 foreach my $address (@email) {
511 if (!(join(" ",@email2) =~ m/$address/ )) {
512 push @email2, $address;
513 $doc_obj->add_utf8_metadata ($thissection, "emailAddress", $address);
514 print $outhandle " extracting $address\n"
515 if ($self->{'verbosity'} > 3);
516 }
517 }
518 print $outhandle " done extracting email addresses.\n"
519 if ($self->{'verbosity'} > 2);
520
521}
522
523# extract metadata
524sub auto_extract_metadata {
525
526
527 my $self = shift (@_);
528 my ($doc_obj) = @_;
529
530 if ($self->{'extract_email'}) {
531 my $thissection = $doc_obj->get_top_section();
532 while (defined $thissection) {
533 my $text = $doc_obj->get_text($thissection);
534 $self->extract_email (\$text, $doc_obj, $thissection) if $text =~ /./;
535 $thissection = $doc_obj->get_next_section ($thissection);
536 }
537 }
538
539
540#adding kea keyphrases
541 if ($self->{'kea'}) {
542
543 my $thissection = $doc_obj->get_top_section();
544 my $text = "";
545 my @list;
546
547 while (defined $thissection) { #loop through sections to gather whole doc
548 my $sectiontext = $doc_obj->get_text($thissection);
549 $text = $text.$sectiontext;
550 $thissection = $doc_obj->get_next_section ($thissection);
551 }
552
553 if($self->{'kea_options'}) { #if kea options flag is set, call Kea with specified options
554 @list = &Kea::extract_KeyPhrases ($text, $self->{'kea_options'});
555 } else { #otherwise call Kea with no options
556 @list = &Kea::extract_KeyPhrases ($text);
557 }
558
559 if(@list){ #if a list of kea keyphrases was returned (ie not empty)
560 my $keyphrases = $list[0]; #first arg is keyphrase list
561 my $stems = $list[1]; #second arg is stemmed keyphrase list
562 print STDERR "keyphrases: $keyphrases\n";
563 print STDERR "stems: $stems\n";
564 $thissection = $doc_obj->get_top_section(); #add metadata to top section
565 $doc_obj->add_metadata($thissection, "kea", $keyphrases);
566 $doc_obj->add_metadata($thissection, "stems", $stems);
567 }
568 } #end of kea
569
570 if ($self->{'first'}) {
571 my $thissection = $doc_obj->get_top_section();
572 while (defined $thissection) {
573 my $text = $doc_obj->get_text($thissection);
574 $self->extract_first_NNNN_characters (\$text, $doc_obj, $thissection) if $text =~ /./;
575 $thissection = $doc_obj->get_next_section ($thissection);
576 }
577 }
578
579 if ($self->{'extract_acronyms'}) {
580 my $thissection = $doc_obj->get_top_section();
581 while (defined $thissection) {
582 my $text = $doc_obj->get_text($thissection);
583 $self->extract_acronyms (\$text, $doc_obj, $thissection) if $text =~ /./;
584 $thissection = $doc_obj->get_next_section ($thissection);
585 }
586 }
587
588 if ($self->{'markup_acronyms'}) {
589 my $thissection = $doc_obj->get_top_section();
590 while (defined $thissection) {
591 my $text = $doc_obj->get_text($thissection);
592 $text = $self->markup_acronyms ($text, $doc_obj, $thissection);
593 $doc_obj->delete_text($thissection);
594 $doc_obj->add_text($thissection, $text);
595 $thissection = $doc_obj->get_next_section ($thissection);
596 }
597 }
598
599 if($self->{'date_extract'}) {
600 my $thissection = $doc_obj->get_top_section();
601 while (defined $thissection) {
602
603 my $text = $doc_obj->get_text($thissection);
604 &DateExtract::get_date_metadata($text, $doc_obj,
605 $thissection,
606 $self->{'no_biblio'},
607 $self->{'max_year'},
608 $self->{'max_century'});
609 $thissection = $doc_obj->get_next_section ($thissection);
610 }
611 }
612}
613
614# extract acronyms from a section in a document. progress is
615# reported to outhandle based on the verbosity. both the Acronym
616# and the AcronymKWIC metadata items are created.
617
618sub extract_acronyms {
619 my $self = shift (@_);
620 my ($textref, $doc_obj, $thissection) = @_;
621 my $outhandle = $self->{'outhandle'};
622
623 print $outhandle " extracting acronyms ...\n"
624 if ($self->{'verbosity'} > 2);
625
626 my $acro_array = &acronym::acronyms($textref);
627
628 foreach my $acro (@$acro_array) {
629
630 #check that this is the first time ...
631 my $seen_before = "false";
632 my $previous_data = $doc_obj->get_metadata($thissection, "Acronym");
633 foreach my $thisAcro (@$previous_data) {
634 if ($thisAcro eq $acro->to_string()) {
635 $seen_before = "true";
636 print $outhandle " already seen ". $acro->to_string() . "\n"
637 if ($self->{'verbosity'} >= 4);
638 }
639 }
640
641 if ($seen_before eq "false") {
642 #write it to the file ...
643 $acro->write_to_file();
644
645 #do the normal acronym
646 $doc_obj->add_utf8_metadata($thissection, "Acronym", $acro->to_string());
647 print $outhandle " adding ". $acro->to_string() . "\n"
648 if ($self->{'verbosity'} > 3);
649
650 }
651 }
652 print $outhandle " done extracting acronyms. \n"
653 if ($self->{'verbosity'} > 2);
654}
655
656sub markup_acronyms {
657 my $self = shift (@_);
658 my ($text, $doc_obj, $thissection) = @_;
659 my $outhandle = $self->{'outhandle'};
660
661 print $outhandle " marking up acronyms ...\n"
662 if ($self->{'verbosity'} > 2);
663
664 #self is passed in to check for verbosity ...
665 $text = &acronym::markup_acronyms($text, $self);
666
667 print $outhandle " done marking up acronyms. \n"
668 if ($self->{'verbosity'} > 2);
669
670 return $text;
671}
672
6731;
Note: See TracBrowser for help on using the repository browser.