File Coverage

blib/lib/Lingua/YaTeA/Tree.pm
Criterion Covered Total %
statement 209 340 61.4
branch 39 94 41.4
condition 7 24 29.1
subroutine 29 36 80.5
pod 29 31 93.5
total 313 525 59.6


line stmt bran cond sub pod time code
1             package Lingua::YaTeA::Tree;
2 5     5   29 use strict;
  5         9  
  5         130  
3 5     5   24 use warnings;
  5         8  
  5         98  
4 5     5   23 use Lingua::YaTeA::IndexSet;
  5         7  
  5         29  
5 5     5   97 use UNIVERSAL;
  5         8  
  5         17  
6 5     5   114 use Scalar::Util qw(blessed);
  5         8  
  5         14298  
7              
8             our $VERSION=$Lingua::YaTeA::VERSION;
9              
10             sub new
11             {
12 111     111 1 167 my ($class) = @_;
13 111         192 my $this = {};
14 111         166 bless ($this,$class);
15 111         233 $this->{NODE_SET} = ();
16 111         175 $this->{HEAD} = ();
17 111         148 $this->{RELIABILITY} = ();
18 111         238 $this->{INDEX_SET} = Lingua::YaTeA::IndexSet->new();
19 111         208 $this->{SIMPLIFIED_INDEX_SET} = Lingua::YaTeA::IndexSet->new();
20 111         189 return $this;
21             }
22              
23              
24             sub setHead
25             {
26 124     124 1 172 my ($this) = @_;
27              
28 124         237 my $root = $this->getNodeSet->getRoot;
29 124         252 $this->{HEAD} = $root->searchHead(0);
30             }
31              
32              
33              
34             sub setReliability
35             {
36 85     85 1 148 my ($this,$reliability) = @_;
37 85         142 $this->{RELIABILITY} = $reliability;
38             }
39              
40              
41              
42             sub fillNodeLeaves
43             {
44 45     45 1 58 my ($this) = @_;
45 45         78 $this->getNodeSet->fillNodeLeaves($this->getIndexSet);
46             }
47              
48             sub getIndexSet
49             {
50 457     457 1 631 my ($this) = @_;
51 457         1011 return $this->{INDEX_SET};
52             }
53              
54             sub getNodeSet
55             {
56 808     808 1 1041 my ($this) = @_;
57              
58             # print STDERR "gNS1\n";
59              
60 808         1805 return $this->{NODE_SET};
61             }
62              
63              
64             sub setSimplifiedIndexSet
65             {
66 28     28 1 54 my ($this,$original) = @_;
67 28         64 $this->{SIMPLIFIED_INDEX_SET} = $original->copy;
68             }
69              
70             sub copy
71             {
72 38     38 1 64 my ($this) = @_;
73 38         81 my $new = Lingua::YaTeA::Tree->new;
74 38 50       65 if(defined $this->getNodeSet)
75             {
76 38         62 $new->{NODE_SET} = $this->getNodeSet->copy;
77 38         87 $new->{HEAD} = $new->setHead;
78             }
79 38         76 $new->{INDEX_SET} = $this->getIndexSet->copy;
80 38         69 $new->{SIMPLIFIED_INDEX_SET} = $this->getSimplifiedIndexSet->copy;
81 38         88 return $new;
82             }
83              
84              
85             sub getSimplifiedIndexSet
86             {
87 379     379 1 503 my ($this) = @_;
88 379         923 return $this->{SIMPLIFIED_INDEX_SET};
89             }
90              
91              
92             sub getRoot
93             {
94 155     155 1 217 my ($this) = @_;
95 155         231 return $this->getNodeSet->getRoot;
96             }
97              
98             sub updateRoot
99             {
100 72     72 1 111 my ($this) = @_;
101 72         129 $this->getNodeSet->updateRoot;
102             }
103              
104              
105              
106              
107              
108             sub setNodeSet
109             {
110 26     26 1 46 my ($this,$node_set) = @_;
111 26         40 $this->{NODE_SET} = $node_set;
112             }
113              
114              
115             sub addNodes
116             {
117 63     63 1 103 my ($this,$node_set) = @_;
118 63         107 $this->getNodeSet->addNodes($node_set);
119            
120             }
121              
122              
123              
124             sub print
125             {
126 0     0 1 0 my ($this,$words_a,$fh) = @_;
127 0 0       0 if(!defined $fh)
128             {
129 0         0 $fh = \*STDERR;
130             }
131 0         0 print $fh $this . "\n";
132 0         0 print $fh "index set ";
133 0         0 $this->getIndexSet->print($fh);
134 0         0 print $fh "\n";
135 0 0       0 if(defined $this->getSimplifiedIndexSet)
136             {
137 0         0 print $fh "simplified index set ";
138 0         0 $this->getSimplifiedIndexSet->print($fh);
139 0         0 print $fh "\n";
140             }
141 0         0 print $fh "node set : ";
142 0 0       0 if(defined $this->getNodeSet)
143             {
144 0         0 $this->getNodeSet->printAllNodes($words_a,$fh);
145             }
146             }
147              
148              
149             sub printParenthesised
150             {
151 45     45 1 64 my ($this,$words_a,$fh) = @_;
152             # print "(" . $this . ")";
153 45         74 $this->getNodeSet->printParenthesised($words_a,$fh);
154             }
155              
156              
157             sub getHead
158             {
159 0     0 1 0 my ($this) = @_;
160 0         0 return $this->{HEAD};
161             }
162              
163             sub getReliability
164             {
165 0     0 1 0 my ($this) = @_;
166 0         0 return $this->{RELIABILITY};
167             }
168              
169             sub setIndexSet
170             {
171 0     0 1 0 my ($this,$original) = @_;
172 0         0 $this->{INDEX_SET} = $original->copy;
173             }
174              
175             sub check
176             {
177 85     85 1 134 my ($this,$phrase) = @_;
178 85         98 my $if;
179 85         120 my $depth = 0;
180              
181 85         162 $this->getRoot->buildIF(\$if,$phrase->getWords, \$depth);
182 85         636 $if =~ s/ +$//;
183            
184 85 50       294 if($if eq $phrase->getIF)
185             {
186 85         274 return 1;
187             }
188             else
189             {
190             # print "Arbre mal forme :" .$if . "\n";
191             # $this->getNodeSet->printAllNodes($phrase->getWords);
192 0         0 warn "\nArbre mal forme :\'" .$if . "\' pour \'" . $phrase->getIF."\'\n";
193 0         0 return 0;
194             }
195             }
196              
197             sub getIncludedNodes
198             {
199 0     0 0 0 my ($this,$free_nodes_a,$parsing_direction) = @_;
200 0         0 my $node;
201             my $index_set;
202 0         0 my %index_key_to_nodes;
203 0         0 my @index_sets;
204 0         0 my $included_a;
205 0         0 my $included;
206 0         0 my @node_inclusions;
207 0         0 foreach $node (@$free_nodes_a)
208             {
209 0         0 $index_set = Lingua::YaTeA::IndexSet->new;
210 0         0 $node->fillIndexSet($index_set);
211 0         0 $index_key_to_nodes{$index_set->joinAll('-')} = $node;
212 0         0 push @index_sets, $index_set;
213             }
214 0         0 foreach $index_set (@index_sets)
215             {
216 0         0 $included_a = $index_set->getIncluded(\@index_sets,$parsing_direction);
217 0         0 foreach $included (@{$included_a})
  0         0  
218             {
219 0         0 my @pair;
220 0         0 $pair[0] = $index_key_to_nodes{$index_set->joinAll('-')};
221 0         0 $pair[1] = $index_key_to_nodes{$included->joinAll('-')};
222 0         0 ($pair[2],$pair[3]) = $index_set->getIncludedContext($included);
223 0         0 push @node_inclusions,\@pair;
224             }
225             }
226            
227 0         0 return \@node_inclusions;
228             }
229              
230             sub plugNodePairs
231             {
232 8     8 0 21 my ($this,$parsing_pattern_set,$parsing_direction,$tag_set,$words_a,$fh) = @_;
233 8         50 my $free_nodes_a;
234             my $inclusions_a;
235 8         0 my $pair_a;
236 8         0 my $above;
237 8         0 my $below;
238 8         0 my $success;
239 8         0 my $additional_node_set;
240             # $this->print($words_a,$fh);
241 8         19 $free_nodes_a = $this->getNodeSet->searchFreeNodes();
242 8 50       24 if(scalar @$free_nodes_a > 1)
243             {
244             # print $fh "NB FREE: ". scalar @$free_nodes_a . "\n";
245 0         0 $inclusions_a = $this->getIncludedNodes($free_nodes_a,$parsing_direction);
246            
247 0         0 foreach $pair_a (@$inclusions_a)
248             {
249 0         0 $above = $pair_a->[0];
250 0         0 $below = $pair_a->[1];
251            
252 0         0 ($success,$additional_node_set) = $above->plugInternalNode($below,$pair_a->[2],$pair_a->[3],$parsing_pattern_set,$words_a,$parsing_direction,$tag_set,$fh);
253 0 0       0 if($success == 1)
254             {
255 0         0 $this->addNodes($additional_node_set);
256            
257 0         0 $this->getSimplifiedIndexSet->removeIndex($pair_a->[1]->searchHead(0)->getIndex);
258 0         0 $this->updateRoot;
259             # print $fh "accrochage reussi\n";
260 0         0 return 1;
261             }
262             # else
263             # {
264             # print $fh "accrochage impossible\n";
265             # }
266             }
267             ##### TODO: tenter d'accrocher des sous-arbres adjacents ou proches: il existe un patron pour TeteArbre1 [trou: ex: "of a"] TeteArbre2
268             }
269 8         30 return 0;
270             }
271              
272              
273              
274             sub completeDiscontinuousNodes
275             {
276 8     8 1 23 my ($this,$parsing_pattern_set,$parsing_direction,$tag_set,$words_a,$fh) = @_;
277 8         15 my $previous = -1;
278 8         8 my $discontinuous_infos_a;
279 8         18 my $free_nodes_a = $this->getNodeSet->searchFreeNodes($words_a);
280 8         25 my $discontinuous_nodes_a = $this->getDiscontinuousNodes($free_nodes_a,$words_a,$fh);
281            
282 8         27 foreach $discontinuous_infos_a (@$discontinuous_nodes_a)
283             {
284 0         0 $previous = $discontinuous_infos_a->[1];
285 0         0 $discontinuous_infos_a = $discontinuous_infos_a->[0]->isDiscontinuous(\$previous,$words_a,$fh);
286 0 0 0     0 if ((blessed($discontinuous_infos_a->[0])) && ($discontinuous_infos_a->[0]->isa('Lingua::YaTeA::Node')))
287             {
288             # print $fh "dis_a : ". join ("\n",@$discontinuous_infos_a) . "\n";
289             # print $fh "id:" . $discontinuous_infos_a->[0]->getID . "\n";
290             # $this->print($words_a,$fh);
291            
292 0 0       0 if($discontinuous_infos_a->[0]->completeGap($discontinuous_infos_a->[1], $discontinuous_infos_a->[2],$this,$parsing_pattern_set,$parsing_direction,$tag_set,$words_a,$fh) == 1)
293             {
294             # print $fh "completeGap pour " . $discontinuous_infos_a->[0]->getID . " est OK\n";
295             # $this->print($words_a,$fh);
296 0         0 $previous = -1;
297 0 0 0     0 if(
      0        
298             ($discontinuous_infos_a = $discontinuous_infos_a->[0]->isDiscontinuous(\$previous,$words_a,$fh))
299             &&
300             ((blessed($discontinuous_infos_a->[0])) && ($discontinuous_infos_a->[0]->isa('Lingua::YaTeA::Node')))
301             )
302             {
303             # print $fh "push : " . $discontinuous_infos_a->[0]->getID . "\n";
304 0         0 push @$discontinuous_nodes_a,$discontinuous_infos_a;
305             }
306             }
307             }
308             }
309             }
310              
311             sub getDiscontinuousNodes
312             {
313 16     16 1 34 my ($this,$free_nodes_a,$words_a,$fh) = @_;
314 16         19 my $free_node;
315 16         23 my $previous = -1;
316 16         21 my $discontinuous_infos_a;
317             my @discontinuous;
318              
319 16         22 foreach $free_node (@$free_nodes_a)
320             {
321 18         23 $previous = -1;
322 18         57 $discontinuous_infos_a = $free_node->isDiscontinuous(\$previous,$words_a,$fh);
323 18 50 33     50 if ((blessed($discontinuous_infos_a->[0])) && ($discontinuous_infos_a->[0]->isa('Lingua::YaTeA::Node'))){
324 0         0 push @discontinuous,$discontinuous_infos_a;
325             }
326             }
327 16         34 return \@discontinuous;
328            
329              
330             }
331              
332             sub removeDiscontinuousNodes
333             {
334 8     8 1 16 my ($this,$words_a,$fh) = @_;
335 8         13 my $discontinuous;
336 8         11 my $modified = 0;
337 8         9 my @unplugged;
338             # print $fh "tree id: ". $this ."\n";
339 8         24 my $discontinuous_nodes_a = $this->getDiscontinuousNodes($this->getNodeSet->getNodes,$words_a,$fh);
340 8         23 while (scalar @$discontinuous_nodes_a != 0)
341             {
342 0         0 foreach $discontinuous (@$discontinuous_nodes_a)
343             {
344             # print $fh "discon a degager " .$discontinuous->[0]->getID . "\n";
345             # $discontinuous->[0]->printRecursively($words_a,$fh);
346            
347 0         0 push @unplugged, @{$this->getNodeSet->removeNodes($discontinuous->[0],$words_a,$fh)};
  0         0  
348 0         0 $modified = 1;
349             }
350 0         0 $discontinuous_nodes_a = $this->getDiscontinuousNodes($this->getNodeSet->getNodes,$words_a,$fh);
351             }
352              
353 8         21 $this->updateRoot;
354            
355 8         28 return ($modified,\@unplugged);
356             }
357              
358              
359              
360              
361             sub integrateIslandNodeSets
362             {
363 9     9 1 25 my ($this,$node_sets,$index_set,$new_trees_a,$words_a,$tagset,$fh) = @_;
364 9         35 my $to_add;
365             my $save;
366 9         0 my $tree;
367 9         0 my $i;
368 9         14 my $integrated = 0;
369 9         13 my @new_trees;
370             # print $fh "index set a integrer :";
371             # $index_set->print($fh);
372             # print $fh "\nsimplifie :";
373             # $this->getSimplifiedIndexSet->print($fh);
374             # print $fh "\n";
375              
376 9 50       19 if(! $index_set->moreThanOneInCommon($this->getIndexSet))
377             {
378 9 50       41 if(scalar @$node_sets > 1)
379             {
380 0         0 $save = $this->copy;
381             }
382            
383            
384 9         29 for ($i=0; $i < scalar @$node_sets; $i++)
385             {
386 9 50       21 if($i == 0)
387             {
388 9         16 $tree = $this;
389             }
390             else
391             {
392 0         0 $tree = $save->copy;
393             }
394            
395 9         28 $to_add = $node_sets->[$i]->copy;
396              
397 9         20 $to_add->getRoot->linkToIsland;
398 9 50       32 if($tree->append($to_add,$index_set,$new_trees_a,$words_a,$tagset,$fh))
399             {
400 9         24 $integrated = 1;
401             # print $fh "RES/\n";
402             # $tree->getNodeSet->printAllNodes($words_a,$fh);
403             }
404             else
405             {
406 0         0 push @$new_trees_a, $tree;
407             }
408             }
409            
410             }
411             else
412             { # islands are incompatible
413 0         0 push @$new_trees_a, $this;
414             }
415 9         25 return ($integrated);
416             }
417              
418             sub append
419             {
420 74     74 1 170 my ($this,$added_node_set,$added_index_set,$concurrent_trees_a,$words_a,$tagset,$fh) = @_;
421 74         92 my $addition = 0;
422 74         195 my $pivot;
423             my $mode;
424 74         0 my $root;
425 74         0 my $index_set;
426 74         79 my $modified = 0;
427             # print $fh "append: " . $this . " \n";
428             # $added_node_set->print($words_a,$fh);
429             # print $fh "DANS\n";
430            
431 74 100       131 if(!defined $this->getNodeSet)
432             {
433 26         71 $this->setNodeSet($added_node_set);
434 26         33 $pivot = -1;
435 26 50       52 if ($this->getSimplifiedIndexSet->simplify($added_index_set,$added_node_set,$this,$pivot) == -1 ) {return -1;}
  0         0  
436 26         47 push @$concurrent_trees_a, $this;
437 26         106 return 1;
438             }
439             # $this->getNodeSet->print($words_a,$fh);
440             # print STDERR "a1\n";
441            
442             # if($added_index_set->testSyntacticBreakAndRepetition($words_a,$tagset))
443             # {
444              
445            
446 48         96 $pivot = $added_node_set->getRoot->searchHead(0)->getIndex;
447             # print $fh "pivot :" . $pivot . "\n";
448             # print $fh "a chercger dans ";
449             # $this->getIndexSet->print($fh);
450             # print STDERR "a2\n";
451 48 100       101 if(! $this->getIndexSet->indexExists($pivot))
452             {
453 22         48 $pivot = $this->getIndexSet->searchPivot($added_index_set);
454             }
455             # print STDERR "a3\n";
456 48 100       97 if(defined $pivot)
457             {
458 45         96 $index_set = Lingua::YaTeA::IndexSet->new;
459 45         89 $root = $this->getNodeSet->searchRootNodeForLeaf($pivot);
460            
461 45 50       107 if (defined $root) { # Added by Thierry 02/03/2007
462             # warn "==> $root\n";
463             # print $fh "tourve root :" .$root->getID . "\n";
464 45         119 $root->fillIndexSet($index_set);
465             }
466             }
467             else
468             {
469 3         8 $index_set = $this->getIndexSet;
470             }
471             # print STDERR "a4\n";
472              
473             # warn "===>$index_set\n";
474 48         153 $mode = $index_set->defineAppendMode($added_index_set,$pivot,$fh);
475              
476             # print STDERR "a5\n";
477              
478             # warn "<<<<\n";
479 48 50       88 if(defined $mode)
480             {
481             # print $fh "mode :" .$mode. "\n";
482             # print STDERR "$mode\n";
483              
484 48 100       94 if($mode eq "DISJUNCTION")
485             {
486             # print $fh "disjuncted\n";
487 3         12 ($modified,$addition) = $this->appendDisjuncted($added_node_set,$fh);
488             }
489             else
490             {
491 45 100       133 if($mode =~ /INCLUSION/)
492             {
493             # print $fh "inclusion\n";
494 23         73 ($modified,$addition) = $this->appendIncluded($mode,$root,$index_set,$added_node_set,$added_index_set,$pivot,$words_a,$fh);
495            
496             }
497             else
498             {
499 22 50       68 if($mode =~ /ADJUNCTION/)
500             {
501             # print $fh "adjuction\n";
502 22         66 ($modified,$addition) = $this->appendAdjuncts($root,$index_set,$added_node_set,$added_index_set,$pivot,$concurrent_trees_a,$words_a,$fh);
503 22 50       60 if ($addition == -1) {return -1;}
  0         0  
504             }
505             }
506             }
507 48 50       107 if($modified == 1)
508             {
509 48 50       92 if ($this->getSimplifiedIndexSet->simplify($added_index_set,$added_node_set,$this,$pivot,$fh) == -1) {return -1;}
  0         0  
510             # print $fh "push " . $this . "\n";
511 48         94 push @$concurrent_trees_a, $this;
512             }
513             }
514            
515             # }
516             # else
517             # {
518             # print $fh "passe pas le syntactic break\n";
519             # }
520            
521 48 50       86 if($addition == 1)
522             {
523            
524 48         277 return 1;
525             }
526 0         0 return 0;
527             }
528              
529              
530              
531             sub appendAdjuncts
532             {
533 22     22 1 55 my ($this,$root,$index_set,$added_node_set,$added_index_set,$pivot,$concurrent_trees_a,$words_a,$fh) = @_;
534 22         63 my $type;
535             my $place;
536 22         0 my $above;
537 22         0 my $root2;
538 22         55 my $tree_save = $this->copy;
539 22         49 my $added_save = $added_node_set->copy;
540 22         56 my $sub_index_set_save = $index_set->copy;
541 22         48 my $added_index_set_save = $added_index_set->copy;
542 22         36 my $depth = 0;
543 22         36 my $appended = 0;
544 22         45 my $modified = 0;
545 22 100       45 if ($added_node_set->getRoot->searchHead(0)->getIndex == $pivot )
546             {
547             # print $fh "pivot est tete de l'ajout\n";
548 16         341 my $tree2 = $tree_save->copy;
549             # $tree2->print($words_a,$fh);
550 16         41 my $added2 = $added_save->copy;
551 16         39 $root2 = $tree2->getNodeSet->searchRootNodeForLeaf($pivot);
552 16 50 33     72 if ((defined $root) && (defined $root2)) { # Added by Thierry 02/03/2007
553 16         48 ($above,$place) = $root2->searchLeaf($pivot,\$depth);
554             # print $fh "above: " . $above->getID . " plcae: " . $place ."\n";
555            
556 16 50 66     64 if(
      33        
      66        
557             ($above->{"LINKED_TO_ISLAND"} == 0)
558             ||
559             ($above->getEdgeStatus($place) eq "MODIFIER")
560             ||
561             (
562             ($above->{"LINKED_TO_ISLAND"} == 1)
563             &&
564             (
565             ($added2->getRoot->{"LINKED_TO_ISLAND"} == 1)
566             # ||
567             # ($above->searchHead(0)->getIndex == $pivot)
568             )
569             )
570             )
571             {
572 15 50       38 if($above->hitch($place,$added2->getRoot,$words_a,$fh))
573             {
574            
575 15 50       36 if ($tree2->getSimplifiedIndexSet->simplify($added_index_set,$added2,$tree2,$pivot) != -1 )
576             {
577             # print $fh "arbre modifie " . $tree2 . "\n";
578 15         41 $tree2->addNodes($added2);
579             #$tree2->updateRoot;
580 15         42 $root2->searchRoot->hitchMore($tree2->getNodeSet->searchFreeNodes($words_a),$tree2,$words_a,$fh);
581 15         47 $tree2->updateRoot;
582 15         33 push @$concurrent_trees_a,$tree2;
583 15         40 $appended = 1;
584             }
585             else
586             {
587 0         0 $appended = -1;
588             }
589             }
590             }
591             # else
592             # {
593             # print $fh "Linked to island above: " .$above->getID . "\n";
594             # }
595             }
596            
597             }
598 22 50       73 if ($root->searchHead(0)->getIndex == $pivot)
599             {
600             # print $fh "pivot est tete du hook" . $root->getID. " \n";
601             # $this->print($words_a,$fh);
602 22         59 ($above,$place) = $added_node_set->getRoot->searchLeaf($pivot,\$depth);
603 22 50       55 if (defined $above) { # Added by Thierry Hamon 31/01/2007 - to check
604             # print $fh "above: " . $above->getID . " plcae: " . $place ."\n";
605 22 50       69 if($above->hitch($place,$root,$words_a,$fh))
606             {
607 22         60 $this->addNodes($added_node_set);
608 22         62 $above->searchRoot->hitchMore($this->getNodeSet->searchFreeNodes($words_a),$this,$words_a,$fh);
609 22         59 $this->updateRoot;
610 22         42 $appended = 1;
611 22         30 $modified = 1;
612             }
613             }
614             }
615              
616 22         154 return ($modified,$appended);
617             }
618              
619             sub appendIncluded
620             {
621 23     23 1 62 my ($this,$mode,$root,$index_set,$added_node_set,$added_index_set,$pivot,$words_a,$fh) = @_;
622 23         111 my $above;
623             my $above_index_set;
624 23         0 my $below;
625 23         0 my $below_index_set;
626 23         0 my $type;
627 23         0 my $place;
628 23         0 my $intermediate_node;
629 23         37 my $depth = 0;
630             # print STDERR "I1\n";
631 23 50       46 if($mode =~ /REVERSED/)
632             {
633 23         53 $above = $added_node_set->getRoot;
634             # print STDERR "Ib1\n";
635 23         37 $above_index_set = $added_index_set;
636 23         32 $below = $root;
637 23         32 $below_index_set = $index_set;
638            
639             }
640             else
641             {
642 0         0 $above = $root;
643 0         0 $above_index_set = $index_set;
644 0         0 $below = $added_node_set->getRoot;
645             # print STDERR "Ic1\n";
646 0         0 $below_index_set = $added_index_set;
647             }
648             # print STDERR "I2\n";
649              
650 23         61 $type = $below_index_set->appendPosition($pivot);
651            
652             # print STDERR "$type\n";
653             # print $fh "pivot " . $pivot . "\n";
654             # print $fh "cherche1 dans " . $above->getID ."\n";
655             # $above->printRecursively($words_a,$fh);
656 23         71 ($above,$place) = $above->searchLeaf($pivot,\$depth);
657             # print $fh "above1 ok " . $above->getID . " place:" . $place. "\n";
658             # print STDERR "I3\n";
659              
660              
661 23 50       51 if(defined $above)
662             {
663 23         75 ($above,$intermediate_node,$place) = $above->getHookNode($type,$place,$below_index_set,$fh);
664             # print STDERR "I4\n";
665 23 50       55 if(defined $above)
666             {
667             # print $fh "above2 ok " . $above->getID . " place:" . $place. "\n";
668             # print STDERR "I5\n";
669              
670 23 50       68 if($above->hitch($place,$below,$words_a,$fh))
671             {
672             # $above->printRecursively($words_a,$fh);
673             # print STDERR "I6c\n";
674 23         67 $this->addNodes($added_node_set);
675             # print STDERR "I7c\n";
676              
677             # XXXX
678            
679 23         61 $above->searchRoot->hitchMore($this->getNodeSet->searchFreeNodes($words_a),$this,$words_a,$fh);
680              
681             #print STDERR "I8\n";
682              
683 23         71 $this->updateRoot;
684             # print STDERR "I9\n";
685 23         83 return (1,1);
686             }
687             }
688             }
689 0         0 return (0,0);
690             }
691              
692             sub appendDisjuncted
693             {
694 3     3 1 8 my ($this,$added_node_set) = @_;
695 3         19 $this->addNodes($added_node_set);
696 3         9 return (1,1);
697             }
698              
699             sub getAppendContexts
700             {
701 0     0 1   my ($this,$mode,$pivot,$root,$index_set,$added_node_set,$added_index_set,$words_a) = @_;
702 0           my @contexts;
703             my $place;
704 0           my $above;
705 0           my $below;
706 0           my $tree_save = $this->copy;
707 0           my $added_save = $added_node_set->copy;
708 0           my $sub_index_set_save = $index_set->copy;
709 0           my $added_index_set_save = $added_index_set->copy;
710 0           my $depth = 0;
711 0 0         if($mode =~ /INSERTION/)
712             {
713 0 0         if($mode =~ /REVERSED/)
714             {
715 0           ($above,$place) = $added_node_set->getRoot->searchLeaf($pivot,\$depth);
716 0           $below = $root;
717             }
718             else
719             {
720 0           ($above,$place) = $root->searchLeaf($pivot,\$depth);
721 0           $below = $added_node_set->getRoot;
722             }
723 0           my $context = {"ABOVE"=>$above, "PLACE"=>$place, "BELOW" => $below, "TREE"=>$this, "INDEX_SET"=>$index_set, "ADDED_NODE_SET"=>$added_node_set, "ADDED_INDEX_SET"=>$added_index_set};
724 0           push @contexts, $context;
725             }
726             else
727             {
728              
729 0 0         if($mode !~ /MIDDLE/)
730             {
731 0           ($above,$place) = $added_node_set->getRoot->searchLeaf($pivot,\$depth);
732 0           $below = $root;
733 0           my $context = {"ABOVE"=>$above, "PLACE"=>$place, "BELOW" => $below, "TREE"=>$this, "INDEX_SET"=>$index_set, "ADDED_NODE_SET"=>$added_node_set, "ADDED_INDEX_SET"=>$added_index_set};
734 0           push @contexts, $context;
735 0 0         if($root->{"LINKED_TO_ISLAND"} == 0) # conserver cette condion ?
736             {
737 0           my $tree2 = $tree_save->copy;
738              
739 0           my $added2 = $added_save->copy;
740 0           ($above,$place) = $tree2->getNodeSet->getNodeWithPivot($pivot);
741 0           $below = $added2->searchRootNodeForLeaf($pivot);
742 0 0         if (defined $below) { # Added by Thierry 02/03/2007
743 0           my $context2 = {"ABOVE"=>$above, "PLACE"=>$place, "BELOW" => $below, "TREE"=>$tree2, "INDEX_SET"=>$sub_index_set_save, "ADDED_NODE_SET"=>$added2, "ADDED_INDEX_SET"=>$added_index_set_save};
744 0           push @contexts, $context2;
745             }
746             }
747             }
748            
749             else
750             {
751 0           ($above,$place) = $added_node_set->getRoot->searchLeaf($pivot,\$depth);
752 0           $below = $this->getNodeSet->searchRootNodeForLeaf($pivot);
753 0 0         if (defined $below) { # Added by Thierry 02/03/2007
754 0           my $context = {"ABOVE"=>$above, "PLACE"=>$place, "BELOW" => $below, "TREE"=>$this, "INDEX_SET"=>$index_set, "ADDED_NODE_SET"=>$added_node_set, "ADDED_INDEX_SET"=>$added_index_set};
755 0           push @contexts, $context;
756             }
757             }
758             }
759 0           return \@contexts;
760             }
761              
762             sub updateIndexes
763             {
764 0     0 1   my ($this,$phrase_index_set,$words_a) = @_;
765 0           my $heads_h;
766 0           my $index_set = Lingua::YaTeA::IndexSet->new;
767 0           my $simplified_index_set = $phrase_index_set->copy;
768 0           $this->getNodeSet->fillIndexSet($index_set);
769            
770              
771 0           $heads_h = $this->getNodeSet->searchHeads($words_a);
772 0 0         if ($simplified_index_set->simplifyWithSeveralPivots($index_set,$this->getNodeSet,$this,$heads_h) == -1 ) {return -1;}
  0            
773              
774 0           @{$this->getIndexSet->getIndexes} = @{$index_set->getIndexes};
  0            
  0            
775 0           @{$this->getSimplifiedIndexSet->getIndexes} = @{$simplified_index_set->getIndexes};
  0            
  0            
776             }
777              
778             1;
779              
780             __END__