/[webpac]/trunk2/all2all.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 /trunk2/all2all.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 349 by dpavlin, Sun Jun 13 20:39:44 2004 UTC revision 420 by dpavlin, Thu Sep 9 18:25:34 2004 UTC
# Line 2  Line 2 
2    
3  =head1 NAME  =head1 NAME
4    
5  webpac.pl - basic script for all WebPac needs  all2all.pl - basic script for all WebPAC needs
6    
7  =cut  =cut
8    
9  use strict;  use strict;
 use OpenIsis;  
 use Text::Iconv;  
10  use Data::Dumper;  use Data::Dumper;
11    use Carp;
12    
13  my $cp = Text::Iconv->new("852", "iso-8859-2");  use lib './lib';
14    use WebPAC;
15    use WebPAC::jsFind;
16    use WebPAC::Index;
17    
18    my $webpac = new WebPAC(
19            code_page => 'ISO-8859-2',
20    #       limit_mfn => 500,
21    #       debug => 1,
22    ) || die;
23    
24    my $log = $webpac->_get_logger();
25    
26    my $index = new WebPAC::jsFind(
27            index_path => './out/index',
28            keys => 10,
29    ) || die;
30    
31    my $thes;
32    
33  $|=1;  $|=1;
34    
35  my $db = OpenIsis::open( shift @ARGV || '/data/hidra/THS-500/THS' );  my $maxmfn = $webpac->open_isis(
36  my $maxmfn = OpenIsis::maxRowid( $db ) || 1;          filename => shift @ARGV || '/data/hidra/THS/THS',
37            lookup => [
38            { 'key' => 'd:v900', 'val' => 'v250^a' },
39    #       { 'eval' => '"v901^a" eq "Područje"', 'key' => 'pa:v561^4:v562^4:v461^1', 'val' => 'v900' },
40    #       { 'eval '=> '"v901^a" eq "Mikrotezaurus"', 'key' => 'a:v561^4:v562^4:v461^1', 'val' => 'v900' },
41    #       { 'eval' => '"v901^a" eq "Deskriptor"', 'key' => 'a:v561^4:v562^4:v461^1', 'val' => 'v900' },
42            { 'key' => 'a:v561^4:v562^4:v461^1', 'val' => 'v900' },
43            { 'key' => '900_mfn:v900', 'val' => 'v000' },
44            # tree structure
45            { 'eval' => 'length("v251") == 2', 'key' => 'root:v251', 'val' => 'v900' },
46            { 'eval' => '"v251"', 'key' => 'code:v900', 'val' => 'v561^4:v251' },
47            ],
48    );
49    
50  print "rows: $maxmfn\n\n";  $log->info("rows: $maxmfn");
51    
52  my $data;  $webpac->open_import_xml(type => 'isis_hidra_ths');
53    
54  my @lookup = (  while (my $rec = $webpac->fetch_rec) {
         { 'key' => 'd:v900', 'val' => 'v250^a' },  
         { 'eval' => '"v901^a" eq "Područje"', 'key' => 'pa:v561^4:v562^4:v461^1', 'val' => 'v900' },  
         { 'eval '=> '"v901^a" eq "Mikrotezaurus"', 'key' => 'ma:v561^4:v562^4:v461^1', 'val' => 'v900' },  
         { 'eval' => '"v901^a" eq "Deskriptor"', 'key' => 'da:v561^4:v562^4:v461^1', 'val' => 'v900' },  
 );  
55    
56  sub fill_in {          my @ds = $webpac->data_structure($rec);
         my $tmp = shift || return;  
         my $data = shift || return;  
         my $i = shift || 0;  
   
         my $found = 0;  
   
         sub get_sf {  
                 my ($found,$data,$f,$sf,$i) = @_;  
                 if ($$data->{$f} && $$data->{$f}->[$i]->{$sf}) {  
                         $$found++;  
                         return $$data->{$f}->[$i]->{$sf};  
                 } else {  
                         return '';  
                 }  
         }  
57    
58          sub get_nosf {          if (0 && $log->is_debug) {
59                  my ($found,$data,$f,$i) = @_;                  $log->debug("rec = ",Dumper($rec));
60                  if ($$data->{$f} && $$data->{$f}->[$i]) {                  $log->debug("ds = ",Dumper(\@ds));
                         $$found++;  
                         return $$data->{$f}->[$i];  
                 } else {  
                         return '';  
                 }  
61          }          }
62    
63          $tmp =~ s/v(\d+)\^(\w)/get_sf(\$found,\$data,$1,$2,$i)/ges;          next if (! @ds);
64          $tmp =~ s/v(\d+)/get_nosf(\$found,\$data,$1,$i)/ges;  
65            my $filename = $webpac->{'current_filename'};
66    
67          if ($found) {          if ($filename) {
68                  return $tmp;                  $webpac->output_file(
69                            file => $filename,
70                            template => 'html.tt',
71                            data => \@ds,
72                            headline => $webpac->{'headline'},
73                    );
74          } else {          } else {
75                  return;                  print $webpac->output(
76                            template => 'text.tt',
77                            data => \@ds,
78                            headline => $webpac->{'headline'},
79                    );
80          }          }
 }  
81    
82  print "reading database...\n";          my $headline = $webpac->{'headline'};
83    
84  for (my $mfn = 1; $mfn <= $maxmfn; $mfn++) {          my $f = $filename;
85            $f =~ s!out/!!;
86    
87          my $row = OpenIsis::read( $db, $mfn );          # save into index
88          foreach my $k (keys %{$row}) {          foreach my $ds (@ds) {
89                  if ($k ne "mfn") {                  next if (! $ds->{'swish'});
90                          foreach my $l (@{$row->{$k}}) {  
91                                  $l = $cp->convert($l);                  $index->insert(
92                                  # has subfields?                          index_name => $ds->{'tag'},
93                                  my $val;                          path => $f,
94                                  if ($l =~ m/\^/) {                          headline => $headline,
95                                          foreach my $t (split(/\^/,$l)) {                          words => join(" ",@{$ds->{'swish'}})
96                                                  next if (! $t);                  );
97                                                  $val->{substr($t,0,1)} = substr($t,1);          }
                                         }  
                                 } else {  
                                         $val = $l;  
                                 }  
98    
99                                  push @{$data->{$mfn}->{$k}}, $val;          # save into sorted index (thesaurus)
100                          }          foreach my $ds (@ds) {
101                    next if (! $ds->{'index'});
102    
103                    $thes->{$ds->{'tag'}} ||= new WebPAC::Index;
104    
105                    foreach my $h (@{$ds->{'index'}}) {
106                            $thes->{$ds->{'tag'}}->insert(
107                                    path => $f,
108                                    headline => $h,
109                            );
110                  }                  }
111            }
112    
113    #       print Dumper(\@ds);
114    
115    }
116    
117    foreach my $t (keys %{$thes}) {
118    
119            my @e = $thes->{$t}->elements;
120            if (! @e) {
121                    $log->logwarn("no elements in sorted index $t?");
122                    next;
123            }
124    
125            my $file = "./out/bfilter/$t.txt";
126            $log->info("saving sorted index $t to '$file' [".scalar(@e)." elements]");
127    
128            $webpac->output_file(
129                    file => $file,
130                    template => 'index.tt',
131                    data => \@e,
132                    index_name => $t,
133            );
134    }
135    
136    if (0 && $log->is_debug) {
137            $log->debug("lookup hash: ",Dumper($webpac->{'lookup'}));
138            $log->debug("data hash: ",Dumper($webpac->{'data'}));
139            foreach my $t (keys %{$thes}) {
140                    $log->debug("thesaurus $t hash: ",Dumper($thes->{$t}));
141          }          }
142    }
143    
144    $log->info("lookup hash: ",Dumper($webpac->{'lookup'}));
145    
146    #
147    # tree dump implementation which shouldn't be here :-)
148    #
149    
150    my $file = 'out/browse.html';
151    open(HTML, "> $file") || $log->logdie("can't open '$file'");
152    
153    print HTML qq{
154    <html>
155    <head>
156     <title>Browse</title>
157     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"/>
158    </head>
159    <body>
160    <ul>
161    };
162    
163    foreach my $code (sort keys %{$webpac->{'lookup'}}) {
164    
165            my $l = $webpac->{'lookup'} || $log->logconfess("can't find lookup");
166    
167            if ($code =~ m/^root:/) {
168                    my $v900 = shift @{ $l->{$code} } || $log->logconfess("can't lookup '$code'");
169                    $code =~ s/^root:// || die;
170    
171                    my $term = shift @{ $l->{"d:${v900}"} } || die;
172                    my $mfn = shift @{ $l->{"900_mfn:${v900}"} } || die;
173    
174                    $log->info("$code -> $v900 : $term [$mfn]");
175    
176                    print HTML qq{ <li><a href="thes/$mfn.html">$term</a></li>\n} if (-e "out/thes/$mfn.html");
177    
178                    unless ($l->{"a:${code}::"}) {
179                            $log->warn("can't find 'a:${code}::'");
180                            next;
181                    }
182    
183                    print HTML qq{ <ul>\n};
184    
185          foreach my $i (@lookup) {                  foreach my $l2_v900 (@{ $l->{"a:${code}::"} }) {
186                  my $d = $data->{$mfn};                          
187                  if ($i->{'eval'}) {                          my $l2_code = shift @{ $l->{"code:${l2_v900}"} } || die;
188                          my $eval = fill_in($i->{'eval'},$d);                          my $l2_term = shift @{ $l->{"d:$l2_v900"} } || die;
189                          my $key = fill_in($i->{'key'}, $d);                          my $l2_mfn = shift @{ $l->{"900_mfn:${l2_v900}"} } || die;
190                          my $val = fill_in($i->{'val'}, $d);  
191                          if ($key && $val && eval $eval) {                          $log->info("$l2_code -> $l2_v900 : $l2_term [$l2_mfn]");
192                                  push @{$data->{lookup}->{$key}}, $val;  
193                            print HTML qq{  <li><a href="thes/$l2_mfn.html">$l2_term</a></li>\n} if (-e "out/thes/$l2_mfn.html");
194                            
195                            unless ($l->{"a:${l2_code}:"}) {
196                                    $log->warn("can't find 'a:${l2_code}:'");
197                                    next;
198                          }                          }
199                  } else {  
200                          my $key = fill_in($i->{'key'}, $d);                          print HTML qq{  <ul>\n};
201                          my $val = fill_in($i->{'val'}, $d);  
202                          if ($key && $val) {                          foreach my $l3_v900 (@{ $l->{"a:${l2_code}:"} }) {
203                                  push @{$data->{lookup}->{$key}}, $val;  
204                                    my $l3_term = shift @{ $l->{"d:$l3_v900"} } || die;
205                                    my $l3_mfn = shift @{ $l->{"900_mfn:${l3_v900}"} } || die;
206    
207                                    $log->info(" -> $l3_v900 : $l3_term [$l3_mfn]");
208    
209                                    print HTML qq{   <li><a href="thes/$l3_mfn.html">$l3_term</a></li>\n} if (-e "out/thes/$l3_mfn.html");
210                          }                          }
211    
212                            print HTML qq{  </ul>\n};
213                  }                  }
214                    print HTML qq{ </ul>\n};
215          }          }
   
216  }  }
 print "\n";  
217    
218  for (my $mfn = 1; $mfn <= $maxmfn; $mfn++) {  print HTML qq{
219          my $d = $data->{$mfn};  </ul>
220          print $d->{'250'}->[0]->{'a'},"\n";  </body>
221          my $t = fill_in('v553^1;;v553^a', $d);  </html>
222          print " Uži pojam: $t\n" if ($t);  };
223          $t = fill_in('[a:v251];;[d:[a:v251]]', $d);  
224          print " Uži pojam: $t\n" if ($t);  $index->close;
 }  
225    
 print Dumper($data);  

Legend:
Removed from v.349  
changed lines
  Added in v.420

  ViewVC Help
Powered by ViewVC 1.1.26