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

Legend:
Removed from v.141  
changed lines
  Added in v.214

  ViewVC Help
Powered by ViewVC 1.1.26