1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # AutoExtractMetadata.pm -- base plugin for all plugins that want to do metadata extraction from text and/or metadata
|
---|
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) 2008 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 plugin uses the supporting Extractors to add metadata extraction
|
---|
27 | # functionality to BasePlugin.
|
---|
28 |
|
---|
29 |
|
---|
30 | package AutoExtractMetadata;
|
---|
31 |
|
---|
32 | use strict;
|
---|
33 | no strict 'subs';
|
---|
34 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
35 |
|
---|
36 | use BasePlugin;
|
---|
37 | use AcronymExtractor;
|
---|
38 | use KeyphraseExtractor;
|
---|
39 | use EmailAddressExtractor;
|
---|
40 | use DateExtractor;
|
---|
41 | use GISExtractor;
|
---|
42 |
|
---|
43 | sub BEGIN {
|
---|
44 | @AutoExtractMetadata::ISA = ( 'BasePlugin', 'AcronymExtractor', 'KeyphraseExtractor', 'EmailAddressExtractor', 'DateExtractor', 'GISExtractor' );
|
---|
45 | }
|
---|
46 |
|
---|
47 | my $arguments = [];
|
---|
48 |
|
---|
49 |
|
---|
50 | my $options = { 'name' => "AutoExtractMetadata",
|
---|
51 | 'desc' => "{AutoExtractMetadata.desc}",
|
---|
52 | 'abstract' => "yes",
|
---|
53 | 'inherits' => "no",
|
---|
54 | 'args' => $arguments };
|
---|
55 |
|
---|
56 |
|
---|
57 | sub new {
|
---|
58 |
|
---|
59 | # Start the AutoExtractMetadata Constructor
|
---|
60 | my $class = shift (@_);
|
---|
61 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
62 | push(@$pluginlist, $class);
|
---|
63 |
|
---|
64 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
65 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
66 |
|
---|
67 | # load up the options and args for the supporting plugins
|
---|
68 | new AcronymExtractor($pluginlist, $inputargs, $hashArgOptLists);
|
---|
69 | new KeyphraseExtractor($pluginlist, $inputargs, $hashArgOptLists);
|
---|
70 | new EmailAddressExtractor($pluginlist, $inputargs, $hashArgOptLists);
|
---|
71 | new DateExtractor($pluginlist, $inputargs, $hashArgOptLists);
|
---|
72 | new GISExtractor($pluginlist, $inputargs, $hashArgOptLists);
|
---|
73 |
|
---|
74 | my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
|
---|
75 |
|
---|
76 | return bless $self, $class;
|
---|
77 |
|
---|
78 | }
|
---|
79 |
|
---|
80 | sub begin {
|
---|
81 | my $self = shift (@_);
|
---|
82 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
83 |
|
---|
84 | #initialise those extractors that need initialisation
|
---|
85 | $self->initialise_acronym_extractor();
|
---|
86 | }
|
---|
87 |
|
---|
88 | sub end {
|
---|
89 | # potentially called at the end of each plugin pass
|
---|
90 | # import.pl only has one plugin pass, but buildcol.pl has multiple ones
|
---|
91 |
|
---|
92 | my ($self) = @_;
|
---|
93 | # finalise those extractors that need finalisation
|
---|
94 | $self->finalise_acronym_extractor();
|
---|
95 | }
|
---|
96 |
|
---|
97 | # here is where we call methods from the supporting plugins - gis and textextract
|
---|
98 | sub auto_extract_metadata {
|
---|
99 | my $self = shift(@_);
|
---|
100 | my ($doc_obj) = @_;
|
---|
101 |
|
---|
102 | $self->extract_acronym_metadata($doc_obj);
|
---|
103 | $self->extract_keyphrase_metadata($doc_obj);
|
---|
104 | $self->extract_email_metadata($doc_obj);
|
---|
105 | $self->extract_date_metadata($doc_obj);
|
---|
106 | $self->extract_gis_metadata($doc_obj);
|
---|
107 |
|
---|
108 | }
|
---|
109 |
|
---|
110 | sub clean_up_after_doc_obj_processing {
|
---|
111 | my $self = shift(@_);
|
---|
112 |
|
---|
113 | $self->SUPER::clean_up_after_doc_obj_processing();
|
---|
114 | $self->GISExtractor::clean_up_temp_files();
|
---|
115 | }
|
---|
116 |
|
---|
117 | 1;
|
---|