source: trunk/gsdl/perllib/classify/AZSectionList.pm@ 10218

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

Jeffrey's new parsing modifications, committed approx 6 July, 15.16

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1###########################################################################
2#
3# AZSectionList.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
26# classifier plugin for sorting sections alphabetically
27
28# this is very similar to AZList except it sorts by
29# section level metadata (excluding the top level)
30# instead of just top level metadata
31
32# the only change is to the classify() subroutine which
33# must now iterate through each section, adding each
34# to the classification
35
36# 12/05/02 Added usage datastructure - John Thompson
37
38package AZSectionList;
39
40use AZList;
41use sorttools;
42
43sub BEGIN {
44 @ISA = ('AZList');
45}
46
47my $options = { 'name' => "AZSectionList",
48 'desc' => "{AZSectionList.desc}",
49 'abstract' => "no",
50 'inherits' => "yes" };
51
52
53sub new {
54 my ($class) = shift (@_);
55 my ($classifierslist,$inputargs,$hashArgOptLists) = @_;
56 push(@$classifierslist, $class);
57
58 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
59 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
60
61 my $self = (defined $hashArgOptLists)? new AZList($classifierslist,$inputargs,$hashArgOptLists): new AZList($classifierslist,$inputargs);
62
63 return bless $self, $class;
64}
65
66sub classify {
67 my $self = shift (@_);
68 my ($doc_obj) = @_;
69
70 my $doc_OID = $doc_obj->get_OID();
71 my $thissection = $doc_obj->get_next_section ($doc_obj->get_top_section());
72
73 while (defined $thissection) {
74 $self->classify_section ($thissection, $doc_obj);
75 $thissection = $doc_obj->get_next_section ($thissection);
76 }
77}
78
79sub classify_section {
80 my $self = shift (@_);
81 my ($section, $doc_obj) = @_;
82
83 my $doc_OID = $doc_obj->get_OID();
84
85 my $metavalue;
86 my $metaname;
87
88 if (!defined $self->{'meta_list'}) {
89 # just in case
90 return;
91 }
92
93 # find the first available metadata
94 foreach $m (@{$self->{'meta_list'}}) {
95 $metavalue = $doc_obj->get_metadata_element($section, $m);
96 $metaname = $m;
97 last if defined $metavalue;
98 }
99
100 # if this section doesn't contain the metadata element we're
101 # sorting by we won't include it in this classification
102
103 if (defined $metavalue && $metavalue ne "") {
104 if ($self->{'removeprefix'}) {
105 $metavalue =~ s/^$self->{'removeprefix'}//;
106 }
107
108 $metavalue = &sorttools::format_metadata_for_sorting($metaname, $metavalue, $doc_obj);
109 if (defined $self->{'list'}->{"$doc_OID.$section"}) {
110 my $outhandle = $self->{'outhandle'};
111 print $outhandle "WARNING: AZSectionList::classify called multiple times " .
112 "for $doc_OID.$section\n";
113 }
114 $self->{'list'}->{"$doc_OID.$section"} = $metavalue;
115 }
116}
117
118
1191;
Note: See TracBrowser for help on using the repository browser.