/[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 348 by dpavlin, Sun Jun 13 20:20:29 2004 UTC revision 419 by dpavlin, Thu Sep 9 18:09:21 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}->[$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}->[$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  print Dumper($row);          foreach my $ds (@ds) {
89          foreach my $k (keys %{$row}) {                  next if (! $ds->{'swish'});
90                  if ($k ne "mfn") {  
91                          foreach my $l (@{$row->{$k}}) {                  $index->insert(
92                                  next if (! $l);                          index_name => $ds->{'tag'},
93                                  $l = $cp->convert($l);                          path => $f,
94                                  # has subfields?                          headline => $headline,
95                                  my $val;                          words => join(" ",@{$ds->{'swish'}})
96                                  if ($l =~ m/\^/) {                  );
97                                          foreach my $t (split(/\^/,$l)) {          }
                                                 next if (! $t);  
                                                 $val->{substr($t,0,1)} = substr($t,1);  
                                         }  
                                 } else {  
                                         $val = $l;  
                                 }  
98    
99                                  push @{$data->{$mfn}->{$k}}, $val if ($val && $val ne "");          # 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          foreach my $i (@lookup) {          my $file = "./out/bfilter/$t.txt";
126                  if ($i->{'eval'}) {          $log->info("saving sorted index $t to '$file' [".scalar(@e)." elements]");
127                          my $eval = fill_in($i->{'eval'},$data->{$mfn});  
128                          my $key = fill_in($i->{'key'}, $data->{$mfn});          $webpac->output_file(
129                          my $val = fill_in($i->{'val'}, $data->{$mfn});                  file => $file,
130                          if ($key && $val && eval $eval) {                  template => 'index.tt',
131                                  push @{$data->{lookup}->{$key}}, $val;                  data => \@e,
132                          }                  index_name => $t,
133                  } else {          );
134                          my $key = fill_in($i->{'key'}, $data->{$mfn});  }
135                          my $val = fill_in($i->{'val'}, $data->{$mfn});  
136                          if ($key && $val) {  if (0 && $log->is_debug) {
137                                  push @{$data->{lookup}->{$key}}, $val;          $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    #
145    # tree dump implementation which shouldn't be here :-)
146    #
147    
148    my $file = 'out/browse.html';
149    open(HTML, "> $file") || $log->logdie("can't open '$file'");
150    
151    print HTML qq{
152    <html>
153    <head>
154     <title>Browse</title>
155     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"/>
156    </head>
157    <body>
158    <ul>
159    };
160    
161    foreach my $code (sort keys %{$webpac->{'lookup'}}) {
162    
163            my $l = $webpac->{'lookup'} || $log->logconfess("can't find lookup");
164    
165            if ($code =~ m/^root:/) {
166                    my $v900 = shift @{ $l->{$code} } || $log->logconfess("can't lookup '$code'");
167                    $code =~ s/^root:// || die;
168    
169                    my $term = shift @{ $l->{"d:${v900}"} } || die;
170                    my $mfn = shift @{ $l->{"900_mfn:${v900}"} } || die;
171    
172                    $log->info("$code -> $v900 : $term [$mfn]");
173    
174                    print HTML qq{ <li><a href="thes/$mfn.html">$term</a></li>\n} if (-e "out/thes/$mfn.html");
175    
176                    $log->logconfess("can't find 'a:${code}::'") unless ($l->{"a:${code}::"});
177    
178                    print HTML qq{ <ul>\n};
179    
180                    foreach my $l2_v900 (@{ $l->{"a:${code}::"} }) {
181                            
182                            my $l2_code = shift @{ $l->{"code:${l2_v900}"} } || die;
183                            my $l2_term = shift @{ $l->{"d:$l2_v900"} } || die;
184                            my $l2_mfn = shift @{ $l->{"900_mfn:${l2_v900}"} } || die;
185    
186                            $log->info("$l2_code -> $l2_v900 : $l2_term [$l2_mfn]");
187    
188                            print HTML qq{  <li><a href="thes/$l2_mfn.html">$l2_term</a></li>\n} if (-e "out/thes/$l2_mfn.html");
189    
190                            print HTML qq{  <ul>\n};
191    
192                            foreach my $l3_v900 (@{ $l->{"a:${l2_code}:"} }) {
193    
194                                    my $l3_term = shift @{ $l->{"d:$l3_v900"} } || die;
195                                    my $l3_mfn = shift @{ $l->{"900_mfn:${l3_v900}"} } || die;
196    
197                                    $log->info(" -> $l3_v900 : $l3_term [$l3_mfn]");
198    
199                                    print HTML qq{   <li><a href="thes/$l3_mfn.html">$l3_term</a></li>\n} if (-e "out/thes/$l3_mfn.html");
200                          }                          }
201    
202                            print HTML qq{  </ul>\n};
203                  }                  }
204                    print HTML qq{ </ul>\n};
205          }          }
   
206  }  }
 print "\n";  
207    
208  for (my $mfn = 1; $mfn <= $maxmfn; $mfn++) {  print HTML qq{
209          my $d = $data->{$mfn};  </ul>
210          print $d->{'250'}->[0]->{'a'},"\n";  </body>
211          my $t = fill_in('v553^1;;v553^a', $d);  </html>
212          print " Uži pojam: $t\n" if ($t);  };
213          $t = fill_in('[a:v251];;[d:[a:v251]]', $d);  
214          print " Uži pojam: $t\n" if ($t);  $index->close;
 }  
215    
 print Dumper($data);  

Legend:
Removed from v.348  
changed lines
  Added in v.419

  ViewVC Help
Powered by ViewVC 1.1.26