/[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 76 by dpavlin, Sun Nov 20 20:32:46 2005 UTC revision 251 by dpavlin, Thu Dec 15 14:12:00 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 $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',  
 );  
   
 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,  
         );  
26    
27          # create test output  my $total_rows = 0;
28    
29          my $file = sprintf('out/%02d.html', $mfn );  while (my ($database, $db_config) = each %{ $config->{databases} }) {
         open(my $fh, '>', $file) or die "can't open $file: $!";  
         print $fh $html;  
         close($fh);  
30    
31          $html =~ s#\s*[\n\r]+\s*##gs;          my $abs_path = abs_path($0);
32            $abs_path =~ s#/[^/]*$#/#;
33    
34  #       print STDERR $html;          my $db_path = $config->{webpac}->{db_path} . '/' . $database;
35    
36          $est->add(          my $db = new WebPAC::Store(
37                  id => $mfn,                  path => $db_path,
38                  ds => $ds,                  database => $database,
39                  type => 'search',                  debug => 1,
40          );          );
41    
42  };          my $log = $db->_get_logger;
43            $log->info("working on $database in $db_path");
44    
45            my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
46            $est_config->{database} = $database;
47    
48            $log->info("using HyperEstraier URL $est_config->{masterurl}");
49    
50            my $est = new WebPAC::Output::Estraier(
51                    %{ $est_config },
52            );
53    
54            #
55            # now, iterate through input formats
56            #
57    
58            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            foreach my $input (@inputs) {
66    
67                    my $type = lc($input->{type});
68    
69                    die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis');
70    
71                    my $lookup = new WebPAC::Lookup(
72                            lookup_file => $input->{lookup},
73                    );
74    
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                            lookup => $lookup,
81                    );
82    
83                    my $maxmfn = $isis->open(
84                            filename => $input->{path},
85                            code_page => $input->{encoding},        # database encoding
86                    );
87    
88    $log->info( Dumper($lookup->{_lookup_data}) );
89    
90                    my $n = new WebPAC::Normalize::XML(
91                    #       filter => { 'foo' => sub { shift } },
92                            db => $db,
93                            lookup_regex => $lookup->regex,
94                            lookup => $lookup,
95                            prefix => $input->{name},
96                    );
97    
98                    $n->open(
99                            tag => $input->{normalize}->{tag},
100                            xml_file => $input->{normalize}->{path},
101                    );
102    
103                    for ( 0 ... $isis->size ) {
104    
105                            my $row = $isis->fetch || next;
106    
107                            my $mfn = $row->{'000'}->[0] || die "can't find MFN";
108    
109                            my $ds = $n->data_structure($row);
110    
111                            $est->add(
112                                    id => $input->{name} . "#" . $mfn,
113                                    ds => $ds,
114                                    type => $config->{hyperestraier}->{type},
115                            );
116    
117                            $total_rows++;
118                    }
119    
120            };
121    
122            $log->info("$total_rows records indexed");
123    }
124    

Legend:
Removed from v.76  
changed lines
  Added in v.251

  ViewVC Help
Powered by ViewVC 1.1.26