/[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 285 by dpavlin, Sun Dec 18 21:06:39 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::DB;  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;  use WebPAC::Output::Estraier 0.05;
17    use YAML qw/LoadFile/;
18    use LWP::Simple;
19    
20  my $abs_path = abs_path($0);  my $limit = shift @ARGV;
 $abs_path =~ s#/[^/]*$#/#;  
21    
22  my $isis_file = '/data/isis_data/ps/LIBRI/LIBRI';  my $config = LoadFile('conf/config.yml');
23    
24  my $lookup = new WebPAC::Lookup(  print "config = ",Dumper($config);
         lookup_file => "$abs_path/conf/lookup/isis.pm",  
 );  
25    
26  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,  
 );  
27    
28  my $maxmfn = $isis->open(  my $total_rows = 0;
         filename => $isis_file,  
         code_page => '852',             # database encoding  
 );  
29    
30  my $path = './db/';  while (my ($database, $db_config) = each %{ $config->{databases} }) {
31    
32  my $db = new WebPAC::DB(          my $log = _new WebPAC::Common()->_get_logger();
         path => $path,  
 );  
33    
34  my $n = new WebPAC::Normalize::XML(          #
35  #       filter => { 'foo' => sub { shift } },          # open Hyper Estraier database
36          db => $db,          #
         lookup_regex => $lookup->regex,  
         lookup => $lookup,  
 );  
37    
38  $n->open(          my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
39          tag => 'isis',          $est_config->{database} = $database;
         xml_file => "$abs_path/conf/normalize/isis_ffzg.xml",  
 );  
40    
41  my $out = new WebPAC::Output::TT(          $log->info("using HyperEstraier URL $est_config->{masterurl}");
         include_path => "$abs_path/conf/output/tt",  
         filters => { foo => sub { shift } },  
 );  
42    
43  my $est = new WebPAC::Output::Estraier(          my $est = new WebPAC::Output::Estraier(
44          url => 'http://localhost:1978/node/webpac2',                  %{ $est_config },
         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,  
45          );          );
46    
47          # create test output          #
48            # now WebPAC::Store
49          my $file = sprintf('out/%02d.html', $mfn );          #
50          open(my $fh, '>', $file) or die "can't open $file: $!";          my $abs_path = abs_path($0);
51          print $fh $html;          $abs_path =~ s#/[^/]*$#/#;
52          close($fh);  
53            my $db_path = $config->{webpac}->{db_path} . '/' . $database;
54    
55            $log->info("working on $database in $db_path");
56    
57            my $db = new WebPAC::Store(
58                    path => $db_path,
59                    database => $database,
60                    debug => 1,
61            );
62    
         $html =~ s#\s*[\n\r]+\s*##gs;  
63    
64  #       print STDERR $html;          #
65            # now, iterate through input formats
66            #
67    
68            my @inputs;
69            if (ref($db_config->{input}) eq 'ARRAY') {
70                    @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            foreach my $input (@inputs) {
78    
79                    my $type = lc($input->{type});
80    
81                    die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis');
82    
83                    my $lookup = new WebPAC::Lookup(
84                            lookup_file => $input->{lookup},
85                    );
86    
87                    $log->info("working on input $input->{path} [$input->{type}]");
88    
89                    my $isis = new WebPAC::Input::ISIS(
90                            code_page => $config->{webpac}->{webpac_encoding},
91                            limit_mfn => $input->{limit},
92                            lookup => $lookup,
93                    );
94    
95                    my $maxmfn = $isis->open(
96                            path => $input->{path},
97                            code_page => $input->{encoding},        # database encoding
98                    );
99    
100                    my $n = new WebPAC::Normalize::XML(
101                    #       filter => { 'foo' => sub { shift } },
102                            db => $db,
103                            lookup_regex => $lookup->regex,
104                            lookup => $lookup,
105                            prefix => $input->{name},
106                    );
107    
108                    my $normalize_path = $input->{normalize}->{path};
109    
110                    if ($normalize_path =~ m/\.xml$/i) {
111                            $n->open(
112                                    tag => $input->{normalize}->{tag},
113                                    xml_file => $input->{normalize}->{path},
114                            );
115                    } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) {
116                            $n->open_yaml(
117                                    path => $normalize_path,
118                                    tag => $input->{normalize}->{tag},
119                            );
120                    }
121    
122                    for ( 0 ... $isis->size ) {
123    
124                            my $row = $isis->fetch || next;
125    
126                            my $mfn = $row->{'000'}->[0] || die "can't find MFN";
127    
128                            my $ds = $n->data_structure($row);
129    
130                            $est->add(
131                                    id => $input->{name} . "#" . $mfn,
132                                    ds => $ds,
133                                    type => $config->{hyperestraier}->{type},
134                            );
135    
136                            $total_rows++;
137                    }
138    
139            };
140    
141            $log->info("$total_rows records indexed");
142    
143            #
144            # add Hyper Estraier links to other databases
145            #
146            if (ref($db_config->{links}) eq 'ARRAY') {
147                    foreach my $link (@{ $db_config->{links} }) {
148                            $log->info("adding link $database -> $link->{to} [$link->{credit}]");
149                            $est->add_link(
150                                    from => $database,
151                                    to => $link->{to},
152                                    credit => $link->{credit},
153                            );
154                    }
155            }
156    
157          $est->add(  }
                 id => $mfn,  
                 ds => $ds,  
                 type => 'search',  
         );  
158    
 };  

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

  ViewVC Help
Powered by ViewVC 1.1.26