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 |
|
---|
29 | package NPepaList;
|
---|
30 |
|
---|
31 | use BasClas;
|
---|
32 |
|
---|
33 | use strict;
|
---|
34 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
35 |
|
---|
36 | sub BEGIN {
|
---|
37 | @NPepaList::ISA = ('BasClas');
|
---|
38 | }
|
---|
39 |
|
---|
40 | my $arguments;
|
---|
41 |
|
---|
42 | my $options = { 'name' => "NPepaList",
|
---|
43 | 'desc' => "Classifies Niupepa documents by series",
|
---|
44 | 'abstract' => "no",
|
---|
45 | 'inherits' => "yes" };
|
---|
46 |
|
---|
47 | sub new {
|
---|
48 | my ($class) = shift (@_);
|
---|
49 |
|
---|
50 | my ($classifierslist,$inputargs,$hashArgOptLists) = @_;
|
---|
51 | push(@$classifierslist, $class);
|
---|
52 |
|
---|
53 | if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
|
---|
54 | if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
|
---|
55 |
|
---|
56 | my $self = new BasClas($classifierslist, $inputargs, $hashArgOptLists);
|
---|
57 |
|
---|
58 | if ($self->{'info_only'}) {
|
---|
59 | # don't worry about any options etc
|
---|
60 | return bless $self, $class;
|
---|
61 | }
|
---|
62 |
|
---|
63 | $self->{'list'} = {};
|
---|
64 | $self->{'metaname'} = "Series";
|
---|
65 | $self->{'sortname'} = "Date";
|
---|
66 |
|
---|
67 | return bless $self, $class;
|
---|
68 |
|
---|
69 | }
|
---|
70 |
|
---|
71 | sub init {
|
---|
72 | my $self = shift (@_);
|
---|
73 |
|
---|
74 | $self->{'list'} = {};
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | sub classify {
|
---|
79 | my $self = shift (@_);
|
---|
80 | my ($doc_obj) = @_;
|
---|
81 |
|
---|
82 | my $doc_OID = $doc_obj->get_OID();
|
---|
83 |
|
---|
84 | # want to ignore abstracts
|
---|
85 | my $doctype = $doc_obj->get_metadata_element($doc_obj->get_top_section(), 'doctype');
|
---|
86 | return if (defined $doctype && $doctype eq 'Description');
|
---|
87 |
|
---|
88 | my $date = $doc_obj->get_metadata_element($doc_obj->get_top_section(),
|
---|
89 | $self->{'sortname'});
|
---|
90 | # commentaries have no date but we want them to sort to the top
|
---|
91 | $date = '00000000' unless defined $date;
|
---|
92 |
|
---|
93 | my $series = $doc_obj->get_metadata_element ($doc_obj->get_top_section(),
|
---|
94 | $self->{'metaname'});
|
---|
95 |
|
---|
96 | if (defined $series) {
|
---|
97 | if (!defined $self->{'list'}->{$series}) {
|
---|
98 | $self->{'list'}->{$series} = {};
|
---|
99 | }
|
---|
100 | if (defined $self->{'list'}->{$series}->{$doc_OID}) {
|
---|
101 | print STDERR "WARNING: NPepaList::classify called multiple times for $doc_OID\n";
|
---|
102 | }
|
---|
103 | $self->{'list'}->{$series}->{$doc_OID} = $date;
|
---|
104 | } else {
|
---|
105 | print STDERR "WARNING: NpepaList::classify $doc_OID has no Series metadata\n";
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | sub bydate {
|
---|
111 | # series names are expected to end with their date
|
---|
112 | my ($adate) = $a =~ /([\d-]+)$/;
|
---|
113 | my ($bdate) = $b =~ /([\d-]+)$/;
|
---|
114 | $adate =~ s/-\d+$//;
|
---|
115 | $bdate =~ s/-\d+$//;
|
---|
116 | return $adate <=> $bdate;
|
---|
117 | }
|
---|
118 |
|
---|
119 | sub get_classify_info {
|
---|
120 | my $self = shift (@_);
|
---|
121 |
|
---|
122 | my $classifyinfo = $self->get_entry ('Series', 'VList', 'Invisible');
|
---|
123 |
|
---|
124 | foreach my $series (sort bydate keys %{$self->{'list'}}) {
|
---|
125 | my $cinfo = $self->get_entry ($series, 'VList');
|
---|
126 | foreach my $OID (sort {$self->{'list'}->{$series}->{$a}
|
---|
127 | cmp $self->{'list'}->{$series}->{$b};} keys %{$self->{'list'}->{$series}}) {
|
---|
128 | push (@{$cinfo->{'contains'}}, {'OID'=>$OID});
|
---|
129 | }
|
---|
130 | push (@{$classifyinfo->{'contains'}}, $cinfo);
|
---|
131 | }
|
---|
132 |
|
---|
133 | return $classifyinfo;
|
---|
134 | }
|
---|
135 |
|
---|
136 | sub get_entry {
|
---|
137 | my $self = shift (@_);
|
---|
138 | my ($title, $childtype, $thistype) = @_;
|
---|
139 |
|
---|
140 | # organise into classification structure
|
---|
141 | my %classifyinfo = ('childtype'=>$childtype,
|
---|
142 | 'Title'=>$title,
|
---|
143 | 'contains'=>[]);
|
---|
144 | $classifyinfo{'thistype'} = $thistype
|
---|
145 | if defined $thistype && $thistype =~ /\w/;
|
---|
146 |
|
---|
147 | return \%classifyinfo;
|
---|
148 | }
|
---|
149 |
|
---|
150 | sub set_number{
|
---|
151 | return;
|
---|
152 | }
|
---|
153 |
|
---|
154 | 1;
|
---|