7 |
use Data::Dumper; |
use Data::Dumper; |
8 |
use lib './lib'; |
use lib './lib'; |
9 |
|
|
10 |
|
use WebPAC::Common 0.02; |
11 |
use WebPAC::Lookup; |
use WebPAC::Lookup; |
12 |
use WebPAC::Input::ISIS; |
use WebPAC::Input 0.03; |
13 |
use WebPAC::Store 0.03; |
use WebPAC::Store 0.03; |
14 |
use WebPAC::Normalize::XML; |
use WebPAC::Normalize::XML; |
15 |
use WebPAC::Output::TT; |
use WebPAC::Output::TT; |
16 |
use WebPAC::Output::Estraier; |
use WebPAC::Output::Estraier 0.08; |
17 |
use YAML qw/LoadFile/; |
use YAML qw/LoadFile/; |
18 |
|
use Getopt::Long; |
19 |
|
use File::Path; |
20 |
|
|
21 |
my $limit = shift @ARGV; |
=head1 NAME |
22 |
|
|
23 |
my $config = LoadFile('conf/config.yml'); |
run.pl - start WebPAC indexing |
24 |
|
|
25 |
print "config = ",Dumper($config); |
B<this command will probably go away. Don't get used to it!> |
26 |
|
|
27 |
my $type = lc($config->{input}->{type}); |
Options: |
28 |
|
|
29 |
die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis'); |
=over 4 |
30 |
|
|
31 |
my $abs_path = abs_path($0); |
=item --offset 42 |
|
$abs_path =~ s#/[^/]*$#/#; |
|
32 |
|
|
33 |
my $lookup = new WebPAC::Lookup( |
start loading (all) databases at offset 42 |
|
lookup_file => $config->{input}->{lookup}, |
|
|
); |
|
34 |
|
|
35 |
|
=item --limit 100 |
36 |
|
|
37 |
|
limit loading to 100 records |
38 |
|
|
39 |
my $isis = new WebPAC::Input::ISIS( |
=item --clean |
|
code_page => $config->{webpac}->{webpac_encoding}, |
|
|
limit_mfn => $config->{input}->{limit}, |
|
|
); |
|
40 |
|
|
41 |
my $maxmfn = $isis->open( |
remove database and Hyper Estraier index before indexing |
|
filename => $config->{input}->{path}, |
|
|
code_page => $config->{input}->{encoding}, # database encoding |
|
|
); |
|
42 |
|
|
43 |
my $path = './db/'; |
=item --one=database_name |
44 |
|
|
45 |
my $db = new WebPAC::Store( |
reindex just single database |
|
path => $config->{webpac}->{db_path}, |
|
|
); |
|
46 |
|
|
47 |
my $n = new WebPAC::Normalize::XML( |
=item --config conf/config.yml |
|
# filter => { 'foo' => sub { shift } }, |
|
|
db => $db, |
|
|
lookup_regex => $lookup->regex, |
|
|
lookup => $lookup, |
|
|
); |
|
48 |
|
|
49 |
$n->open( |
path to YAML configuration file |
|
tag => $config->{normalize}->{tag}, |
|
|
xml_file => $config->{normalize}->{path}, |
|
|
); |
|
50 |
|
|
51 |
my $out = new WebPAC::Output::TT( |
=back |
52 |
include_path => $config->{webpac}->{template_path}, |
|
53 |
filters => { foo => sub { shift } }, |
=cut |
54 |
); |
|
55 |
|
my $offset; |
56 |
|
my $limit; |
57 |
|
|
58 |
my $est = new WebPAC::Output::Estraier( |
my $clean = 0; |
59 |
%{ $config->{hyperestraier} } |
my $config = 'conf/config.yml'; |
60 |
|
my $debug = 0; |
61 |
|
my $one_db_name; |
62 |
|
|
63 |
|
GetOptions( |
64 |
|
"limit=i" => \$limit, |
65 |
|
"offset=i" => \$offset, |
66 |
|
"clean" => \$clean, |
67 |
|
"one=s" => \$one_db_name, |
68 |
|
"config" => \$config, |
69 |
|
"debug" => \$debug, |
70 |
); |
); |
71 |
|
|
72 |
|
$config = LoadFile($config); |
73 |
|
|
74 |
|
print "config = ",Dumper($config) if ($debug); |
75 |
|
|
76 |
|
die "no databases in config file!\n" unless ($config->{databases}); |
77 |
|
|
78 |
my $total_rows = 0; |
my $total_rows = 0; |
79 |
|
|
80 |
for ( 0 ... $isis->size ) { |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
81 |
|
|
82 |
|
next if ($one_db_name && $database !~ m/$one_db_name/i); |
83 |
|
|
84 |
|
my $log = _new WebPAC::Common()->_get_logger(); |
85 |
|
|
86 |
|
# |
87 |
|
# open Hyper Estraier database |
88 |
|
# |
89 |
|
|
90 |
|
my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration"); |
91 |
|
$est_config->{database} = $database; |
92 |
|
$est_config->{clean} = $clean; |
93 |
|
|
94 |
|
my $est = new WebPAC::Output::Estraier( %{ $est_config } ); |
95 |
|
|
96 |
my $row = $isis->fetch || next; |
# |
97 |
|
# now WebPAC::Store |
98 |
|
# |
99 |
|
my $abs_path = abs_path($0); |
100 |
|
$abs_path =~ s#/[^/]*$#/#; |
101 |
|
|
102 |
my $mfn = $row->{'000'}->[0] || die "can't find MFN"; |
my $db_path = $config->{webpac}->{db_path} . '/' . $database; |
103 |
|
|
104 |
my $ds = $n->data_structure($row); |
if ($clean) { |
105 |
|
$log->info("creating new database $database in $db_path"); |
106 |
|
rmtree( $db_path ) || $log->warn("can't remove $db_path: $!"); |
107 |
|
} else { |
108 |
|
$log->info("working on $database in $db_path"); |
109 |
|
} |
110 |
|
|
111 |
# print STDERR Dumper($row, $ds); |
my $db = new WebPAC::Store( |
112 |
|
path => $db_path, |
113 |
# my $html = $out->apply( |
database => $database, |
114 |
# template => 'html_ffzg.tt', |
debug => $debug, |
|
# data => $ds, |
|
|
# ); |
|
|
# |
|
|
# # create test output |
|
|
# |
|
|
# my $file = sprintf('out/%02d.html', $mfn ); |
|
|
# open(my $fh, '>', $file) or die "can't open $file: $!"; |
|
|
# print $fh $html; |
|
|
# close($fh); |
|
|
# |
|
|
# $html =~ s#\s*[\n\r]+\s*##gs; |
|
|
# |
|
|
# print STDERR $html; |
|
|
|
|
|
$est->add( |
|
|
id => $mfn, |
|
|
ds => $ds, |
|
|
type => $config->{hyperestraier}->{type}, |
|
115 |
); |
); |
116 |
|
|
|
$total_rows++; |
|
117 |
|
|
118 |
}; |
# |
119 |
|
# now, iterate through input formats |
120 |
|
# |
121 |
|
|
122 |
|
my @inputs; |
123 |
|
if (ref($db_config->{input}) eq 'ARRAY') { |
124 |
|
@inputs = @{ $db_config->{input} }; |
125 |
|
} elsif ($db_config->{input}) { |
126 |
|
push @inputs, $db_config->{input}; |
127 |
|
} else { |
128 |
|
$log->info("database $database doesn't have inputs defined"); |
129 |
|
} |
130 |
|
|
131 |
|
my @supported_inputs = keys %{ $config->{webpac}->{inputs} }; |
132 |
|
|
133 |
|
foreach my $input (@inputs) { |
134 |
|
|
135 |
|
my $type = lc($input->{type}); |
136 |
|
|
137 |
|
die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs)); |
138 |
|
|
139 |
|
my $lookup = new WebPAC::Lookup( |
140 |
|
lookup_file => $input->{lookup}, |
141 |
|
); |
142 |
|
|
143 |
|
my $input_module = $config->{webpac}->{inputs}->{$type}; |
144 |
|
|
145 |
|
$log->info("working on input $input->{path} [$input->{type}] using $input_module"); |
146 |
|
|
147 |
|
my $input_db = new WebPAC::Input( |
148 |
|
module => $input_module, |
149 |
|
code_page => $config->{webpac}->{webpac_encoding}, |
150 |
|
limit => $limit || $input->{limit}, |
151 |
|
offset => $offset, |
152 |
|
lookup => $lookup, |
153 |
|
); |
154 |
|
$log->logdie("can't create input using $input_module") unless ($input); |
155 |
|
|
156 |
|
my $maxmfn = $input_db->open( |
157 |
|
path => $input->{path}, |
158 |
|
code_page => $input->{encoding}, # database encoding |
159 |
|
); |
160 |
|
|
161 |
|
my $n = new WebPAC::Normalize::XML( |
162 |
|
# filter => { 'foo' => sub { shift } }, |
163 |
|
db => $db, |
164 |
|
lookup_regex => $lookup->regex, |
165 |
|
lookup => $lookup, |
166 |
|
prefix => $input->{name}, |
167 |
|
); |
168 |
|
|
169 |
|
my $normalize_path = $input->{normalize}->{path}; |
170 |
|
|
171 |
|
if ($normalize_path =~ m/\.xml$/i) { |
172 |
|
$n->open( |
173 |
|
tag => $input->{normalize}->{tag}, |
174 |
|
xml_file => $input->{normalize}->{path}, |
175 |
|
); |
176 |
|
} elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) { |
177 |
|
$n->open_yaml( |
178 |
|
path => $normalize_path, |
179 |
|
tag => $input->{normalize}->{tag}, |
180 |
|
); |
181 |
|
} |
182 |
|
|
183 |
|
foreach my $pos ( 0 ... $input_db->size ) { |
184 |
|
|
185 |
|
my $row = $input_db->fetch || next; |
186 |
|
|
187 |
|
my $mfn = $row->{'000'}->[0]; |
188 |
|
|
189 |
|
if (! $mfn || $mfn !~ m#^\d+$#) { |
190 |
|
$log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos"); |
191 |
|
$mfn = $pos; |
192 |
|
push @{ $row->{'000'} }, $pos; |
193 |
|
} |
194 |
|
|
195 |
|
my $ds = $n->data_structure($row); |
196 |
|
|
197 |
|
$est->add( |
198 |
|
id => $input->{name} . "/" . $mfn, |
199 |
|
ds => $ds, |
200 |
|
type => $config->{hyperestraier}->{type}, |
201 |
|
); |
202 |
|
|
203 |
|
$total_rows++; |
204 |
|
} |
205 |
|
|
206 |
|
}; |
207 |
|
|
208 |
|
$log->info("$total_rows records indexed"); |
209 |
|
|
210 |
|
# |
211 |
|
# add Hyper Estraier links to other databases |
212 |
|
# |
213 |
|
if (ref($db_config->{links}) eq 'ARRAY') { |
214 |
|
foreach my $link (@{ $db_config->{links} }) { |
215 |
|
$log->info("adding link $database -> $link->{to} [$link->{credit}]"); |
216 |
|
$est->add_link( |
217 |
|
from => $database, |
218 |
|
to => $link->{to}, |
219 |
|
credit => $link->{credit}, |
220 |
|
); |
221 |
|
} |
222 |
|
} |
223 |
|
|
224 |
my $log = $lookup->_get_logger; |
} |
225 |
|
|
|
$log->info("$total_rows records indexed"); |
|