[1483] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # BasClas.pm -- base class for all classifiers
|
---|
[1884] | 4 | #
|
---|
[1483] | 5 | # A component of the Greenstone digital library software
|
---|
| 6 | # from the New Zealand Digital Library Project at the
|
---|
| 7 | # University of Waikato, New Zealand.
|
---|
| 8 | #
|
---|
| 9 | # Copyright (C) 2000 New Zealand Digital Library Project
|
---|
| 10 | #
|
---|
| 11 | # This program is free software; you can redistribute it and/or modify
|
---|
| 12 | # it under the terms of the GNU General Public License as published by
|
---|
| 13 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | # (at your option) any later version.
|
---|
| 15 | #
|
---|
| 16 | # This program is distributed in the hope that it will be useful,
|
---|
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | # GNU General Public License for more details.
|
---|
| 20 | #
|
---|
| 21 | # You should have received a copy of the GNU General Public License
|
---|
| 22 | # along with this program; if not, write to the Free Software
|
---|
| 23 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | #
|
---|
| 25 | ###########################################################################
|
---|
| 26 |
|
---|
| 27 | package BasClas;
|
---|
| 28 |
|
---|
[1884] | 29 | # How a classifier works.
|
---|
| 30 | #
|
---|
| 31 | # For each classifier requested in the collect.cfg file, buildcol.pl creates
|
---|
| 32 | # a new classifier object (a subclass of BasClas). Later, it passes each
|
---|
| 33 | # document object to each classifier in turn for classification.
|
---|
| 34 | #
|
---|
| 35 | # Four primary functions are used:
|
---|
| 36 | #
|
---|
| 37 | # 1. "new" is called before the documents are processed to set up the
|
---|
| 38 | # classifier.
|
---|
| 39 | #
|
---|
| 40 | # 2. "init" is called after buildcol.pl has created the indexes etc but
|
---|
| 41 | # before the documents are classified in order that the classifier might
|
---|
| 42 | # set any variables it requires, etc.
|
---|
| 43 | #
|
---|
| 44 | # 3. "classify" is called once for each document object. The classifier
|
---|
| 45 | # "classifies" each document and updates its local data accordingly.
|
---|
| 46 | #
|
---|
| 47 | # 4. "get_classify_info" is called after every document has been
|
---|
| 48 | # classified. It collates the information about the documents and
|
---|
| 49 | # stores a reference to the classifier so that Greenstone can later
|
---|
| 50 | # display it.
|
---|
| 51 |
|
---|
[1839] | 52 | use parsargv;
|
---|
[1483] | 53 |
|
---|
[1839] | 54 | sub print_general_usage {
|
---|
| 55 | my ($plugin_name) = @_;
|
---|
[1884] | 56 | print STDERR "
|
---|
[1885] | 57 | -verbosity N Controls the quantity of output.
|
---|
| 58 | Defaults to verbosity of buildcol.pl, which is usually 2.
|
---|
[1884] | 59 |
|
---|
[1885] | 60 | (Most general classifier options are set internally by buildcol.)
|
---|
| 61 |
|
---|
[1884] | 62 | ";
|
---|
[1839] | 63 | }
|
---|
| 64 |
|
---|
| 65 | # print_usage should be overridden for any sub-classes
|
---|
| 66 | sub print_usage {
|
---|
[1884] | 67 | print STDERR "
|
---|
| 68 | This classifier has no classifier-specific options
|
---|
[1839] | 69 |
|
---|
[1884] | 70 | ";
|
---|
[1839] | 71 | }
|
---|
| 72 |
|
---|
[1483] | 73 | sub new {
|
---|
[1839] | 74 | my $class = shift (@_);
|
---|
| 75 | my $name = shift (@_);
|
---|
[1483] | 76 |
|
---|
| 77 | my $self = {};
|
---|
| 78 |
|
---|
[1839] | 79 | $self->{'outhandle'} = STDERR;
|
---|
| 80 |
|
---|
| 81 | # general options available to all classifiers
|
---|
| 82 | if (!parsargv::parse(\@_,
|
---|
| 83 | q^builddir/.*/^, \$self->{'builddir'},
|
---|
| 84 | q^outhandle/.*/STDERR^, \$self->{'outhandle'},
|
---|
| 85 | q^verbosity/\d/2^, \$self->{'verbosity'},
|
---|
| 86 | "allow_extra_options")) {
|
---|
| 87 |
|
---|
| 88 | print STDERR "\nThe $name classifier uses an incorrect general option\n";
|
---|
| 89 | print STDERR "(general options are those available to all classifiers).\n";
|
---|
| 90 | print STDERR "Check your collect.cfg configuration file.\n";
|
---|
| 91 | &print_general_usage($plugin_name);
|
---|
| 92 | die "\n";
|
---|
[1483] | 93 | }
|
---|
| 94 |
|
---|
[1839] | 95 |
|
---|
| 96 |
|
---|
[1483] | 97 | return bless $self, $class;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | sub init {
|
---|
| 101 | my $self = shift (@_);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | sub classify {
|
---|
| 105 | my $self = shift (@_);
|
---|
| 106 | my ($doc_obj) = @_;
|
---|
| 107 |
|
---|
| 108 | my $outhandle = $self->{'outhandle'};
|
---|
| 109 | print $outhandle "BasClas::classify function must be implemented in sub-class\n";
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | sub get_classify_info {
|
---|
| 113 | my $self = shift (@_);
|
---|
| 114 |
|
---|
| 115 | my $outhandle = $self->{'outhandle'};
|
---|
| 116 | print $outhandle "BasClas::classify function must be implemented in sub-class\n";
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | 1;
|
---|