/[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 210 by dpavlin, Mon Dec 5 17:47:04 2005 UTC revision 286 by dpavlin, Sun Dec 18 21:06:46 2005 UTC
# Line 7  use File::Temp qw/tempdir/; Line 7  use File::Temp qw/tempdir/;
7  use Data::Dumper;  use Data::Dumper;
8  use lib './lib';  use lib './lib';
9    
10    use WebPAC::Common 0.02;
11  use WebPAC::Lookup;  use WebPAC::Lookup;
12  use WebPAC::Input::ISIS;  use WebPAC::Input::ISIS 0.02;
13  use WebPAC::Store 0.03;  use WebPAC::Store 0.03;
14  use WebPAC::Normalize::XML;  use WebPAC::Normalize::XML;
15  use WebPAC::Output::TT;  use WebPAC::Output::TT;
16  use WebPAC::Output::Estraier 0.02;  use WebPAC::Output::Estraier 0.05;
17  use YAML qw/LoadFile/;  use YAML qw/LoadFile/;
18  use LWP::Simple;  use LWP::Simple;
19    
# Line 24  print "config = ",Dumper($config); Line 25  print "config = ",Dumper($config);
25    
26  die "no databases in config file!\n" unless ($config->{databases});  die "no databases in config file!\n" unless ($config->{databases});
27    
28    my $total_rows = 0;
29    
30  while (my ($database, $db_config) = each %{ $config->{databases} }) {  while (my ($database, $db_config) = each %{ $config->{databases} }) {
31    
32          my $type = lc($db_config->{input}->{type});          my $log = _new WebPAC::Common()->_get_logger();
33    
34          die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis');          #
35            # open Hyper Estraier database
36            #
37    
38          my $abs_path = abs_path($0);          my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
39          $abs_path =~ s#/[^/]*$#/#;          $est_config->{database} = $database;
40    
41            $log->info("using HyperEstraier URL $est_config->{masterurl}");
42    
43          my $lookup = new WebPAC::Lookup(          my $est = new WebPAC::Output::Estraier(
44                  lookup_file => $db_config->{input}->{lookup},                  %{ $est_config },
45          );          );
46    
47          my $db_path = $config->{webpac}->{db_path} . '/' . $database;          #
48            # now WebPAC::Store
49            #
50            my $abs_path = abs_path($0);
51            $abs_path =~ s#/[^/]*$#/#;
52    
53            my $db_path = $config->{webpac}->{db_path} . '/' . $database;
54    
         my $log = $lookup->_get_logger;  
55          $log->info("working on $database in $db_path");          $log->info("working on $database in $db_path");
56    
         my $isis = new WebPAC::Input::ISIS(  
                 code_page => $config->{webpac}->{webpac_encoding},  
                 limit_mfn => $db_config->{input}->{limit},  
         );  
   
         my $maxmfn = $isis->open(  
                 filename => $db_config->{input}->{path},  
                 code_page => $db_config->{input}->{encoding},   # database encoding  
         );  
   
         my $path = './db/';  
   
57          my $db = new WebPAC::Store(          my $db = new WebPAC::Store(
58                  path => $db_path,                  path => $db_path,
59                    database => $database,
60                    debug => 1,
61          );          );
62    
         my $n = new WebPAC::Normalize::XML(  
         #       filter => { 'foo' => sub { shift } },  
                 db => $db,  
                 lookup_regex => $lookup->regex,  
                 lookup => $lookup,  
         );  
63    
64          $n->open(          #
65                  tag => $db_config->{normalize}->{tag},          # now, iterate through input formats
66                  xml_file => $db_config->{normalize}->{path},          #
         );  
67    
68          my $out = new WebPAC::Output::TT(          my @inputs;
69                  include_path => $config->{webpac}->{template_path},          if (ref($db_config->{input}) eq 'ARRAY') {
70                  filters => { foo => sub { shift } },                  @inputs = @{ $db_config->{input} };
71          );          } elsif ($db_config->{input}) {
72                    push @inputs, $db_config->{input};
73            } else {
74                    $log->info("database $database doesn't have inputs defined");
75            }
76    
77          my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");          my @supported_inputs = keys %{ $config->{webpac}->{inputs} };
         $est_config->{database} = $database;  
78    
79          $log->info("using HyperEstraier URL $est_config->{url}");          foreach my $input (@inputs) {
80    
81          my $est = new WebPAC::Output::Estraier(                  my $type = lc($input->{type});
                 %{ $est_config },  
         );  
82    
83          my $total_rows = 0;                  die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs));
84    
85          for ( 0 ... $isis->size ) {                  my $lookup = new WebPAC::Lookup(
86                            lookup_file => $input->{lookup},
87                    );
88    
89                  my $row = $isis->fetch || next;                  my $input_module = $config->{webpac}->{inputs}->{$type};
90    
91                  my $mfn = $row->{'000'}->[0] || die "can't find MFN";                  $log->info("working on input $input->{path} [$input->{type}] using $input_module");
92    
93                  my $ds = $n->data_structure($row);                  sub new_input {
94                            my $name = shift;
95                            my $args = shift;
96                            new $name->($args);
97                    }
98    
99                    my $input = new_input($input_module,{
100                            code_page => $config->{webpac}->{webpac_encoding},
101                            limit_mfn => $input->{limit},
102                            lookup => $lookup,
103                    });
104                    $log->logdie("can't create input using $input_module") unless ($input);
105    
106                    my $maxmfn = $input->open(
107                            path => $input->{path},
108                            code_page => $input->{encoding},        # database encoding
109                    );
110    
111          #       print STDERR Dumper($row, $ds);                  my $n = new WebPAC::Normalize::XML(
112                    #       filter => { 'foo' => sub { shift } },
113                            db => $db,
114                            lookup_regex => $lookup->regex,
115                            lookup => $lookup,
116                            prefix => $input->{name},
117                    );
118    
119          #       my $html = $out->apply(                  my $normalize_path = $input->{normalize}->{path};
         #               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;  
120    
121                  $est->add(                  if ($normalize_path =~ m/\.xml$/i) {
122                          id => $mfn,                          $n->open(
123                          ds => $ds,                                  tag => $input->{normalize}->{tag},
124                          type => $config->{hyperestraier}->{type},                                  xml_file => $input->{normalize}->{path},
125                  );                          );
126                    } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) {
127                            $n->open_yaml(
128                                    path => $normalize_path,
129                                    tag => $input->{normalize}->{tag},
130                            );
131                    }
132    
133                    for ( 0 ... $input->size ) {
134    
135                            my $row = $input->fetch || next;
136    
137                            my $mfn = $row->{'000'}->[0] || die "can't find MFN";
138    
139                            my $ds = $n->data_structure($row);
140    
141                            $est->add(
142                                    id => $input->{name} . "#" . $mfn,
143                                    ds => $ds,
144                                    type => $config->{hyperestraier}->{type},
145                            );
146    
147                  $total_rows++;                          $total_rows++;
148                    }
149    
150          };          };
151    
152          $log->info("$total_rows records indexed");          $log->info("$total_rows records indexed");
153    
154            #
155            # add Hyper Estraier links to other databases
156            #
157            if (ref($db_config->{links}) eq 'ARRAY') {
158                    foreach my $link (@{ $db_config->{links} }) {
159                            $log->info("adding link $database -> $link->{to} [$link->{credit}]");
160                            $est->add_link(
161                                    from => $database,
162                                    to => $link->{to},
163                                    credit => $link->{credit},
164                            );
165                    }
166            }
167    
168  }  }
169    

Legend:
Removed from v.210  
changed lines
  Added in v.286

  ViewVC Help
Powered by ViewVC 1.1.26