source: trunk/niupepa/perllib/classify/NPepaList.pm@ 1023

Last change on this file since 1023 was 1023, checked in by sjboddie, 24 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1###########################################################################
2#
3# NpepaList.pm -- website plugin
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) 1999 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# There should probably be a general classifier to do this kind of stuff
28
29package NPepaList;
30
31sub new {
32 my ($class, @options) = @_;
33
34 return bless {
35 'list'=>{},
36 'metaname' => 'Series',
37 'sortname' => 'Date'
38 }, $class;
39}
40
41sub init {
42 my $self = shift (@_);
43
44 $self->{'list'} = {};
45}
46
47
48sub classify {
49 my $self = shift (@_);
50 my ($doc_obj) = @_;
51
52 my $doc_OID = $doc_obj->get_OID();
53
54 # want to ignore abstracts
55 my $doctype = $doc_obj->get_metadata_element($doc_obj->get_top_section(), 'doctype');
56 return if (defined $doctype && $doctype eq 'Description');
57
58 my $date = $doc_obj->get_metadata_element($doc_obj->get_top_section(),
59 $self->{'sortname'});
60 # commentaries have no date but we want them to sort to the top
61 $date = '00000000' unless defined $date;
62
63 my $series = $doc_obj->get_metadata_element ($doc_obj->get_top_section(),
64 $self->{'metaname'});
65
66 if (defined $series) {
67 if (!defined $self->{'list'}->{$series}) {
68 $self->{'list'}->{$series} = {};
69 }
70 if (defined $self->{'list'}->{$series}->{$doc_OID}) {
71 print STDERR "WARNING: NPepaList::classify called multiple times for $doc_OID\n";
72 }
73 $self->{'list'}->{$series}->{$doc_OID} = $date;
74 } else {
75 print STDERR "WARNING: NpepaList::classify $doc_OID has no Series metadata\n";
76 }
77}
78
79
80sub get_classify_info {
81 my $self = shift (@_);
82
83 my $classifyinfo = $self->get_entry ('Series', 'VList', 'Invisible');
84
85 foreach $series (sort keys %{$self->{'list'}}) {
86 my $cinfo = $self->get_entry ($series, 'VList');
87 foreach $OID (sort {$self->{'list'}->{$series}->{$a}
88 cmp $self->{'list'}->{$series}->{$b};} keys %{$self->{'list'}->{$series}}) {
89 push (@{$cinfo->{'contains'}}, {'OID'=>$OID});
90 }
91 push (@{$classifyinfo->{'contains'}}, $cinfo);
92 }
93
94 return $classifyinfo;
95}
96
97sub get_entry {
98 my $self = shift (@_);
99 my ($title, $childtype, $thistype) = @_;
100
101 # organise into classification structure
102 my %classifyinfo = ('childtype'=>$childtype,
103 'Title'=>$title,
104 'contains'=>[]);
105 $classifyinfo{'thistype'} = $thistype
106 if defined $thistype && $thistype =~ /\w/;
107
108 return \%classifyinfo;
109}
110
1111;
Note: See TracBrowser for help on using the repository browser.