source: trunk/gsdl/perllib/classify/BasClas.pm@ 1884

Last change on this file since 1884 was 1884, checked in by paynter, 23 years ago

Added some documentation.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1###########################################################################
2#
3# BasClas.pm -- base class for all classifiers
4#
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
27package BasClas;
28
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
52use parsargv;
53
54sub print_general_usage {
55 my ($plugin_name) = @_;
56 print STDERR "
57 usage: plugin $plugin_name [options]
58
59";
60}
61
62# print_usage should be overridden for any sub-classes
63sub print_usage {
64 print STDERR "
65This classifier has no classifier-specific options
66
67";
68}
69
70sub new {
71 my $class = shift (@_);
72 my $name = shift (@_);
73
74 my $self = {};
75
76 $self->{'outhandle'} = STDERR;
77
78 # general options available to all classifiers
79 if (!parsargv::parse(\@_,
80 q^builddir/.*/^, \$self->{'builddir'},
81 q^outhandle/.*/STDERR^, \$self->{'outhandle'},
82 q^verbosity/\d/2^, \$self->{'verbosity'},
83 "allow_extra_options")) {
84
85 print STDERR "\nThe $name classifier uses an incorrect general option\n";
86 print STDERR "(general options are those available to all classifiers).\n";
87 print STDERR "Check your collect.cfg configuration file.\n";
88 &print_general_usage($plugin_name);
89 die "\n";
90 }
91
92
93
94 return bless $self, $class;
95}
96
97sub init {
98 my $self = shift (@_);
99}
100
101sub classify {
102 my $self = shift (@_);
103 my ($doc_obj) = @_;
104
105 my $outhandle = $self->{'outhandle'};
106 print $outhandle "BasClas::classify function must be implemented in sub-class\n";
107}
108
109sub get_classify_info {
110 my $self = shift (@_);
111
112 my $outhandle = $self->{'outhandle'};
113 print $outhandle "BasClas::classify function must be implemented in sub-class\n";
114}
115
1161;
Note: See TracBrowser for help on using the repository browser.