7 |
=cut |
=cut |
8 |
|
|
9 |
use strict; |
use strict; |
10 |
use Data::Dumper; |
use locale; |
11 |
|
use YAML; |
12 |
use Carp; |
use Carp; |
13 |
use Getopt::Long; |
use Getopt::Long; |
14 |
|
|
65 |
{ 'key' => 'a:v561^4:v562^4:v461^1', 'val' => 'v900' }, |
{ 'key' => 'a:v561^4:v562^4:v461^1', 'val' => 'v900' }, |
66 |
{ 'key' => '900_mfn:v900', 'val' => 'v000' }, |
{ 'key' => '900_mfn:v900', 'val' => 'v000' }, |
67 |
# tree structure |
# tree structure |
68 |
{ 'eval' => 'length("v251") == 2', 'key' => 'root:v251', 'val' => 'v900' }, |
{ 'eval' => 'length("v251") == 2 && "v800" =~ m/EUROVOC/ || "v800" =~ m/CROVOC/ && "v251" =~ m/^(H|HD|L|Z|P)$/', 'key' => 'root:v251', 'val' => 'v900' }, |
69 |
{ 'eval' => '"v251"', 'key' => 'code:v900', 'val' => 'v561^4:v251' }, |
{ 'eval' => '"v251"', 'key' => 'code:v900', 'val' => 'v561^4:v251' }, |
70 |
|
{ 'eval' => '"v561^4" && "v562^4"', 'key' => 'code:v900', 'val' => 'v561^4:v562^4' }, |
71 |
], |
], |
72 |
); |
); |
73 |
|
|
84 |
my @ds = $webpac->data_structure($rec); |
my @ds = $webpac->data_structure($rec); |
85 |
|
|
86 |
if (0 && $log->is_debug) { |
if (0 && $log->is_debug) { |
87 |
$log->debug("rec = ",Dumper($rec)); |
$log->debug("rec = ",Dump($rec)); |
88 |
$log->debug("ds = ",Dumper(\@ds)); |
$log->debug("ds = ",Dump(\@ds)); |
89 |
} |
} |
90 |
|
|
91 |
next if (! @ds); |
next if (! @ds); |
116 |
foreach my $ds (@ds) { |
foreach my $ds (@ds) { |
117 |
next if (! $ds->{'swish'}); |
next if (! $ds->{'swish'}); |
118 |
|
|
119 |
|
# strip all non word characters from beginning or end |
120 |
|
# of word |
121 |
|
my $words = join(" ",@{$ds->{'swish'}}); |
122 |
|
$words =~ s/^\W+//; |
123 |
|
$words =~ s/\W*\s+\W*/ /g; |
124 |
|
$words =~ s/\W+$//; |
125 |
|
|
126 |
$index->insert( |
$index->insert( |
127 |
index_name => $ds->{'tag'}, |
index_name => $ds->{'tag'}, |
128 |
path => $f, |
#path => $f, |
129 |
|
path => $webpac->mfn, |
130 |
headline => $headline, |
headline => $headline, |
131 |
words => join(" ",@{$ds->{'swish'}}) |
words => $words, |
132 |
); |
); |
133 |
} |
} |
134 |
|
|
140 |
|
|
141 |
foreach my $h (@{$ds->{'index'}}) { |
foreach my $h (@{$ds->{'index'}}) { |
142 |
$thes->{$ds->{'tag'}}->insert( |
$thes->{$ds->{'tag'}}->insert( |
|
path => $f, |
|
143 |
headline => $h, |
headline => $h, |
144 |
|
mfn => $webpac->mfn, |
145 |
); |
); |
146 |
} |
} |
147 |
} |
} |
148 |
|
|
149 |
# print Dumper(\@ds); |
# print Dump(\@ds); |
150 |
|
|
151 |
} |
} |
152 |
|
|
170 |
} |
} |
171 |
|
|
172 |
if (0 && $log->is_debug) { |
if (0 && $log->is_debug) { |
173 |
$log->debug("lookup hash: ",Dumper($webpac->{'lookup'})); |
$log->debug("lookup hash: ",Dump($webpac->{'lookup'})); |
174 |
$log->debug("data hash: ",Dumper($webpac->{'data'})); |
$log->debug("data hash: ",Dump($webpac->{'data'})); |
175 |
foreach my $t (keys %{$thes}) { |
foreach my $t (keys %{$thes}) { |
176 |
$log->debug("thesaurus $t hash: ",Dumper($thes->{$t})); |
$log->debug("thesaurus $t hash: ",Dump($thes->{$t})); |
177 |
} |
} |
178 |
} |
} |
179 |
|
|
180 |
} # XXX if(0) |
} # XXX if(0) |
181 |
|
|
182 |
$log->debug("lookup hash: ",Dumper($webpac->{'lookup'})); |
$log->debug("lookup hash: ",Dump($webpac->{'lookup'})); |
183 |
|
|
184 |
$log->info("creating tree"); |
$log->info("creating tree"); |
185 |
|
|
199 |
lookup_v900 => sub { shift @{$l->{"root:".$_[0]}} }, |
lookup_v900 => sub { shift @{$l->{"root:".$_[0]}} }, |
200 |
lookup_term => sub { shift @{$l->{"d:".$_[1]}} }, |
lookup_term => sub { shift @{$l->{"d:".$_[1]}} }, |
201 |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[1]}} }, |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[1]}} }, |
202 |
have_children => sub { defined($l->{"a:".$_[0]."::"}) }, |
have_children => sub { return $l->{"a:".$_[0]."::"} }, |
203 |
child_code => sub { return $_[0] }, |
have_children_at_level => sub { |
204 |
|
return unless (defined($l->{"code:".$_[1]})); |
205 |
|
my $code = shift @{$l->{"code:".$_[1]}}; |
206 |
|
print STDERR "## $_[1] -> $code\n"; |
207 |
|
return undef unless($code); |
208 |
|
return(9, $l->{"a:$code:"} ) if (defined($l->{"a:$code:"})); |
209 |
|
}, |
210 |
style => 'display: none', |
style => 'display: none', |
211 |
},{ |
},{ |
212 |
# 1 |
# 1 |
213 |
code_arr => sub { @{$l->{"a:".$_[0]."::"}} }, |
code_arr => sub { @{$_[0]} }, |
214 |
filter_code => sub { shift }, # nop |
filter_code => sub { shift }, # nop |
215 |
lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} }, |
lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} }, |
216 |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
217 |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
218 |
have_children => sub { defined($l->{"a:".$_[1].":"}) }, |
have_children => sub { return $l->{"a:".$_[1].":"} }, |
|
child_code => sub { return $_[1] }, |
|
219 |
style => 'display: none', |
style => 'display: none', |
220 |
},{ |
},{ |
221 |
# 2 |
# 2 |
222 |
code_arr => sub { @{$l->{"a:".$_[0].":"}} }, |
code_arr => sub { @{$_[0]} }, |
223 |
filter_code => sub { shift }, |
filter_code => sub { shift }, |
224 |
lookup_v900 => sub { shift }, |
lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} }, |
225 |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
226 |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
227 |
have_children => sub { defined($l->{"a:".$_[2].":".$_[1]}) }, |
have_children => sub { return $l->{"a:".$_[1].":".$_[0]} }, |
228 |
child_code => sub { return "a:".$_[2].":".$_[1] }, |
#style => 'display: none', |
|
style => 'display: none', |
|
229 |
},{ |
},{ |
230 |
# 3 uži pojam |
# 3 uži pojam |
231 |
code_arr => sub { @{$l->{$_[0]}} }, |
code_arr => sub { @{$_[0]} }, |
232 |
filter_code => sub { shift }, |
filter_code => sub { shift }, |
233 |
lookup_v900 => sub { |
lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} }, |
|
my ($c,$p) = @_; |
|
|
$p =~ s/^a:(..:....):.*$/$1/; |
|
|
return "a:".$p.":".$c; |
|
|
}, |
|
234 |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
235 |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
236 |
have_children => sub { defined($l->{$_[1]}) }, |
have_children => sub { return $l->{"a:".$_[1].":".$_[0]} }, |
|
child_code => sub { return $_[1] }, |
|
237 |
},{ |
},{ |
238 |
# 4 |
# 4 |
239 |
code_arr => sub { @{$l->{$_[0]}} }, |
code_arr => sub { @{$_[0]} }, |
240 |
filter_code => sub { shift }, |
filter_code => sub { shift }, |
241 |
lookup_v900 => sub { |
lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} }, |
|
my ($c,$p) = @_; |
|
|
$p =~ s/^a:(..:....):.*$/$1/; |
|
|
return "a:".$p.":".$c; |
|
|
}, |
|
242 |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
243 |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
244 |
have_children => sub { defined($l->{$_[1]}) }, |
have_children => sub { return $l->{"a:".$_[1].":".$_[0]} }, |
|
child_code => sub { return $_[1] }, |
|
245 |
},{ |
},{ |
246 |
# 5 |
# 5 |
247 |
code_arr => sub { @{$l->{$_[0]}} }, |
code_arr => sub { @{$_[0]} }, |
248 |
filter_code => sub { shift }, |
filter_code => sub { shift }, |
249 |
lookup_v900 => sub { |
lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} }, |
|
my ($c,$p) = @_; |
|
|
$p =~ s/^a:(..:....):.*$/$1/; |
|
|
return "a:".$p.":".$c; |
|
|
}, |
|
250 |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
251 |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
252 |
have_children => sub { defined($l->{$_[1]}) }, |
have_children => sub { return $l->{"a:".$_[1].":".$_[0]} }, |
|
child_code => sub { return $_[1] }, |
|
253 |
},{ |
},{ |
254 |
# 6 |
# 6 |
255 |
code_arr => sub { @{$l->{$_[0]}} }, |
code_arr => sub { @{$_[0]} }, |
256 |
filter_code => sub { shift }, |
filter_code => sub { shift }, |
257 |
lookup_v900 => sub { |
lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} }, |
|
my ($c,$p) = @_; |
|
|
$p =~ s/^a:(..:....):.*$/$1/; |
|
|
return "a:".$p.":".$c; |
|
|
}, |
|
258 |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
259 |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
260 |
have_children => sub { defined($l->{$_[1]}) }, |
have_children => sub { return $l->{"a:".$_[1].":".$_[0]} }, |
|
child_code => sub { return $_[1] }, |
|
261 |
},{ |
},{ |
262 |
# 7 |
# 7 |
263 |
code_arr => sub { @{$l->{$_[0]}} }, |
code_arr => sub { @{$_[0]} }, |
264 |
filter_code => sub { shift }, |
filter_code => sub { shift }, |
265 |
lookup_v900 => sub { |
lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} }, |
|
my ($c,$p) = @_; |
|
|
$p =~ s/^a:(..:....):.*$/$1/; |
|
|
return "a:".$p.":".$c; |
|
|
}, |
|
266 |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
267 |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
268 |
have_children => sub { defined($l->{$_[1]}) }, |
have_children => sub { return $l->{"a:".$_[1].":".$_[0]} }, |
|
child_code => sub { return $_[1] }, |
|
269 |
},{ |
},{ |
270 |
# 8 |
# 8 |
271 |
code_arr => sub { @{$l->{$_[0]}} }, |
code_arr => sub { @{$_[0]} }, |
272 |
filter_code => sub { shift }, |
filter_code => sub { shift }, |
273 |
lookup_v900 => sub { |
lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} }, |
|
my ($c,$p) = @_; |
|
|
$p =~ s/^a:(..:....):.*$/$1/; |
|
|
return "a:".$p.":".$c; |
|
|
}, |
|
274 |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
275 |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
276 |
# have_children => sub { defined($l->{$_[1]}) }, |
# have_children => sub { return $l->{"a:".$_[1].":".$_[0]} }, |
|
# child_code => sub { return $_[1] }, |
|
277 |
have_children => sub { 0 }, |
have_children => sub { 0 }, |
278 |
child_code => sub { 0 }, |
},{ |
279 |
|
# 9 - level which is never reached except explicitly |
280 |
|
code_arr => sub { @{$_[0]} }, |
281 |
|
filter_code => sub { shift }, |
282 |
|
lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} }, |
283 |
|
lookup_term => sub { shift @{$l->{"d:".$_[0]}} }, |
284 |
|
lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} }, |
285 |
|
have_children => sub { 0 }, |
286 |
|
have_children_at_level => sub { defined($l->{"a:".$_[1].":".$_[0]}) && return (9,$l->{"a:".$_[1].":".$_[0]}) }, |
287 |
|
},{ |
288 |
}); |
}); |
289 |
|
|
290 |
my $tree = new WebPAC::Tree( |
my $tree = new WebPAC::Tree( |