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.05; |
17 |
|
use YAML qw/LoadFile/; |
18 |
|
use LWP::Simple; |
19 |
|
|
20 |
my $limit = shift @ARGV; |
my $limit = shift @ARGV; |
21 |
|
|
22 |
my $abs_path = abs_path($0); |
my $config = LoadFile('conf/config.yml'); |
|
$abs_path =~ s#/[^/]*$#/#; |
|
23 |
|
|
24 |
my $isis_file = '/data/isis_data/ps/LIBRI/LIBRI'; |
print "config = ",Dumper($config); |
25 |
|
|
26 |
my $lookup = new WebPAC::Lookup( |
die "no databases in config file!\n" unless ($config->{databases}); |
27 |
lookup_file => "$abs_path/conf/lookup/isis.pm", |
|
28 |
); |
my $total_rows = 0; |
29 |
|
|
30 |
my $isis = new WebPAC::Input::ISIS( |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
31 |
code_page => 'ISO-8859-2', # application encoding |
|
32 |
limit_mfn => $limit, |
my $log = _new WebPAC::Common()->_get_logger(); |
|
); |
|
|
|
|
|
my $maxmfn = $isis->open( |
|
|
filename => $isis_file, |
|
|
code_page => '852', # database encoding |
|
|
); |
|
|
|
|
|
my $path = './db/'; |
|
|
|
|
|
my $db = new WebPAC::DB( |
|
|
path => $path, |
|
|
); |
|
|
|
|
|
my $n = new WebPAC::Normalize::XML( |
|
|
# filter => { 'foo' => sub { shift } }, |
|
|
db => $db, |
|
|
lookup_regex => $lookup->regex, |
|
|
lookup => $lookup, |
|
|
); |
|
|
|
|
|
$n->open( |
|
|
tag => 'isis', |
|
|
xml_file => "$abs_path/conf/normalize/isis_ffzg.xml", |
|
|
); |
|
|
|
|
|
my $out = new WebPAC::Output::TT( |
|
|
include_path => "$abs_path/conf/output/tt", |
|
|
filters => { foo => sub { shift } }, |
|
|
); |
|
|
|
|
|
my $est = new WebPAC::Output::Estraier( |
|
|
url => 'http://localhost:1978/node/webpac2', |
|
|
user => 'admin', |
|
|
passwd => 'admin', |
|
|
database => 'ps', |
|
|
); |
|
|
|
|
|
while (my $row = $isis->fetch) { |
|
|
|
|
|
my $mfn = $row->{'000'}->[0] || die "can't find MFN"; |
|
|
|
|
|
my $ds = $n->data_structure($row); |
|
|
|
|
|
# print STDERR Dumper($row, $ds); |
|
|
|
|
|
my $html = $out->apply( |
|
|
template => 'html_ffzg.tt', |
|
|
data => $ds, |
|
|
); |
|
33 |
|
|
34 |
# create test output |
# |
35 |
|
# open Hyper Estraier database |
36 |
|
# |
37 |
|
|
38 |
my $file = sprintf('out/%02d.html', $mfn ); |
my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration"); |
39 |
open(my $fh, '>', $file) or die "can't open $file: $!"; |
$est_config->{database} = $database; |
|
print $fh $html; |
|
|
close($fh); |
|
40 |
|
|
41 |
$html =~ s#\s*[\n\r]+\s*##gs; |
$log->info("using HyperEstraier URL $est_config->{masterurl}"); |
42 |
|
|
43 |
# print STDERR $html; |
my $est = new WebPAC::Output::Estraier( |
44 |
|
%{ $est_config }, |
45 |
|
); |
46 |
|
|
47 |
$est->add( |
# |
48 |
id => $mfn, |
# now WebPAC::Store |
49 |
ds => $ds, |
# |
50 |
type => 'search', |
my $abs_path = abs_path($0); |
51 |
|
$abs_path =~ s#/[^/]*$#/#; |
52 |
|
|
53 |
|
my $db_path = $config->{webpac}->{db_path} . '/' . $database; |
54 |
|
|
55 |
|
$log->info("working on $database in $db_path"); |
56 |
|
|
57 |
|
my $db = new WebPAC::Store( |
58 |
|
path => $db_path, |
59 |
|
database => $database, |
60 |
|
debug => 1, |
61 |
); |
); |
62 |
|
|
63 |
}; |
|
64 |
|
# |
65 |
|
# now, iterate through input formats |
66 |
|
# |
67 |
|
|
68 |
|
my @inputs; |
69 |
|
if (ref($db_config->{input}) eq 'ARRAY') { |
70 |
|
@inputs = @{ $db_config->{input} }; |
71 |
|
} elsif ($db_config->{input}) { |
72 |
|
push @inputs, $db_config->{input}; |
73 |
|
} else { |
74 |
|
$log->info("database $database doesn't have inputs defined"); |
75 |
|
} |
76 |
|
|
77 |
|
my @supported_inputs = keys %{ $config->{webpac}->{inputs} }; |
78 |
|
|
79 |
|
foreach my $input (@inputs) { |
80 |
|
|
81 |
|
my $type = lc($input->{type}); |
82 |
|
|
83 |
|
die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs)); |
84 |
|
|
85 |
|
my $lookup = new WebPAC::Lookup( |
86 |
|
lookup_file => $input->{lookup}, |
87 |
|
); |
88 |
|
|
89 |
|
my $input_module = $config->{webpac}->{inputs}->{$type}; |
90 |
|
|
91 |
|
$log->info("working on input $input->{path} [$input->{type}] using $input_module"); |
92 |
|
|
93 |
|
my $input_db = new WebPAC::Input( |
94 |
|
module => $input_module, |
95 |
|
code_page => $config->{webpac}->{webpac_encoding}, |
96 |
|
limit => $input->{limit}, |
97 |
|
lookup => $lookup, |
98 |
|
); |
99 |
|
$log->logdie("can't create input using $input_module") unless ($input); |
100 |
|
|
101 |
|
my $maxmfn = $input_db->open( |
102 |
|
path => $input->{path}, |
103 |
|
code_page => $input->{encoding}, # database encoding |
104 |
|
); |
105 |
|
|
106 |
|
my $n = new WebPAC::Normalize::XML( |
107 |
|
# filter => { 'foo' => sub { shift } }, |
108 |
|
db => $db, |
109 |
|
lookup_regex => $lookup->regex, |
110 |
|
lookup => $lookup, |
111 |
|
prefix => $input->{name}, |
112 |
|
); |
113 |
|
|
114 |
|
my $normalize_path = $input->{normalize}->{path}; |
115 |
|
|
116 |
|
if ($normalize_path =~ m/\.xml$/i) { |
117 |
|
$n->open( |
118 |
|
tag => $input->{normalize}->{tag}, |
119 |
|
xml_file => $input->{normalize}->{path}, |
120 |
|
); |
121 |
|
} elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) { |
122 |
|
$n->open_yaml( |
123 |
|
path => $normalize_path, |
124 |
|
tag => $input->{normalize}->{tag}, |
125 |
|
); |
126 |
|
} |
127 |
|
|
128 |
|
foreach my $pos ( 0 ... $input_db->size ) { |
129 |
|
|
130 |
|
my $row = $input_db->fetch || next; |
131 |
|
|
132 |
|
my $mfn = $row->{000}->[0] || $row->{000} || die "can't find MFN"; |
133 |
|
|
134 |
|
if ($mfn =~ m#^\d+$#) { |
135 |
|
$log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos"); |
136 |
|
$mfn = $pos; |
137 |
|
$row->{000}->[0] = $pos; |
138 |
|
} |
139 |
|
|
140 |
|
my $ds = $n->data_structure($row); |
141 |
|
|
142 |
|
$est->add( |
143 |
|
id => $input->{name} . "#" . $mfn, |
144 |
|
ds => $ds, |
145 |
|
type => $config->{hyperestraier}->{type}, |
146 |
|
); |
147 |
|
|
148 |
|
$total_rows++; |
149 |
|
} |
150 |
|
|
151 |
|
}; |
152 |
|
|
153 |
|
$log->info("$total_rows records indexed"); |
154 |
|
|
155 |
|
# |
156 |
|
# add Hyper Estraier links to other databases |
157 |
|
# |
158 |
|
if (ref($db_config->{links}) eq 'ARRAY') { |
159 |
|
foreach my $link (@{ $db_config->{links} }) { |
160 |
|
$log->info("adding link $database -> $link->{to} [$link->{credit}]"); |
161 |
|
$est->add_link( |
162 |
|
from => $database, |
163 |
|
to => $link->{to}, |
164 |
|
credit => $link->{credit}, |
165 |
|
); |
166 |
|
} |
167 |
|
} |
168 |
|
|
169 |
|
} |
170 |
|
|