/[webpac]/trunk/filter/mem_lookup.pm
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 /trunk/filter/mem_lookup.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 207 - (hide annotations)
Sat Jan 31 21:03:06 2004 UTC (16 years, 3 months ago) by dpavlin
File size: 2723 byte(s)
thesaurus is finally working... It contains recursive entries to parnet
term, and we actually needed to display narrower terms, so mem_lookup was
created. Important changes:
- you can write eval{"901a" eq "Mikrotezaurus"} within <isis>
  tag and if expression evaluates to false, no content will be outputed
  (It's used to hide microtesarus terms from lover level descriptors)
- mem_lookup.pm now supports formats: you can write something like
  [a:5614];;[d:[a:5614]] and it will correctly embed values

1 dpavlin 205 # this filter is used to find narrower terms in thesaurus which has
2     # only broader terms defined
3     #
4     # it's general purpose memory lookup filter actually with following
5     # sintax:
6     #
7     # prefix syntax before key value is arbitrary. I use here "d" to denote
8     # display value and "a" to denote array (although they are stored the
9     # same: as array with one or more elements)
10     #
11     # store operations:
12     # key: d900, val: 250 (what to display)
13     # <isis filter="mem_lookup">d900 => 250</isis>
14     # key: a4611, val: 900 (parent fields has childs)
15     # <isis filter="mem_lookup">a4611 => 900</isis>
16     #
17     # lookup:
18     # key: a900 (lookup array, delimited by delimiters in one line)
19     # <isis filter="mem_lookup" type="display">[a900]</isis>
20     #
21     # - each key can have more than one value
22     # - storing something into lookup WON'T return any value to
23     # indexer, so it's save to leave type="" undefiend
24     # - lookup will (of course) return one or more values
25    
26     sub mem_lookup {
27     my @out;
28     foreach (@_) {
29     if (/^(.+)\s=>\s(.+)$/) {
30     my ($k,$v) = ($1,$2);
31     # store in array if it doesn't exist
32     if (! grep(/^$v$/, @{$main::cache->{mem_lookup}->{$k}})) {
33     push @{$main::cache->{mem_lookup}->{$k}}, $v;
34 dpavlin 207 #print STDERR "## mem_lookup store: $k => $v [",join("|",@{$main::cache->{mem_lookup}->{$k}}),"]\n";
35 dpavlin 205 }
36     } elsif (/^(.*)\[([^\[]*)\[([^\[\]]+)\]([^\]]*)\](.*)$/) {
37     # indirect lookup [prefix[key]suffix]
38     my ($pre,$prek,$k,$postk,$post) = ($1,$2,$3,$4,$5);
39     if ($main::cache->{mem_lookup}->{$k}) {
40     my @keys = @{$main::cache->{mem_lookup}->{$k}};
41 dpavlin 207 #print STDERR "## mem_lookup fetch keys $pre|$prek|$k|$postk|$post == [".join("|",@keys)."]\n";
42 dpavlin 205 foreach my $k2 (@keys) {
43 dpavlin 207 my $full_k = $prek.$k2.$postk;
44     if ($main::cache->{mem_lookup}->{$full_k}) {
45     foreach my $v (@{$main::cache->{mem_lookup}->{$full_k}}) {
46     my ($pret,$postt) = ($pre,$post);
47     $pret=~s/\[$k\]/$k2/g;
48     $postt=~s/\[$k\]/$k2/g;
49     push @out,$pret.$v.$postt;
50 dpavlin 205 }
51     }
52     }
53 dpavlin 207 #print STDERR "## mem_lookup return values $pre\[$prek\[$k\]$postk\]$post == [".join("|",@out)."]\n";
54 dpavlin 205
55     }
56     } elsif (/^(.*)\[([^\[\]]+)\](.*)$/) {
57     # direct lookup [key]
58     my ($pre,$k,$post) = ($1,$2,$3);
59     if ($main::cache->{mem_lookup}->{$k}) {
60     #print STDERR "## mem_lookup fetch $k == ".join("|",@{$main::cache->{mem_lookup}->{$k}})."\n";
61     foreach my $v (@{$main::cache->{mem_lookup}->{$k2}}) {
62     push @out,$pre.$v.$post;
63     }
64     }
65     #print STDERR "## mem_lookup return values $k == ".join("|",@out)."\n";
66    
67     } else {
68     # value is undef
69     #warn "mem_lookup: invalid filter specification: '$_'";
70     }
71     }
72     #print STDERR "mem_lookup dump: ",Dumper($main::cache->{mem_lookup}),"\n";
73 dpavlin 207 #print STDERR "out: ".Dumper(@out)."\n" if (@out);
74 dpavlin 205 return @out;
75     }
76    
77     1;

Properties

Name Value
cvs2svn:cvs-rev 1.2

  ViewVC Help
Powered by ViewVC 1.1.26