9 |
|
|
10 |
use WebPAC::Lookup; |
use WebPAC::Lookup; |
11 |
use WebPAC::Input::ISIS; |
use WebPAC::Input::ISIS; |
12 |
use WebPAC::DB; |
use WebPAC::Store 0.03; |
13 |
use WebPAC::Normalize::XML; |
use WebPAC::Normalize::XML; |
14 |
use WebPAC::Output::TT; |
use WebPAC::Output::TT; |
15 |
use WebPAC::Output::Estraier; |
use WebPAC::Output::Estraier 0.02; |
16 |
|
use YAML qw/LoadFile/; |
17 |
|
use LWP::Simple; |
18 |
|
|
19 |
my $limit = shift @ARGV; |
my $limit = shift @ARGV; |
20 |
|
|
21 |
my $abs_path = abs_path($0); |
my $config = LoadFile('conf/config.yml'); |
|
$abs_path =~ s#/[^/]*$#/#; |
|
22 |
|
|
23 |
my $isis_file = '/data/isis_data/ps/LIBRI/LIBRI'; |
print "config = ",Dumper($config); |
24 |
|
|
25 |
my $lookup = new WebPAC::Lookup( |
die "no databases in config file!\n" unless ($config->{databases}); |
|
lookup_file => "$abs_path/conf/lookup/isis.pm", |
|
|
); |
|
|
|
|
|
my $isis = new WebPAC::Input::ISIS( |
|
|
code_page => 'ISO-8859-2', # application encoding |
|
|
limit_mfn => $limit, |
|
|
); |
|
|
|
|
|
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', |
|
|
); |
|
26 |
|
|
27 |
my $total_rows = 0; |
my $total_rows = 0; |
28 |
|
|
29 |
for ( 0 ... $isis->size ) { |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
30 |
|
|
31 |
my $row = $isis->fetch || next; |
my $type = lc($db_config->{input}->{type}); |
32 |
|
|
33 |
my $mfn = $row->{'000'}->[0] || die "can't find MFN"; |
die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis'); |
34 |
|
|
35 |
my $ds = $n->data_structure($row); |
my $abs_path = abs_path($0); |
36 |
|
$abs_path =~ s#/[^/]*$#/#; |
37 |
|
|
38 |
# print STDERR Dumper($row, $ds); |
my $lookup = new WebPAC::Lookup( |
39 |
|
lookup_file => $db_config->{input}->{lookup}, |
|
# my $html = $out->apply( |
|
|
# template => 'html_ffzg.tt', |
|
|
# 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 => 'search', |
|
40 |
); |
); |
41 |
|
|
42 |
$total_rows++; |
my $db_path = $config->{webpac}->{db_path} . '/' . $database; |
43 |
|
|
|
}; |
|
44 |
|
|
45 |
my $log = $lookup->_get_logger; |
my $log = $lookup->_get_logger; |
46 |
|
$log->info("working on $database in $db_path"); |
47 |
|
|
48 |
|
my $path = './db/'; |
49 |
|
|
50 |
|
my $db = new WebPAC::Store( |
51 |
|
path => $db_path, |
52 |
|
); |
53 |
|
|
54 |
|
my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration"); |
55 |
|
$est_config->{database} = $database; |
56 |
|
|
57 |
|
$log->info("using HyperEstraier URL $est_config->{masterurl}"); |
58 |
|
|
59 |
|
my $est = new WebPAC::Output::Estraier( |
60 |
|
%{ $est_config }, |
61 |
|
); |
62 |
|
|
63 |
|
# |
64 |
|
# now, iterate through input formats |
65 |
|
# |
66 |
|
|
67 |
|
my @inputs; |
68 |
|
if (ref($db_config->{input}) eq 'ARRAY') { |
69 |
|
@inputs = @{ $db_config->{input} }; |
70 |
|
} else { |
71 |
|
push @inputs, $db_config->{input}; |
72 |
|
} |
73 |
|
|
74 |
|
foreach my $input (@inputs) { |
75 |
|
$log->info("working on input $input->{path} [$input->{type}]"); |
76 |
|
|
77 |
|
my $isis = new WebPAC::Input::ISIS( |
78 |
|
code_page => $config->{webpac}->{webpac_encoding}, |
79 |
|
limit_mfn => $input->{limit}, |
80 |
|
); |
81 |
|
|
82 |
|
my $maxmfn = $isis->open( |
83 |
|
filename => $input->{path}, |
84 |
|
code_page => $input->{encoding}, # database encoding |
85 |
|
); |
86 |
|
|
87 |
|
my $n = new WebPAC::Normalize::XML( |
88 |
|
# filter => { 'foo' => sub { shift } }, |
89 |
|
db => $db, |
90 |
|
lookup_regex => $lookup->regex, |
91 |
|
lookup => $lookup, |
92 |
|
); |
93 |
|
|
94 |
|
$n->open( |
95 |
|
tag => $input->{normalize}->{tag}, |
96 |
|
xml_file => $input->{normalize}->{path}, |
97 |
|
); |
98 |
|
|
99 |
|
for ( 0 ... $isis->size ) { |
100 |
|
|
101 |
|
my $row = $isis->fetch || next; |
102 |
|
|
103 |
|
my $mfn = $row->{'000'}->[0] || die "can't find MFN"; |
104 |
|
|
105 |
|
my $ds = $n->data_structure($row); |
106 |
|
|
107 |
|
$est->add( |
108 |
|
id => $input->{name} . "#" . $mfn, |
109 |
|
ds => $ds, |
110 |
|
type => $config->{hyperestraier}->{type}, |
111 |
|
); |
112 |
|
|
113 |
|
$total_rows++; |
114 |
|
} |
115 |
|
|
116 |
|
}; |
117 |
|
|
118 |
|
$log->info("$total_rows records indexed"); |
119 |
|
} |
120 |
|
|
|
$log->info("$total_rows records indexed"); |
|