source: trunk/gsdl/perllib/classify/List.pm@ 408

Last change on this file since 408 was 385, checked in by sjboddie, 25 years ago

moved string formatting for sorting into it's own module

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
1# simple list classifier plugin
2# collect.cfg usage: 'List metaelement' or simply 'List'
3# the first will create a single list of all documents
4# with metaelement metadata (sorted alphabetically by whichever
5# metadata element was chosen).
6# The second will create a single list of all documents
7# which won't be sorted at all - they may well be in
8# some completely random order ;-|
9
10
11package List;
12
13use sorttools;
14
15sub new {
16 my ($class, @options) = @_;
17
18 my $list = [];
19 if (defined $options[0]) {
20 $list = {};
21 }
22
23 return bless {
24 'list'=>$list,
25 'metaname' => $options[0]
26 }, $class;
27}
28
29sub init {
30 my $self = shift (@_);
31
32 if (defined $self->{'metaname'}) {
33 $self->{'list'} = {};
34 } else {
35 $self->{'list'} = [];
36 }
37}
38
39sub classify {
40 my $self = shift (@_);
41 my ($doc_obj) = @_;
42
43 my $doc_OID = $doc_obj->get_OID();
44
45 if (defined $self->{'metaname'}) {
46 my $metavalue = $doc_obj->get_metadata_element ($doc_obj->get_top_section(),
47 $self->{'metaname'});
48 if (defined $metavalue) {
49 if ($self->{'metaname'} eq 'Creator') {
50 &sorttools::format_string_name_english (\$metavalue);
51 } else {
52 &sorttools::format_string_english (\$metavalue);
53 }
54 if (defined $self->{'list'}->{$doc_OID}) {
55 print STDERR "WARNING: List::classify called multiple times for $doc_OID\n";
56 }
57 $self->{'list'}->{$doc_OID} = $metavalue;
58 }
59 } else {
60 push (@{$self->{'list'}}, $doc_OID);
61 }
62}
63
64sub get_classify_info {
65 my $self = shift (@_);
66
67 my $classifytitle = "List";
68 my $contains = "";
69 my @list = ();
70 if (defined $self->{'metaname'}) {
71 $classifytitle = $self->{'metaname'};
72 if (keys %{$self->{'list'}}) {
73 @list = sort {$self->{'list'}->{$a}
74 cmp $self->{'list'}->{$b};} keys %{$self->{'list'}};
75 }
76 } else {
77 @list = @{$self->{'list'}};
78 }
79
80 # organise into classification structure
81 my %classifyinfo = ('classifytype'=>'List',
82 'Title'=>$classifytitle,
83 'contains'=>[]);
84 foreach $OID (@list) {
85 push (@{$classifyinfo{'contains'}}, {'OID'=>$OID});
86 }
87
88 return \%classifyinfo;
89}
90
91
921;
Note: See TracBrowser for help on using the repository browser.