source: trunk/gsdl/perllib/classify/NewList.pm@ 13839

Last change on this file since 13839 was 13839, checked in by qq6, 17 years ago

a classify is used to classify documents based on metadata : lastmodified

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1###########################################################################
2#
3# NewList.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# simple list classifier plugin
27# to see the options, run "perl -S classinfo.pl NewList"
28
29use BasClas;
30package NewList;
31
32use strict;
33no strict 'refs'; # allow filehandles to be variables and viceversa
34use diagnostics;
35use sorttools;
36
37sub BEGIN {
38 @NewList::ISA = ('BasClas');
39}
40
41my $arguments =
42 [ { 'name' => "after_specified_date",
43 'desc' => "{NewList.after_specified_date}",
44 'type' => "string" },
45 { 'name' => "return_doc_size",
46 'desc' => "{NewList.return_doc_size}",
47 'type' => "int",
48 'deft' => "20",
49 'reqd' => "no"},
50 ];
51
52my $options = { 'name' => "NewList",
53 'desc' => "{NewList.desc}",
54 'abstract' => "no",
55 'inherits' => "yes",
56 'args' => $arguments };
57
58
59sub new {
60 my ($class) = shift (@_);
61
62 my ($classifierslist,$inputargs,$hashArgOptLists) = @_;
63 push(@$classifierslist, $class);
64
65 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
66 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
67
68 my $self = new BasClas($classifierslist, $inputargs, $hashArgOptLists);
69
70 # Transfer value from Auto Parsing to the variable name that used in previous GreenStone.
71 my (@meta_list,$meta1);
72 if ($self->{"metadata"}) {
73 @meta_list = split(/,/, $self->{"metadata"});
74 $meta1 = $meta_list[0];
75 $self->{'meta_list'} = \@meta_list;
76 } else {
77 $meta1=undef;
78 @meta_list = undef;
79 }
80
81 if (!$self->{"buttonname"}) {
82 if (defined ($self->{'metadata'})) {
83 $self->{"buttonname"} = $self->generate_title_from_metadata($self->{'metadata'});
84 } else {
85 $self->{"buttonname"} = 'NewList';
86 }
87 }
88
89
90 # Further setup
91
92 $self->{'list'} = [];
93
94 # Clean out the unused keys
95 delete $self->{"metadata"}; # Delete this key
96 return bless $self, $class;
97}
98
99sub init {
100 my $self = shift (@_);
101
102}
103
104sub classify {
105 use Time::Local;
106 my $self = shift (@_);
107 my ($doc_obj) = @_;
108
109 my $doc_OID = $doc_obj->get_OID();
110
111 # are we sorting the list??
112 my $nosort = 0;
113 if (defined $self->{'sort'} && $self->{'sort'} eq "nosort") {
114 $nosort = 1;
115 }
116
117 if (defined $self->{'after_specified_date'}){
118 my $topsection=$doc_obj->get_top_section();
119 my @values=split('/',$self->{'after_specified_date'});
120
121 my $specified_date=timelocal(0,0,0,$values[0],$values[1]-1,$values[2]);
122
123 my $value_lastmodified=
124 $doc_obj->get_metadata_element($topsection, 'lastmodified');
125
126 my @values_lastmodi=(localtime($value_lastmodified))[3,4,5];
127 #print STDERR "$values_lastmodi[0], $values_lastmodi[1], $values_lastmodi[2]+1900 \n";
128 my $lastmodified_date=timelocal(0,0,0,$values_lastmodi[0],$values_lastmodi[1],$values_lastmodi[2]+1900);
129
130 #print STDERR "specified_date : " . localtime($specified_date) . "\n";
131 if ($lastmodified_date>=$specified_date){
132 print STDERR " lastmodified_value: ", localtime($value_lastmodified), "\n";
133 push (@{$self->{'lastmodified_values'}},$value_lastmodified);
134 push (@{$self->{'list'}}, $doc_OID);
135 }else{
136 return;
137 }
138
139 }else{
140 return;
141 }
142
143 my $id = $self->get_number();
144 $doc_obj->add_metadata($doc_obj->get_top_section(), "memberof", "CL$id");
145}
146
147
148sub get_classify_info {
149 my $self = shift (@_);
150 my ($no_thistype) = @_;
151 # $no_thistype = 0 unless defined $no_thistype;
152 my $memberof = &supports_memberof();
153 my $return_doc_size=0;
154 if (defined $self->{'return_doc_size'}){
155 $return_doc_size=$self->{'return_doc_size'};
156 }
157
158 my @list = ();
159 @list = @{$self->{'list'}};
160
161
162 # organise into classification structure
163 my %classifyinfo = ('childtype'=>'VList',
164 'Title'=>$self->{'buttonname'},
165 'contains'=>[]);
166
167 $classifyinfo{'thistype'} = 'Invisible';
168 #$classifyinfo{'thistype'} = 'Invisible' unless $no_thistype;
169 # always supports memberof
170 $classifyinfo{'supportsmemberof'} = $memberof;
171
172 #mapping lastmodified with OID in a hashtable
173 my %metavaluetoOIDhash=();
174 my $size= @{$self->{'lastmodified_values'}};
175 print STDERR "size of lastmodified_values: ", $size, "\n";
176 my @lastmodified_values=();
177 @lastmodified_values = @{$self->{'lastmodified_values'}};
178
179 my $i;
180 for ($i=0;($i<$size);$i++){
181 #print STDERR "lastmodified_values : " . $lastmodified_values[$i] . "list : " . $list[$i], "\n";
182 $metavaluetoOIDhash{$list[$i]}=$lastmodified_values[$i];
183 }
184
185 #sort the hashtable by values, then form an array containing keys
186 my @sortedOIDbylastmodified = sort { $metavaluetoOIDhash{$b} <=> $metavaluetoOIDhash{$a} } keys %metavaluetoOIDhash;
187
188 my $j=0;
189 for ($i=0;($i<$size);$i++){
190 my $OID= $sortedOIDbylastmodified[$i];
191 my $hashref={};
192 # special oid format, if using offsets (from AZCompactList)
193 if ($OID =~ s/\.offset(\d+)$//) {
194 $hashref->{'offset'}=$1;
195 }
196 $hashref->{'OID'}=$OID;
197
198 push (@{$classifyinfo{'contains'}}, $hashref);
199 $j++;
200
201 if($return_doc_size>0 && $j>=$return_doc_size){
202 last;
203 }
204 }
205
206 return \%classifyinfo;
207}
208
209sub supports_memberof {
210 my $self = shift(@_);
211
212 return "true";
213}
214
215
2161;
217
218
219
220
Note: See TracBrowser for help on using the repository browser.