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

Contents of /trunk2/all2all.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 349 - (show annotations)
Sun Jun 13 20:39:44 2004 UTC (15 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 2582 byte(s)
don't materialize hash values which are undef

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26