6 use File::Temp qw/tempdir/;
10 use WebPAC::Common 0.02;
12 use WebPAC::Input::ISIS;
13 use WebPAC::Store 0.03;
14 use WebPAC::Normalize::XML;
15 use WebPAC::Output::TT;
16 use WebPAC::Output::Estraier 0.05;
17 use YAML qw/LoadFile/;
20 my $limit = shift @ARGV;
22 my $config = LoadFile('conf/config.yml');
24 print "config = ",Dumper($config);
26 die "no databases in config file!\n" unless ($config->{databases});
30 while (my ($database, $db_config) = each %{ $config->{databases} }) {
32 my $log = _new WebPAC::Common()->_get_logger();
35 # open Hyper Estraier database
38 my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
39 $est_config->{database} = $database;
41 $log->info("using HyperEstraier URL $est_config->{masterurl}");
43 my $est = new WebPAC::Output::Estraier(
50 my $abs_path = abs_path($0);
51 $abs_path =~ s#/[^/]*$#/#;
53 my $db_path = $config->{webpac}->{db_path} . '/' . $database;
55 $log->info("working on $database in $db_path");
57 my $db = new WebPAC::Store(
59 database => $database,
65 # now, iterate through input formats
69 if (ref($db_config->{input}) eq 'ARRAY') {
70 @inputs = @{ $db_config->{input} };
71 } elsif ($db_config->{input}) {
72 push @inputs, $db_config->{input};
74 $log->info("database $database doesn't have inputs defined");
77 foreach my $input (@inputs) {
79 my $type = lc($input->{type});
81 die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis');
83 my $lookup = new WebPAC::Lookup(
84 lookup_file => $input->{lookup},
87 $log->info("working on input $input->{path} [$input->{type}]");
89 my $isis = new WebPAC::Input::ISIS(
90 code_page => $config->{webpac}->{webpac_encoding},
91 limit_mfn => $input->{limit},
95 my $maxmfn = $isis->open(
96 filename => $input->{path},
97 code_page => $input->{encoding}, # database encoding
100 my $n = new WebPAC::Normalize::XML(
101 # filter => { 'foo' => sub { shift } },
103 lookup_regex => $lookup->regex,
105 prefix => $input->{name},
108 my $normalize_path = $input->{normalize}->{path};
110 if ($normalize_path =~ m/\.xml$/i) {
112 tag => $input->{normalize}->{tag},
113 xml_file => $input->{normalize}->{path},
115 } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) {
117 path => $normalize_path,
118 tag => $input->{normalize}->{tag},
122 for ( 0 ... $isis->size ) {
124 my $row = $isis->fetch || next;
126 my $mfn = $row->{'000'}->[0] || die "can't find MFN";
128 my $ds = $n->data_structure($row);
131 id => $input->{name} . "#" . $mfn,
133 type => $config->{hyperestraier}->{type},
141 $log->info("$total_rows records indexed");
144 # add Hyper Estraier links to other databases
146 if (ref($db_config->{links}) eq 'ARRAY') {
147 foreach my $link (@{ $db_config->{links} }) {
148 $log->info("adding link $database -> $link->{to} [$link->{credit}]");
152 credit => $link->{credit},