source: trunk/gsdl/perllib/classify/SectionList.pm@ 10253

Last change on this file since 10253 was 10253, checked in by kjdon, 19 years ago

added 'use strict' to all classifiers, and made modifications (mostly adding 'my') to make them compile

  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
RevLine 
[537]1###########################################################################
2#
3# SectionList.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
[425]26# Same as List classifier but includes all sections of document
27# (excluding top level) rather than just top level document
28# itself
29
[3540]30# 12/05/02 Added usage datastructure - John Thompson
31
[425]32package SectionList;
33
[1483]34use List;
[425]35use sorttools;
36
[10253]37use strict;
38no strict 'refs'; # allow filehandles to be variables and viceversa
39
[1250]40sub BEGIN {
[10253]41 @SectionList::ISA = ('List');
[425]42}
43
[10253]44my $arguments = [];
[4759]45my $options = { 'name' => "SectionList",
[5645]46 'desc' => "{SectionList.desc}",
[6408]47 'abstract' => "no",
48 'inherits' => "yes" };
[3540]49
[1839]50
[10218]51sub new {
52 my ($class) = shift (@_);
53 my ($classifierslist,$inputargs,$hashArgOptLists) = @_;
54 push(@$classifierslist, $class);
[3540]55
[10218]56 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
57 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
[4786]58
[10218]59 my $self = (defined $hashArgOptLists)? new List($classifierslist,$inputargs,$hashArgOptLists): new List($classifierslist,$inputargs);
60
[1611]61 return bless $self, $class;
[1483]62}
63
[425]64sub classify {
65 my $self = shift (@_);
[6974]66 my ($doc_obj, @options) = @_;
[838]67
[6974]68 # @options used by AZCompactList when is uses SectionList internally
[6970]69 # are we sorting the list??
70 my $nosort = 0;
[10218]71 if (defined $self->{'sort'} && $self->{'sort'} eq "nosort") {
[6970]72 $nosort = 1;
[838]73 }
[425]74
[6974]75 my $thissection = undef;
[6970]76
[10253]77 foreach my $option (@options)
[6974]78 {
79 if ($option =~ m/^section=(\d+)$/i)
80 {
81 $thissection = $1;
82 }
83 }
[6970]84
[425]85 my $sortmeta = "";
[10218]86 if (!$nosort && defined $self->{'sort'}) {
87 if ($self->{'sort'} =~ /^filename$/i) {
[425]88 $sortmeta = $doc_obj->get_source_filename();
89 } else {
[10218]90 $sortmeta = $doc_obj->get_metadata_element($doc_obj->get_top_section(), $self->{'sort'});
[6970]91 if (defined $sortmeta) {
[10218]92 $sortmeta = &sorttools::format_metadata_for_sorting($self->{'sort'}, $sortmeta, $doc_obj);
[425]93 }
94 }
95 $sortmeta = "" unless defined $sortmeta;
96 }
97
[6974]98 if (defined $thissection) {
99 # just classify the one section
100 $self->classify_section($thissection, $doc_obj, $sortmeta, $nosort);
101 } else
102 {
103 $thissection = $doc_obj->get_next_section ($doc_obj->get_top_section());
104 while (defined $thissection) {
105 $self->classify_section($thissection, $doc_obj, $sortmeta, $nosort);
106 $thissection = $doc_obj->get_next_section ($thissection);
107 }
[838]108 }
[425]109}
110
111sub classify_section {
112 my $self = shift (@_);
[6974]113 my ($section, $doc_obj, $sortmeta, $nosort) = @_;
[425]114
115 my $doc_OID = $doc_obj->get_OID();
[6970]116 $nosort = 0 unless defined $nosort;
[425]117 $sortmeta = "" unless defined $sortmeta;
118
[6970]119 my $metavalue;
120 my $metaname;
121 if (defined $self->{'meta_list'}) {
122 # find the first available metadata
[10253]123 foreach my $m (@{$self->{'meta_list'}}) {
[6970]124 $metavalue = $doc_obj->get_metadata_element($section, $m);
125 $metaname = $m;
126 last if defined $metavalue;
127 }
128 #if we haven't found a metavalue here, then the section shouldn't be included
129 return unless defined $metavalue;
130 }
131
132 # we know the section should be included, add it now if we are not sorting
133 if ($nosort) {
134 push (@{$self->{'list'}}, "$doc_OID.$section");
135 return;
136 }
137 # check that it hasn't been added already
138 if (defined $self->{'list'}->{"$doc_OID.$section"}) {
139 my $outhandle = $self->{'outhandle'};
140 print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n";
141 }
142
[10218]143 if (defined $self->{'sort'}) {
[6970]144 # sorting on alternative metadata
145 $self->{'list'}->{"$doc_OID.$section"} = $sortmeta;
[425]146 } else {
[10218]147 # sorting on the classification metadata
[6970]148 # do the same formatting on the meta value as for sort meta
[8852]149 $metavalue = &sorttools::format_metadata_for_sorting($metaname, $metavalue, $doc_obj);
[6970]150 $self->{'list'}->{"$doc_OID.$section"} = $metavalue;
[425]151 }
152}
1531;
Note: See TracBrowser for help on using the repository browser.