/[webpac2]/trunk/run.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/run.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 74 by dpavlin, Sun Nov 20 20:13:39 2005 UTC revision 233 by dpavlin, Tue Dec 6 16:40:18 2005 UTC
# Line 9  use lib './lib'; Line 9  use lib './lib';
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 $abs_path = abs_path($0);  my $limit = shift @ARGV;
 $abs_path =~ s#/[^/]*$#/#;  
20    
21  my $isis_file = '/data/isis_data/ps/LIBRI/LIBRI';  my $config = LoadFile('conf/config.yml');
22    
23  my $lookup = new WebPAC::Lookup(  print "config = ",Dumper($config);
         lookup_file => "$abs_path/conf/lookup/isis.pm",  
 );  
24    
25  my $isis = new WebPAC::Input::ISIS(  die "no databases in config file!\n" unless ($config->{databases});
         code_page => 'ISO-8859-2',      # application encoding  
         limit_mfn => 50,  
 );  
26    
27  my $maxmfn = $isis->open(  my $total_rows = 0;
         filename => $isis_file,  
         code_page => '852',             # database encoding  
 );  
28    
29  my $path = './db/';  while (my ($database, $db_config) = each %{ $config->{databases} }) {
30    
31  my $db = new WebPAC::DB(          my $abs_path = abs_path($0);
32          path => $path,          $abs_path =~ s#/[^/]*$#/#;
 );  
33    
34  my $n = new WebPAC::Normalize::XML(          my $db_path = $config->{webpac}->{db_path} . '/' . $database;
 #       filter => { 'foo' => sub { shift } },  
         db => $db,  
         lookup_regex => $lookup->regex,  
         lookup => $lookup,  
 );  
35    
36  $n->open(          my $db = new WebPAC::Store(
37          tag => 'isis',                  path => $db_path,
38          xml_file => "$abs_path/conf/normalize/isis_ffzg.xml",                  database => $database,
39  );                  debug => 1,
40            );
41    
42  my $out = new WebPAC::Output::TT(          my $log = $db->_get_logger;
43          include_path => "$abs_path/conf/output/tt",          $log->info("working on $database in $db_path");
         filters => { foo => sub { shift } },  
 );  
44    
45  my $est = new WebPAC::Output::Estraier(          my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
46          url => 'http://localhost:1978/node/webpac2',          $est_config->{database} = $database;
         user => 'admin',  
         passwd => 'admin',  
         database => 'ps',  
 );  
47    
48  while (my $row = $isis->fetch) {          $log->info("using HyperEstraier URL $est_config->{masterurl}");
49    
50          my $mfn = $row->{'000'}->[0] || die "can't find MFN";          my $est = new WebPAC::Output::Estraier(
51                    %{ $est_config },
52            );
53    
54          my $ds = $n->data_structure($row);          #
55            # now, iterate through input formats
56            #
57    
58  #       print STDERR Dumper($row, $ds);          my @inputs;
59            if (ref($db_config->{input}) eq 'ARRAY') {
60                    @inputs = @{ $db_config->{input} };
61            } else {
62                    push @inputs, $db_config->{input};
63            }
64    
65          my $html = $out->apply(          foreach my $input (@inputs) {
                 template => 'html_ffzg.tt',  
                 data => $ds,  
         );  
66    
67          # create test output                  my $type = lc($input->{type});
68    
69          my $file = sprintf('out/%02d.html', $mfn );                  die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis');
         open(my $fh, '>', $file) or die "can't open $file: $!";  
         print $fh $html;  
         close($fh);  
70    
71          $html =~ s#\s*[\n\r]+\s*##gs;                  my $lookup = new WebPAC::Lookup(
72                            lookup_file => $input->{lookup},
73                    );
74    
75  #       print STDERR $html;                  $log->info("working on input $input->{path} [$input->{type}]");
76    
77          $est->add(                  my $isis = new WebPAC::Input::ISIS(
78                  id => $mfn,                          code_page => $config->{webpac}->{webpac_encoding},
79                  ds => $ds,                          limit_mfn => $input->{limit},
80                  type => 'search',                  );
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                            prefix => $input->{name},
93                    );
94    
95                    $n->open(
96                            tag => $input->{normalize}->{tag},
97                            xml_file => $input->{normalize}->{path},
98                    );
99    
100                    for ( 0 ... $isis->size ) {
101    
102                            my $row = $isis->fetch || next;
103    
104                            my $mfn = $row->{'000'}->[0] || die "can't find MFN";
105    
106                            my $ds = $n->data_structure($row);
107    
108                            $est->add(
109                                    id => $input->{name} . "#" . $mfn,
110                                    ds => $ds,
111                                    type => $config->{hyperestraier}->{type},
112                            );
113    
114                            $total_rows++;
115                    }
116    
117            };
118    
119            $log->info("$total_rows records indexed");
120    }
121    
 };  

Legend:
Removed from v.74  
changed lines
  Added in v.233

  ViewVC Help
Powered by ViewVC 1.1.26