/[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 217 by dpavlin, Mon Dec 5 17:47:51 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 $type = lc($db_config->{input}->{type});
         path => $path,  
 );  
32    
33  my $n = new WebPAC::Normalize::XML(          die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis');
 #       filter => { 'foo' => sub { shift } },  
         db => $db,  
         lookup_regex => $lookup->regex,  
         lookup => $lookup,  
 );  
34    
35  $n->open(          my $abs_path = abs_path($0);
36          tag => 'isis',          $abs_path =~ s#/[^/]*$#/#;
         xml_file => "$abs_path/conf/normalize/isis_ffzg.xml",  
 );  
37    
38  my $out = new WebPAC::Output::TT(          my $lookup = new WebPAC::Lookup(
39          include_path => "$abs_path/conf/output/tt",                  lookup_file => $db_config->{input}->{lookup},
40          filters => { foo => sub { shift } },          );
 );  
41    
42  my $est = new WebPAC::Output::Estraier(          my $db_path = $config->{webpac}->{db_path} . '/' . $database;
         url => 'http://localhost:1978/node/webpac2',  
         user => 'admin',  
         passwd => 'admin',  
         database => 'ps',  
 );  
43    
 while (my $row = $isis->fetch) {  
44    
45          my $mfn = $row->{'000'}->[0] || die "can't find MFN";          my $log = $lookup->_get_logger;
46            $log->info("working on $database in $db_path");
47    
48          my $ds = $n->data_structure($row);          my $db = new WebPAC::Store(
49                    path => $db_path,
50                    database => $database,
51            );
52    
53  #       print STDERR Dumper($row, $ds);          my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
54            $est_config->{database} = $database;
55    
56          my $html = $out->apply(          $log->info("using HyperEstraier URL $est_config->{masterurl}");
                 template => 'html_ffzg.tt',  
                 data => $ds,  
         );  
57    
58          # create test output          my $est = new WebPAC::Output::Estraier(
59                    %{ $est_config },
60            );
61    
62          my $file = sprintf('out/%02d.html', $mfn );          #
63          open(my $fh, '>', $file) or die "can't open $file: $!";          # now, iterate through input formats
64          print $fh $html;          #
65          close($fh);  
66            my @inputs;
67            if (ref($db_config->{input}) eq 'ARRAY') {
68                    @inputs = @{ $db_config->{input} };
69            } else {
70                    push @inputs, $db_config->{input};
71            }
72    
73            foreach my $input (@inputs) {
74                    $log->info("working on input $input->{path} [$input->{type}]");
75    
76                    my $isis = new WebPAC::Input::ISIS(
77                            code_page => $config->{webpac}->{webpac_encoding},
78                            limit_mfn => $input->{limit},
79                    );
80    
81                    my $maxmfn = $isis->open(
82                            filename => $input->{path},
83                            code_page => $input->{encoding},        # database encoding
84                    );
85    
86                    my $n = new WebPAC::Normalize::XML(
87                    #       filter => { 'foo' => sub { shift } },
88                            db => $db,
89                            lookup_regex => $lookup->regex,
90                            lookup => $lookup,
91                    );
92    
93                    $n->open(
94                            tag => $input->{normalize}->{tag},
95                            xml_file => $input->{normalize}->{path},
96                    );
97    
98                    for ( 0 ... $isis->size ) {
99    
100                            my $row = $isis->fetch || next;
101    
102                            my $mfn = $row->{'000'}->[0] || die "can't find MFN";
103    
104                            my $ds = $n->data_structure($row);
105    
106                            $est->add(
107                                    id => $input->{name} . "#" . $mfn,
108                                    ds => $ds,
109                                    type => $config->{hyperestraier}->{type},
110                            );
111    
112          $html =~ s#\s*[\n\r]+\s*##gs;                          $total_rows++;
113                    }
114    
115  #       print STDERR $html;          };
116    
117          $est->add(          $log->info("$total_rows records indexed");
118                  id => $mfn,  }
                 ds => $ds,  
                 type => 'search',  
         );  
119    
 };  

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

  ViewVC Help
Powered by ViewVC 1.1.26