/[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

Annotation of /trunk2/all2all.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 348 - (hide annotations)
Sun Jun 13 20:20:29 2004 UTC (15 years, 3 months ago) by dpavlin
File MIME type: text/plain
File size: 2643 byte(s)
first commit of new code

1 dpavlin 1 #!/usr/bin/perl -w
2    
3 dpavlin 348 =head1 NAME
4    
5     webpac.pl - basic script for all WebPac needs
6    
7     =cut
8    
9 dpavlin 1 use strict;
10     use OpenIsis;
11 dpavlin 348 use Text::Iconv;
12 dpavlin 1 use Data::Dumper;
13    
14 dpavlin 348 my $cp = Text::Iconv->new("852", "iso-8859-2");
15    
16 dpavlin 10 $|=1;
17 dpavlin 9
18 dpavlin 348 my $db = OpenIsis::open( shift @ARGV || '/data/hidra/THS-500/THS' );
19     my $maxmfn = OpenIsis::maxRowid( $db ) || 1;
20 dpavlin 13
21 dpavlin 348 print "rows: $maxmfn\n\n";
22 dpavlin 10
23 dpavlin 348 my $data;
24 dpavlin 10
25 dpavlin 348 my @lookup = (
26     { 'key' => 'd:v900', 'val' => 'v250^a' },
27     { 'eval' => '"v901^a" eq "Podruèje"', 'key' => 'pa:v561^4:v562^4:v461^1', 'val' => 'v900' },
28     { 'eval '=> '"v901^a" eq "Mikrotezaurus"', 'key' => 'ma:v561^4:v562^4:v461^1', 'val' => 'v900' },
29     { 'eval' => '"v901^a" eq "Deskriptor"', 'key' => 'da:v561^4:v562^4:v461^1', 'val' => 'v900' },
30 dpavlin 54 );
31 dpavlin 3
32 dpavlin 348 sub fill_in {
33     my $tmp = shift || return;
34     my $data = shift || return;
35     my $i = shift || 0;
36 dpavlin 170
37 dpavlin 348 my $found = 0;
38 dpavlin 177
39 dpavlin 348 sub get_sf {
40     my ($found,$data,$f,$sf,$i) = @_;
41     if ($$data->{$f}->[$i]->{$sf}) {
42     $$found++;
43     return $$data->{$f}->[$i]->{$sf};
44 dpavlin 178 } else {
45 dpavlin 348 return '';
46 dpavlin 178 }
47     }
48    
49 dpavlin 348 sub get_nosf {
50     my ($found,$data,$f,$i) = @_;
51     if ($$data->{$f}->[$i]) {
52     $$found++;
53     return $$data->{$f}->[$i];
54     } else {
55     return '';
56 dpavlin 274 }
57     }
58    
59 dpavlin 348 $tmp =~ s/v(\d+)\^(\w)/get_sf(\$found,\$data,$1,$2,$i)/ges;
60     $tmp =~ s/v(\d+)/get_nosf(\$found,\$data,$1,$i)/ges;
61 dpavlin 279
62 dpavlin 348 if ($found) {
63     return $tmp;
64     } else {
65     return;
66 dpavlin 279 }
67 dpavlin 348 }
68 dpavlin 279
69 dpavlin 348 print "reading database...\n";
70 dpavlin 170
71 dpavlin 348 for (my $mfn = 1; $mfn <= $maxmfn; $mfn++) {
72 dpavlin 13
73 dpavlin 348 my $row = OpenIsis::read( $db, $mfn );
74     print Dumper($row);
75     foreach my $k (keys %{$row}) {
76     if ($k ne "mfn") {
77     foreach my $l (@{$row->{$k}}) {
78     next if (! $l);
79     $l = $cp->convert($l);
80     # has subfields?
81     my $val;
82     if ($l =~ m/\^/) {
83     foreach my $t (split(/\^/,$l)) {
84     next if (! $t);
85     $val->{substr($t,0,1)} = substr($t,1);
86 dpavlin 153 }
87     } else {
88 dpavlin 348 $val = $l;
89 dpavlin 153 }
90    
91 dpavlin 348 push @{$data->{$mfn}->{$k}}, $val if ($val && $val ne "");
92 dpavlin 17 }
93 dpavlin 3 }
94 dpavlin 9
95 dpavlin 348 }
96 dpavlin 13
97 dpavlin 348 foreach my $i (@lookup) {
98     if ($i->{'eval'}) {
99     my $eval = fill_in($i->{'eval'},$data->{$mfn});
100     my $key = fill_in($i->{'key'}, $data->{$mfn});
101     my $val = fill_in($i->{'val'}, $data->{$mfn});
102     if ($key && $val && eval $eval) {
103     push @{$data->{lookup}->{$key}}, $val;
104 dpavlin 59 }
105 dpavlin 348 } else {
106     my $key = fill_in($i->{'key'}, $data->{$mfn});
107     my $val = fill_in($i->{'val'}, $data->{$mfn});
108     if ($key && $val) {
109     push @{$data->{lookup}->{$key}}, $val;
110 dpavlin 178 }
111 dpavlin 59 }
112 dpavlin 3 }
113 dpavlin 13
114 dpavlin 3 }
115 dpavlin 348 print "\n";
116 dpavlin 3
117 dpavlin 348 for (my $mfn = 1; $mfn <= $maxmfn; $mfn++) {
118     my $d = $data->{$mfn};
119     print $d->{'250'}->[0]->{'a'},"\n";
120     my $t = fill_in('v553^1;;v553^a', $d);
121     print " U¾i pojam: $t\n" if ($t);
122     $t = fill_in('[a:v251];;[d:[a:v251]]', $d);
123     print " U¾i pojam: $t\n" if ($t);
124 dpavlin 164 }
125    
126 dpavlin 348 print Dumper($data);

Properties

Name Value
cvs2svn:cvs-rev 1.64
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26