source: branches/New_Config_Format-branch/gsdl/perllib/plugins/IndexPlug.pm@ 1279

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

merged changes to trunk into New_Config_Format branch

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
RevLine 
[537]1###########################################################################
2#
3# IndexPlug.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
[286]26# This recursive plugin processes an index.txt file.
27# The index.txt file should contain the list of files to be
28# included in the collection followed by any extra metadata to
29# be associated with each file.
30
31# The index.txt file should be formatted as follows:
32# The first line may be a key (beginning with key:)
33# to name the metadata fields
34# (e.g. key: Subject Organization Date)
35# The following lines will contain a filename followed
36# by the value that metadata entry is to be set to.
37# (e.g. 'irma/iw097e 3.2 unesco 1993' will associate the
38# metadata Subject=3.2, Organization=unesco, and Date=1993
39# with the file irma/iw097e if the above key line was used)
40
41# Note that if any of the metadata fields use the Hierarchy
42# classifier plugin then the value they're set to should
43# correspond to the first field (the descriptor) in the
44# appropriate classification file.
45
46# Metadata values may be named separately using a tag
47# (e.g. <Subject>3.2) and this will override any name
48# given to them by the key line.
49# If there's no key line any unnamed metadata value will be
50# named 'Subject'.
51
52package IndexPlug;
53
54use plugin;
55use BasPlug;
56use doc;
57use util;
58use cfgread;
59
60sub BEGIN {
61 @ISA = ('BasPlug');
62}
63
[1279]64use strict;
65
[286]66sub new {
67 my ($class) = @_;
[1279]68 my $self = new BasPlug ("IndexPlug", @_);
[286]69
70 return bless $self, $class;
71}
72
73# return 1 if this class might recurse using $pluginfo
74sub is_recursive {
75 my $self = shift (@_);
76
77 return 1;
78}
79
[317]80# return number of files processed, undef if can't process
[286]81# Note that $base_dir might be "" and that $file might
82# include directories
83sub read {
84 my $self = shift (@_);
[317]85 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs) = @_;
[286]86
87 my $indexfile = &util::filename_cat($base_dir, $file, "index.txt");
88 if (!-f $indexfile) {
89 # not a directory containing an index file
[317]90 return undef;
[286]91 }
92
93 # found an index.txt file
94 print STDERR "IndexPlug: processing $indexfile\n";
95
96 # read in the index.txt
97 my $list = &cfgread::read_cfg_file ($indexfile, undef, '^[^#]\w');
98 my @fields = ();
99 # see if there's a 'key:' line
[317]100 if (defined $list->{'key:'}) {
101 @fields = @{$list->{'key:'}};
[286]102 }
103
104 # process each document
105 my $count = 0;
[1279]106 foreach my $docfile (keys (%$list)) {
[809]107 last if ($maxdocs != -1 && $count >= $maxdocs);
[286]108 $metadata = {}; # at present we can do this as metadata
109 # will always be empty when it arrives
[317]110 # at this plugin - this might cause
[286]111 # problems if things change though
112
113 # note that $list->{$docfile} is an array reference
114 if ($docfile !~ /key:/i) {
[1279]115 my $i = 0;
[286]116 for ($i = 0; $i < scalar (@{$list->{$docfile}}); $i ++) {
117 if ($list->{$docfile}->[$i] =~ /^<([^>]+)>(.+)$/) {
118 unless (defined ($metadata->{$1})) {
119 $metadata->{$1} = [];
120 }
121 push (@{$metadata->{$1}}, $2);
122 } elsif (scalar @fields >= $i) {
123 unless (defined ($metadata->{$fields[$i]})) {
124 $metadata->{$fields[$i]} = [];
125 }
126 push (@{$metadata->{$fields[$i]}}, $list->{$docfile}->[$i]);
127 } else {
128 $metadata->{'Subject'} = $list->{$docfile};
129 }
130 }
[640]131 $count += &plugin::read ($pluginfo, $base_dir, $docfile, $metadata, $processor, $maxdocs);
[286]132 }
133 }
134
[317]135 return $count; # was processed
[286]136}
137
138
1391;
Note: See TracBrowser for help on using the repository browser.