[537] | 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 |
|
---|
[425] | 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 | package SectionList;
|
---|
| 31 |
|
---|
[1483] | 32 | use List;
|
---|
[425] | 33 | use sorttools;
|
---|
| 34 |
|
---|
[1250] | 35 | sub BEGIN {
|
---|
| 36 | @ISA = ('List');
|
---|
[425] | 37 | }
|
---|
| 38 |
|
---|
[1839] | 39 | sub print_usage {
|
---|
| 40 | print STDERR "
|
---|
| 41 | usage: classify SectionList [options]
|
---|
| 42 | options:
|
---|
| 43 |
|
---|
| 44 | -metadata X Metadata field used for classification,
|
---|
| 45 | list will be sorted by this element.
|
---|
| 46 |
|
---|
| 47 | -title X (optional) Title field for this classification.
|
---|
| 48 | if not included title field will be Metaname.
|
---|
| 49 |
|
---|
| 50 | -sort X (optional) Sort documents in list by this metadata field.
|
---|
| 51 | By default it will sort by Metaname, or (if this is not
|
---|
| 52 | set) in build (random) order.
|
---|
| 53 |
|
---|
| 54 | Same as List classifier but includes all sections of document
|
---|
| 55 | (excluding top level) rather than just top level document.
|
---|
| 56 | ";
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[1483] | 59 | sub new {
|
---|
[1839] | 60 | my $class = shift (@_);
|
---|
| 61 | my $self = new List($class, @_);
|
---|
| 62 |
|
---|
[1611] | 63 | return bless $self, $class;
|
---|
[1483] | 64 | }
|
---|
| 65 |
|
---|
[425] | 66 | sub classify {
|
---|
| 67 | my $self = shift (@_);
|
---|
[1250] | 68 | my ($doc_obj, @options) = @_;
|
---|
[838] | 69 |
|
---|
| 70 | my $thissection = undef;
|
---|
[425] | 71 |
|
---|
[838] | 72 | my $option;
|
---|
| 73 | foreach $option (@options)
|
---|
| 74 | {
|
---|
| 75 | if ($option =~ m/^section=(\d+)$/i)
|
---|
| 76 | {
|
---|
| 77 | $thissection = $1;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
[425] | 80 |
|
---|
| 81 | my $sortmeta = "";
|
---|
| 82 | if (defined $self->{'sortname'}) {
|
---|
| 83 | if ($self->{'sortname'} =~ /^filename$/i) {
|
---|
| 84 | $sortmeta = $doc_obj->get_source_filename();
|
---|
| 85 | } else {
|
---|
| 86 | $sortmeta = $doc_obj->get_metadata_element($doc_obj->get_top_section(),
|
---|
| 87 | $self->{'sortname'});
|
---|
| 88 | if ($self->{'sortname'} eq "Creator") {
|
---|
| 89 | &sorttools::format_string_name_english (\$sortmeta);
|
---|
| 90 | } else {
|
---|
| 91 | &sorttools::format_string_english (\$sortmeta);
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | $sortmeta = "" unless defined $sortmeta;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[838] | 97 | if (!defined $thissection)
|
---|
| 98 | {
|
---|
| 99 | $thissection = $doc_obj->get_next_section ($doc_obj->get_top_section());
|
---|
| 100 | while (defined $thissection) {
|
---|
| 101 | $self->classify_section($thissection, $doc_obj, $sortmeta);
|
---|
| 102 | $thissection = $doc_obj->get_next_section ($thissection);
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 | else
|
---|
| 106 | {
|
---|
[425] | 107 | $self->classify_section($thissection, $doc_obj, $sortmeta);
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | sub classify_section {
|
---|
| 112 | my $self = shift (@_);
|
---|
| 113 | my ($section, $doc_obj, $sortmeta) = @_;
|
---|
| 114 |
|
---|
| 115 | my $doc_OID = $doc_obj->get_OID();
|
---|
| 116 | $sortmeta = "" unless defined $sortmeta;
|
---|
| 117 |
|
---|
[545] | 118 | if (defined $self->{'sortname'}) {
|
---|
| 119 | if (defined $self->{'metaname'}) {
|
---|
[425] | 120 |
|
---|
[545] | 121 | my $metavalue = $doc_obj->get_metadata_element ($section, $self->{'metaname'});
|
---|
| 122 | if (defined $metavalue) {
|
---|
| 123 | if (defined $self->{'list'}->{"$doc_OID.$section"}) {
|
---|
[1483] | 124 | my $outhandle = $self->{'outhandle'};
|
---|
| 125 | print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n";
|
---|
[545] | 126 | }
|
---|
| 127 | $self->{'list'}->{"$doc_OID.$section"} = $sortmeta;
|
---|
| 128 | }
|
---|
| 129 | } else {
|
---|
[425] | 130 | if (defined $self->{'list'}->{"$doc_OID.$section"}) {
|
---|
[1483] | 131 | my $outhandle = $self->{'outhandle'};
|
---|
| 132 | print $outhandle "WARNING: SectionList::classify called multiple times for $doc_OID.$section\n";
|
---|
[425] | 133 | }
|
---|
| 134 | $self->{'list'}->{"$doc_OID.$section"} = $sortmeta;
|
---|
| 135 | }
|
---|
[545] | 136 |
|
---|
[425] | 137 | } else {
|
---|
[545] | 138 | if (defined $self->{'metaname'}) {
|
---|
| 139 |
|
---|
| 140 | my $metavalue = $doc_obj->get_metadata_element ($section, $self->{'metaname'});
|
---|
| 141 | if (defined $metavalue) {
|
---|
| 142 | push (@{$self->{'list'}}, "$doc_OID.$section");
|
---|
| 143 | }
|
---|
| 144 | } else {
|
---|
| 145 | push (@{$self->{'list'}}, "$doc_OID.$section");
|
---|
| 146 | }
|
---|
[425] | 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | 1;
|
---|