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