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