File Coverage

blib/lib/Lingua/YaTeA/Node.pm
Criterion Covered Total %
statement 387 996 38.8
branch 130 458 28.3
condition 60 333 18.0
subroutine 42 72 58.3
pod 62 64 96.8
total 681 1923 35.4


line stmt bran cond sub pod time code
1             package Lingua::YaTeA::Node;
2 5     5   29 use strict;
  5         8  
  5         115  
3 5     5   21 use warnings;
  5         8  
  5         89  
4 5     5   19 use Data::Dumper;
  5         24  
  5         196  
5 5     5   24 use UNIVERSAL;
  5         8  
  5         19  
6 5     5   1807 use Lingua::YaTeA::TermLeaf;
  5         9  
  5         36  
7 5     5   1865 use Lingua::YaTeA::MultiWordTermCandidate;
  5         13  
  5         40  
8 5     5   1870 use Lingua::YaTeA::MonolexicalTermCandidate;
  5         11  
  5         51  
9 5     5   135 use Scalar::Util qw(blessed);
  5         23  
  5         44362  
10              
11             our $id = 0;
12              
13             our $VERSION=$Lingua::YaTeA::VERSION;
14              
15             sub new
16             {
17 571     571 1 842 my ($class,$level) = @_;
18 571         808 my $this = {};
19 571         789 bless ($this,$class);
20 571         1078 $this->{ID} = $id++;
21 571         810 $this->{LEVEL} = $level;
22 571         810 $this->{LEFT_EDGE} = ();
23 571         772 $this->{LEFT_STATUS} = ();
24 571         750 $this->{RIGHT_EDGE} = ();
25 571         779 $this->{RIGHT_STATUS} = ();
26 571         781 $this->{DET} = ();
27 571         1143 $this->{PREP}= ();
28 571         748 $this->{LINKED_TO_ISLAND} = 0;
29 571         1081 return $this;
30             }
31              
32             sub addEdge
33             {
34 600     600 1 914 my ($this,$edge,$status) = @_;
35 600         1731 my %mapping =("M"=>"MODIFIER", "H"=>"HEAD","C1"=>"COORDONNE1", "C2"=>"COORDONNE2" );
36 600 100       1046 if (!defined $this->{LEFT_EDGE}){ # si le fils gauche est vide, on le remplit
37 300         379 $this->{LEFT_EDGE} = $edge;
38 300         717 $this->{LEFT_STATUS} = $mapping{$status};
39             }
40             else{
41 300         362 $this->{RIGHT_EDGE} = $edge; # sinon, on remplit le fils droit
42 300         722 $this->{RIGHT_STATUS} = $mapping{$status};
43             }
44             }
45              
46              
47              
48              
49             sub getEdgeStatus
50             {
51 20     20 1 40 my ($this,$place) = @_;
52 20         90 return $this->{$place.'_STATUS'};
53             }
54              
55             sub getLeftEdgeStatus
56             {
57 154     154 1 235 my ($this) = @_;
58 154         386 return $this->{LEFT_STATUS};
59             }
60              
61             sub getRightEdgeStatus
62             {
63 125     125 1 179 my ($this) = @_;
64 125         302 return $this->{RIGHT_STATUS};
65             }
66              
67             sub getNodeStatus
68             {
69 49     49 1 66 my ($this) = @_;
70 49         60 my $father;
71 49 50 33     249 if ((blessed($this)) && ($this->isa('Lingua::YaTeA::Edge')))
72             {
73 49         80 $father = $this->{FATHER};
74 49 100       95 if ($father->{LEFT_EDGE} == $this)
75             {
76 10         41 return $father->{LEFT_STATUS};
77             }
78             else
79             {
80 39         130 return $father->{RIGHT_STATUS};
81             }
82             }
83             else
84             {
85 0         0 return "ROOT";
86             }
87             }
88              
89             sub getNodePosition
90             {
91 0     0 1 0 my ($this) = @_;
92 0         0 my $father;
93 0 0 0     0 if ((blessed($this)) && ($this->isa('Lingua::YaTeA::Edge')))
94             {
95 0         0 $father = $this->{FATHER};
96 0 0       0 if ($father->{LEFT_EDGE} == $this)
97             {
98 0         0 return "LEFT";
99             }
100             else
101             {
102 0         0 return "RIGHT";
103             }
104             }
105             }
106              
107             sub getHead
108             {
109 685     685 1 860 my ($this) = @_;
110 685 100       1133 if($this->{LEFT_STATUS} eq "HEAD")
111             {
112 227         389 return $this->{LEFT_EDGE};
113             }
114 458         637 return $this->{RIGHT_EDGE};
115             }
116              
117              
118              
119             sub getModifier
120             {
121 0     0 1 0 my ($this) = @_;
122 0 0       0 if($this->{LEFT_STATUS} eq "MODIFIER")
123             {
124 0         0 return $this->{LEFT_EDGE};
125             }
126 0         0 return $this->{RIGHT_EDGE};
127             }
128              
129             sub getLeftEdge
130             {
131 5113     5113 1 6394 my ($this) = @_;
132 5113         6514 return $this->getEdge("LEFT");
133             }
134              
135             sub getRightEdge
136             {
137 4891     4891 1 6074 my ($this) = @_;
138 4891         6293 return $this->getEdge("RIGHT");
139             }
140              
141             sub getEdge
142             {
143 10077     10077 1 11893 my ($this,$position) = @_;
144 10077         29014 return $this->{$position."_EDGE"};
145             }
146              
147             sub getID
148             {
149 1844     1844 1 2258 my ($this) = @_;
150 1844         5191 return $this->{ID};
151              
152             }
153              
154             sub getLevel
155             {
156 64     64 1 96 my ($this) = @_;
157 64         188 return $this->{"LEVEL"};
158             }
159              
160              
161              
162             sub getDeterminer
163             {
164 965     965 1 1216 my ($this) = @_;
165 965         1670 return $this->{DET};
166             }
167              
168             sub getPreposition
169             {
170 1224     1224 1 1592 my ($this) = @_;
171 1224         2304 return $this->{PREP};
172             }
173              
174             sub linkToFather
175             {
176 20     20 1 35 my ($this,$uncomplete_a,$status) = @_;
177 20         27 my $father;
178 20 50       48 if (scalar @$uncomplete_a != 0)
179             {
180 20         34 $father = $uncomplete_a->[$#$uncomplete_a];
181 20         27 $this->{FATHER} = $father;
182 20         44 $father->addEdge($this,$status);
183             }
184            
185             }
186              
187             sub fillLeaves
188             {
189 112     112 1 200 my ($this,$counter_r,$index_set, $depth) = @_;
190              
191 112         134 $depth++;
192 112 50       208 if ($depth < 50) { # Temporary added by Thierry Hamon 02/03/2007
193 112 50       178 if ($this->getLeftEdge eq "")
194             {
195 112         312 $this->{LEFT_EDGE} = Lingua::YaTeA::TermLeaf->new($index_set->getIndex($$counter_r++));
196             }
197             else
198             {
199 0         0 $this->getLeftEdge->fillLeaves($counter_r,$index_set, $depth);
200             }
201            
202 112 100       226 if (defined $this->getPreposition)
203             {
204 28         81 $this->{PREP} = Lingua::YaTeA::TermLeaf->new($index_set->getIndex($$counter_r++));
205             }
206 112 100       261 if (defined $this->getDeterminer)
207             {
208 8         23 $this->{DET} = Lingua::YaTeA::TermLeaf->new($index_set->getIndex($$counter_r++));
209             }
210 112 100       190 if ($this->getRightEdge eq "")
211             {
212 110         221 $this->{RIGHT_EDGE} = Lingua::YaTeA::TermLeaf->new($index_set->getIndex($$counter_r++));
213             }
214             else
215             {
216 2         6 $this->getRightEdge->fillLeaves($counter_r,$index_set, $depth);
217             }
218             } else {
219 0         0 warn "fillLeaves: Going out a deep recursive method call (more than 50 calls)\n";
220             }
221             }
222              
223              
224              
225              
226              
227              
228             sub searchHead
229             {
230 685     685 1 944 my ($this, $depth) = @_;
231             # print $this->getID . "\n";
232 685         1033 my $head = $this->getHead;
233             # print STDERR "==> $depth\r";
234            
235 685 50       1268 if(defined $head) {
236 685         756 $depth++;
237 685 50       959 if ($depth < 50) {
238 685         1278 return $head->searchHead($depth);
239             } else {
240 0         0 warn "searchHead: Going out a deep recursive method call (more than 50 calls)\n";
241 0         0 return undef;
242             }
243             }
244             }
245              
246             sub isLinkedToIsland
247             {
248 0     0 0 0 my ($this) = @_;
249 0         0 return $this->{"LINKED_TO_ISLAND"};
250             }
251              
252              
253             sub printSimple
254             {
255 0     0 1 0 my ($this,$words_a,$fh) = @_;
256 0         0 my $left_edge;
257             my $right_edge;
258 0 0       0 if(!defined $fh)
259             {
260 0         0 $fh = \*STDERR;
261             }
262 0         0 print $fh "\t\t[" . ref($this) ."\n";
263 0         0 print $fh "\t\tid: " . $this->getID . "\n";
264 0         0 print $fh "\t\tlevel:" . $this->getLevel;
265 0         0 print $fh "\t\tlinked to island:" . $this->isLinkedToIsland. "\n";
266            
267              
268 0         0 $left_edge = $this->getLeftEdge;
269 0         0 print $fh "\t\tleft_edge: ";
270 0 0 0     0 if((blessed($left_edge)) && ($left_edge->isa("Lingua::YaTeA::RootNode")))
271             {
272 0         0 print $fh $left_edge->getID . "\n";
273             }
274             else
275             {
276 0         0 $left_edge->print($words_a,$fh);
277             }
278 0         0 print $fh "\t\tleft_status: " . $this->getLeftEdgeStatus . "\n";
279 0 0       0 if (defined $this->{PREP})
280             {
281 0         0 print $fh "\t\tprep: " ;
282 0         0 $this->{PREP}->print($words_a,$fh);
283 0         0 print $fh "\n";
284             }
285 0 0       0 if (defined $this->{DET})
286             {
287 0         0 print $fh "\t\tdet: ";
288 0         0 $this->{DET}->print($words_a,$fh);
289 0         0 print $fh "\n";
290             }
291 0         0 print $fh "\t\tright_edge: ";
292 0         0 $right_edge = $this->getRightEdge;
293 0         0 $right_edge->print($words_a,$fh);
294 0         0 print $fh "\t\tright_status: " . $this->getRightEdgeStatus . "\n";
295 0         0 print $fh "\t\t]\n";
296             }
297              
298             sub printRecursively
299             {
300 0     0 1 0 my ($this,$words_a,$fh) = @_;
301 0         0 my $left_edge;
302             my $right_edge;
303 0 0       0 if(!defined $fh)
304             {
305 0         0 $fh = \*STDERR;
306             }
307 0         0 print $fh "\t\t[" .ref($this) ."\n";
308 0         0 print $fh "\t\tid: " . $this->getID . "\n";
309 0         0 print $fh "\t\tlevel:" . $this->getLevel;
310 0         0 print $fh "\t\tlinked to island:" . $this->isLinkedToIsland. "\n";;
311 0 0 0     0 if((blessed($this)) && ($this->isa('Lingua::YaTeA::InternalNode')))
312             {
313 0         0 $this->printFather($fh);
314             }
315 0         0 $left_edge = $this->getLeftEdge;
316 0         0 print $fh "\t\tleft_edge: ";
317 0         0 $left_edge->print($words_a,$fh);
318              
319 0         0 print $fh "\t\tstatus: " . $this->getLeftEdgeStatus . "\n";
320 0 0       0 if (defined $this->getPreposition)
321             {
322 0         0 print $fh "\t\tprep: ";
323 0 0 0     0 if ((blessed($this->getPreposition)) && ($this->getPreposition->isa('Lingua::YaTeA::TermLeaf')))
324             {
325 0         0 $this->getPreposition->print($words_a,$fh);
326             }
327             else
328             {
329 0         0 print $fh $this->getPreposition;
330             }
331 0         0 print $fh "\n";
332             }
333 0 0       0 if (defined $this->getDeterminer)
334             {
335 0         0 print $fh "\t\tdet: ";
336 0 0 0     0 if ((blessed($this->getPreposition)) && ($this->getPreposition->isa('Lingua::YaTeA::TermLeaf')))
337             {
338 0         0 $this->getDeterminer->print($words_a,$fh);
339             }
340             else
341             {
342 0         0 print $fh $this->getDeterminer;
343             }
344 0         0 print $fh "\n";
345             }
346 0         0 print $fh "\t\tright_edge: ";
347 0         0 $right_edge = $this->getRightEdge;
348              
349 0         0 $right_edge->print($words_a,$fh);
350 0         0 print $fh "\t\tstatus: " . $this->getRightEdgeStatus . "\n";
351            
352 0         0 print $fh "\t\t]\n";
353            
354              
355 0 0 0     0 if ((blessed($left_edge)) && ($left_edge->isa("Lingua::YaTeA::Node")))
356             {
357 0         0 $left_edge->printRecursively($words_a,$fh);
358             }
359 0 0 0     0 if ((blessed($right_edge)) && ($right_edge->isa("Lingua::YaTeA::Node")))
360             {
361 0         0 $right_edge->printRecursively($words_a,$fh);
362             }
363             }
364              
365             sub searchRoot
366             {
367 111     111 1 165 my ($this) = @_;
368 111 50 33     447 if((blessed($this)) && ($this->isa('Lingua::YaTeA::RootNode')))
369             {
370 111         273 return $this;
371             }
372             # print STDERR "S1 ($this)\n";
373 0         0 $this->getFather->searchRoot;
374             }
375              
376             sub hitchMore
377             {
378 60     60 1 100 my ($this,$free_nodes_a,$tree,$words_a,$fh) = @_;
379              
380 60         205 my $pivot;
381             my $node;
382 60         0 my $position;
383 60         0 my $above;
384 60         0 my $below;
385 60         0 my $mode;
386 60         67 my $depth = 0;
387 60         216 my $head;
388             my $place;
389 60         0 my $previous;
390 60         0 my $next;
391 60         0 my $included_index;
392 60         144 my $sub_index_set = Lingua::YaTeA::IndexSet->new;
393 60         166 $this->fillIndexSet($sub_index_set,0);
394 60         115 my $added_index_set;
395             #print $fh "hitchMore dans\n";
396             #$this->printRecursively($words_a,$fh);
397             # print $fh scalar(@$free_nodes_a) . "h1\n";
398              
399              
400 60         106 foreach my $n (@$free_nodes_a)
401             {
402            
403 65 100       107 if($n->getID != $this->getID)
404             {
405             # print $fh "free: \n";
406             # $n->printRecursively($words_a,$fh);
407 5         11 $head= $n->searchHead(0);
408 5 50 33     57 if((defined $head)&&((blessed($head)) && $head->isa('Lingua::YaTeA::TermLeaf')))
      33        
409             {
410 5         12 $pivot = $head->getIndex;
411             # print $fh "pivot " . $pivot . "\n";
412 5         14 $added_index_set = Lingua::YaTeA::IndexSet->new;
413 5         12 $n->fillIndexSet($added_index_set,0);
414 5         8 $depth = 0;
415 5         12 ($node,$position) = $this->searchLeaf($pivot,\$depth);
416 5 100 66     40 if ((blessed($node)) && ($node->isa('Lingua::YaTeA::Node')))
417             {
418            
419 4         14 ($mode) = $sub_index_set->defineAppendMode($added_index_set,$pivot);
420 4 50       10 if(defined $mode)
421             {
422             # print STDERR "mode1 = $mode\n";
423 4 50       10 if($mode ne "DISJUNCTION")
424             {
425              
426 4 100       15 if($mode =~ /INCLUSION/)
427             {
428             # print $fh "inclusion\n";
429 1 50       10 if($mode =~ /REVERSED/)
430             {
431             # print $fh "reversed\n";
432 0         0 $depth = 0;
433 0         0 ($previous,$next) = $added_index_set->getIncludedContext($sub_index_set);
434             #($above,$place) = $n->searchLeaf($pivot,\$depth);
435 0         0 ($above,$place) = $n->searchLeaf($pivot,\$depth);
436 0         0 $below = $node;
437             }
438             else
439             {
440 1         3 $depth = 0;
441 1         4 ($previous,$next) = $sub_index_set->getIncludedContext($added_index_set);
442 1         3 ($above,$place) = $node->searchLeaf($pivot,\$depth);
443 1         3 $below = $n;
444             }
445 1 50       15 if($place eq "LEFT")
446             {
447 0   0     0 while
      0        
      0        
448             (
449             ($above->searchRightMostLeaf(\$depth)->getIndex < $below->searchRightMostLeaf(\$depth)->getIndex)
450             &&
451             (! ((blessed($above)) && ($above->isa('Lingua::YaTeA::RootNode'))))
452             &&
453             ($above->getFather->getLeftEdge->searchRightMostLeaf(\$depth)->getIndex < $below->searchRightMostLeaf(\$depth)->getIndex)
454             )
455             {
456 0         0 $above = $above->getFather;
457             }
458             }
459             else
460             {
461 1 50       4 if($place eq "RIGHT")
462             {
463 1   0     9 while
      33        
      33        
464             (
465             ($above->searchLeftMostLeaf(\$depth)->getIndex > $below->searchLeftMostLeaf(\$depth)->getIndex)
466             &&
467             (! ((blessed($above)) && ($above->isa('Lingua::YaTeA::RootNode'))))
468             &&
469             ($above->getFather->getRightEdge->searchLeftMostLeaf(\$depth)->getIndex > $below->searchLeftMostLeaf(\$depth)->getIndex)
470             )
471             {
472 0         0 $above = $above->getFather;
473             }
474             }
475             }
476             }
477             else
478             {
479 3 50       17 if($mode eq "ADJUNCTION")
480             {
481             # print $fh "adjunction\n";
482             # print STDERR "hm1\n";
483 3         6 $depth = 0;
484 3         7 ($above,$place) = $node->searchLeaf($pivot,\$depth);
485             # print STDERR "hm2\n";
486 3         5 $below = $n;
487             }
488             }
489             # print STDERR "hm3\n";
490            
491 4 50       15 if($above->hitch($place,$below,$words_a,$fh))
492             {
493 4         13 $tree->updateRoot;
494             }
495             # print $fh "apres hitch dans hitchmore\n";
496             # $above->printRecursively($words_a,$fh);
497             # print STDERR "hm4\n";
498              
499             }
500             else
501             {
502 0         0 warn "DISJUNCTION (ignore but what to do ?)\n";
503             }
504             }
505              
506             }
507             else
508             {
509 1         2 $depth = 0;
510 1         4 $head = $this->searchHead(0);
511 1 50 33     10 if ((defined $head) && ((blessed($head)) && ($head->isa('Lingua::YaTeA::TermLeaf'))))
      33        
512             {
513 1         4 $pivot = $head->getIndex;
514 1         3 ($node,$position) = $n->searchLeaf($pivot,\$depth);
515 1 50 33     7 if ((blessed($node)) && ($node->isa('Lingua::YaTeA::Node')))
516             {
517 0         0 ($mode) = $added_index_set->defineAppendMode($sub_index_set,$pivot);
518            
519 0 0       0 if(defined $mode)
520             {
521 0 0       0 if($mode ne "DISJUNCTION")
522             {
523             # print STDERR "mode2 = $mode\n";
524 0 0       0 if($mode =~ /INCLUSION/)
525             {
526 0 0       0 if($mode =~ /REVERSED/)
527             {
528 0         0 $depth = 0;
529 0         0 ($above,$place) = $this->searchLeaf($pivot,\$depth);
530 0         0 $below = $node;
531             }
532             else
533             {
534 0         0 $depth = 0;
535 0         0 ($above,$place) = $n->searchLeaf($pivot,\$depth);
536 0         0 $below = $this;
537             }
538             }
539             else
540             {
541 0 0       0 if($mode eq "ADJUNCTION")
542             {
543 0         0 $depth = 0;
544 0         0 ($above,$place) = $n->searchLeaf($pivot,\$depth);
545 0         0 $below = $this;
546             }
547             }
548              
549 0         0 $above->hitch($place,$below,$words_a);
550             }
551             }
552             }
553             }
554             }
555             }
556              
557             }
558             }
559             }
560              
561              
562             sub hitch
563             {
564 64     64 1 130 my ($this,$place,$to_add,$words_a,$fh) = @_;
565 64 100       131 if(defined $fh)
566             {
567             # print $fh "hook\n";
568            
569             # print STDERR "hi1\n";
570             # $this->printRecursively($words_a,$fh);
571             # print $fh "to add\n";
572             # $to_add->printRecursively($words_a,$fh);
573             }
574 64 50       147 if($this->checkCompatibility($place,$to_add,$fh))
575             {
576             # print STDERR "hi2\n";
577             # if(defined $fh)
578             # {
579             # print $fh "compatibles\n";
580             # }
581 64 50 33     332 if ((blessed($to_add)) && ($to_add->isa('Lingua::YaTeA::RootNode')))
582             {
583 64         107 bless ($to_add,'Lingua::YaTeA::InternalNode');
584             }
585             # print STDERR "hi3\n";
586 64 50 33     372 if ((blessed($this->{$place."_EDGE"})) && ($this->{$place."_EDGE"}->isa('Lingua::YaTeA::InternalNode')))
587             {
588 0         0 $to_add->plugSubNodeSet($this->{$place."_EDGE"});
589             }
590              
591             # print STDERR "hi4\n";
592 64         223 $to_add->setFather($this);
593             # print STDERR "hi5\n";
594 64         108 $this->{$place."_EDGE"} = $to_add;
595             # print STDERR "hi6a\n";
596 64         150 $to_add->updateLevel($this->getLevel + 1);
597             #print STDERR "hi7a\n";
598            
599 64         241 return 1;
600            
601             }
602             else
603             {
604             #incompatible nodes
605 0         0 return 0;
606             }
607             }
608              
609             sub freeFromFather
610             {
611 0     0 1 0 my ($this) = @_;
612 0         0 undef $this->{FATHER};
613 0         0 bless ($this,'Lingua::YaTeA::RootNode');
614             }
615              
616              
617             sub plugSubNodeSet
618             {
619 0     0 1 0 my ($this,$to_plug) = @_;
620 0         0 my $head_position = $this->getHeadPosition;
621 0         0 my $head_node;
622 0         0 my $depth = 0;
623              
624 0 0 0     0 if ((blessed($this->{$head_position . "_EDGE"})) && ($this->{$head_position . "_EDGE"}->isa('Lingua::YaTeA::TermLeaf')))
625             {
626 0         0 $this->{$head_position . "_EDGE"} = $to_plug;
627 0         0 $to_plug->setFather($this);
628             }
629             else
630             {
631 0         0 ($head_node,$head_position) = $this->{$head_position . "_EDGE"}->searchLeaf($to_plug->searchHead(0)->getIndex,\$depth);
632 0         0 $head_node->{$head_position . "_EDGE"} = $to_plug;
633 0         0 $to_plug->setFather($head_node);
634             }
635             }
636              
637             sub checkCompatibility
638             {
639 64     64 1 110 my ($this,$place,$to_add,$fh) = @_;
640              
641             # print STDERR "cC1\n";
642             # if(defined $fh)
643             # {
644             # print $fh "place: " . $place ."\n";
645             # }
646 64 50       115 if($this->getID != $to_add->getID)
647             {
648             # print STDERR "cC3\n";
649             # if(defined $fh)
650             # {
651             # print $fh "differents\n";
652             # }
653             # if(defined $fh)
654             # {
655             # print $fh "tete add: " . $to_add->searchHead(0)->getIndex . "\n";
656             # print $fh "tete hook: " . $this->getEdge($place)->searchHead(0)->getIndex . "\n";
657             # }
658 64 50       112 if($to_add->searchHead(0)->getIndex == $this->getEdge($place)->searchHead(0)->getIndex)
659             {
660             # if(defined $fh)
661             # {
662             # print $fh "ca colle\n";
663             # }
664             # Print STDERR "cC3\n";
665 64 50       143 if($this->checkNonCrossing($to_add,$fh))
666             {
667             # if(defined $fh)
668             # {
669             # print $fh "croisent pas\n";
670             # }
671             # print STDERR "cC4\n";
672 64         159 return 1;
673             }
674             # print STDERR "cC5\n";
675 0         0 return 0;
676             }
677 0         0 return 0;
678             }
679 0         0 return 0;
680             }
681              
682              
683              
684              
685              
686             sub checkNonCrossing
687             {
688 64     64 1 107 my ($this,$to_add,$fh) = @_;
689              
690 64         79 my $previous = -1;
691 64         72 my $gap;
692 64         148 my $above_index_set = Lingua::YaTeA::IndexSet->new;
693            
694              
695             # print STDERR "cNC1\n";
696              
697 64         152 $this->fillIndexSet($above_index_set,0);
698            
699             # print STDERR "cNC2\n";
700              
701 64         205 my $above_gaps_a = $above_index_set->getGaps;
702            
703             # print STDERR "cNC2b\n";
704 64         295 my $to_add_index_set;
705             my $index;
706 64         0 my $pivot;
707 64         0 my @both;
708            
709 64         0 my $i;
710 64         0 my %filled_gaps;
711 64         0 my @gaps;
712              
713             # print STDERR scalar(@$above_gaps_a) . "\n";
714              
715              
716 64 50       102 if(scalar @$above_gaps_a > 1)
717             {
718             # print STDERR "cNC3a\n";
719 0         0 $to_add_index_set = Lingua::YaTeA::IndexSet->new;
720             # print STDERR "cNC3b\n";
721 0         0 $to_add->fillIndexSet($to_add_index_set,0);
722             # print STDERR "cNC4\n";
723 0         0 foreach $index (@{$to_add_index_set->getIndexes})
  0         0  
724             {
725             # print STDERR "cNC5\n";
726 0         0 foreach $gap (@$above_gaps_a)
727             {
728 0 0       0 if(exists $gap->{$index})
729             {
730 0         0 $filled_gaps{$gap} = $gap;
731             }
732             }
733             }
734             # print STDERR "cNC6\n";
735 0         0 @gaps = values %filled_gaps;
736             # print STDERR "cNC7\n";
737              
738 0 0       0 if(scalar @gaps > 1)
739             {
740 0 0       0 if(scalar @gaps == 2)
741             {
742             # print STDERR "cNC8\n";
743 0         0 $pivot = $above_index_set->searchPivot($to_add_index_set);
744 0 0       0 if(defined $pivot)
745             {
746             # print STDERR "cNC9\n";
747 0         0 push @both, keys %{$gaps[0]};
  0         0  
748 0         0 push @both, keys %{$gaps[1]};
  0         0  
749 0         0 @both = sort (@both);
750 0         0 $previous = -1;
751             # print STDERR "cNC10\n";
752              
753 0         0 for ($i=0; $i < scalar @both; $i++)
754             {
755             # print STDERR "cNC11\n";
756 0         0 $index = $both[$i];
757              
758 0 0 0     0 if(
      0        
      0        
759             ($index != $previous+1)
760             &&
761             ($pivot == $previous+1)
762             &&
763             (
764             (!defined $both[$i+1])
765             ||
766             ($pivot == $both[$i+1])
767             )
768             )
769             {
770 0         0 return 1;
771             }
772 0         0 $previous = $index;
773             }
774 0         0 return 0;
775             }
776             }
777 0         0 return 0;
778             }
779             }
780             # print STDERR "cNC(F)\n";
781              
782 64         232 return 1;
783             }
784              
785              
786              
787             sub copyRecursively
788             {
789 271     271 1 422 my ($this,$new_set,$father, $depth_r) = @_;
790 271         522 my $new;
791             my $field;
792 271         0 my $edge;
793 271         616 my @fields = ('LEVEL','LEFT_STATUS','RIGHT_STATUS','DET','PREP','LINKED_TO_ISLAND');
794 271         528 $$depth_r++;
795 271 50       436 if ($$depth_r < 50) { # Temporary added by Thierry Hamon 09/02/2012
796 271 100 66     1262 if ((blessed($this)) && ($this->isa('Lingua::YaTeA::RootNode')))
797             {
798 208         508 $new = Lingua::YaTeA::RootNode->new;
799 208         301 $new_set->{ROOT_NODE} = $new;
800             }
801             else
802             {
803 63         154 $new = Lingua::YaTeA::InternalNode->new;
804 63         114 $new->{FATHER} = $father;
805             }
806 271         491 foreach $field (@fields)
807             {
808 1626         2352 $new->{$field} = $this->{$field};
809             }
810 271         1127 $new_set->addNode($new);
811 271 100 66     647 if ((blessed($this->getLeftEdge)) && ($this->getLeftEdge->isa('Lingua::YaTeA::TermLeaf')))
812             {
813 151         232 $new->{LEFT_EDGE} = $this->getLeftEdge;
814             }
815             else{
816 120         194 $edge = $this->getLeftEdge;
817 120 50       229 if(defined $edge)
818             {
819 120         331 $new->{LEFT_EDGE} = $edge->copyRecursively($new_set,$new, $depth_r);
820             }
821             }
822 271 100 66     512 if ((blessed($this->getRightEdge)) && ($this->getRightEdge->isa('Lingua::YaTeA::TermLeaf')))
823             {
824 106         172 $new->{RIGHT_EDGE} = $this->getRightEdge;
825             }
826             else
827             {
828 165         258 $edge = $this->getRightEdge;
829 165 50       285 if(defined $edge)
830             {
831 165         350 $new->{RIGHT_EDGE} = $edge->copyRecursively($new_set,$new, $depth_r);
832             }
833             }
834             } else {
835 0         0 warn "copyRecursively: Going out a deep recursive method call (more than 50 calls)\n";
836 0         0 $new = $this;
837             # return undef;
838             }
839 271         592 return $new;
840            
841             }
842              
843              
844             sub searchLeftMostLeaf
845             {
846 7     7 1 12 my ($this) = @_;
847 7         8 my $left_most;
848             my $left;
849            
850 7         9 $left = $this->getLeftEdge;
851 7 100 66     35 if ((blessed($left)) && ($left->isa('Lingua::YaTeA::Node')))
852             {
853 1         4 $left = $left->searchLeftMostLeaf;
854             }
855 7         18 return $left;
856             }
857              
858              
859              
860             sub searchRightMostLeaf
861             {
862 0     0 1 0 my ($this,$depth_r) = @_;
863 0         0 my $right;
864 0         0 $$depth_r++;
865 0 0       0 if ($$depth_r < 50) { # Temporary added by sophie Aubin 14/01/2008
866            
867 0         0 $right = $this->getRightEdge;
868            
869 0 0 0     0 if ((blessed($right)) && ($right->isa('Lingua::YaTeA::Node')))
870             {
871 0         0 $right = $right->searchRightMostLeaf($depth_r);
872             }
873 0         0 return $right;
874             }
875             else
876             {
877 0         0 warn "searchRightMostLeaf: Going out a deep recursive method call (more than 50 calls)\n";
878 0         0 return undef;
879             }
880             }
881              
882              
883              
884              
885              
886             sub getPreviousWord
887             {
888 0     0 1 0 my ($this,$place) = @_;
889 0         0 my $depth = 0;
890 0 0       0 if($place eq "LEFT")
891             {
892 0 0 0     0 if ((blessed($this)) && ($this->isa('Lingua::YaTeA::RootNode')))
893             {
894 0         0 return;
895             }
896             else
897             {
898 0         0 return $this->getFather->getPreviousWord($this->getNodePosition);
899             }
900             }
901             else
902             {
903 0 0       0 if(defined $this->getDeterminer)
904             {
905 0         0 return $this->getDeterminer;
906             }
907 0 0       0 if(defined $this->getPreposition)
908             {
909 0         0 return $this->getPreposition;
910             }
911 0 0 0     0 if ((blessed($this->getLeftEdge)) && ($this->getLeftEdge->isa('Lingua::YaTeA::Node')))
912             {
913 0         0 return $this->getLeftEdge->searchRightMostLeaf(\$depth);
914             }
915             else
916             {
917 0         0 return $this->getLeftEdge;
918             }
919             }
920            
921             }
922              
923              
924              
925              
926             sub getNextWord
927             {
928 0     0 1 0 my ($this,$place) = @_;
929 0 0       0 if($place eq "RIGHT")
930             {
931 0 0 0     0 if((blessed($this)) && ($this->isa('Lingua::YaTeA::RootNode')))
932             {
933 0         0 return;
934             }
935             else
936             {
937 0         0 return $this->getFather->getNextWord($this->getNodePosition);
938             }
939             }
940             else
941             {
942 0 0       0 if(defined $this->getPreposition)
943             {
944 0         0 return $this->getPreposition;
945             }
946 0 0       0 if(defined $this->getDeterminer)
947             {
948 0         0 return $this->getDeterminer;
949             }
950 0 0 0     0 if ((blessed($this->getRightEdge)) && ($this->getRightEdge->isa('Lingua::YaTeA::Node')))
951             {
952 0         0 return $this->getRightEdge->searchLeftMostLeaf;
953             }
954             else
955             {
956 0         0 return $this->getRightEdge;
957             }
958             }
959             }
960              
961              
962              
963              
964             sub findWordContext
965             {
966 0     0 1 0 my ($this,$word_index,$place) = @_;
967            
968 0         0 my $next;
969             my $previous;
970              
971 0         0 $previous = $this->getPreviousWord($place);
972 0         0 $next = $this->getNextWord($place);
973              
974 0 0 0     0 if((!defined $previous)&&(!defined $next))
975             {
976 0         0 die "Index not found\n";
977             }
978 0         0 return ($previous,$next);
979             }
980              
981              
982             sub buildIF
983             {
984 179     179 1 273 my ($this, $if_r, $words_a, $depth_r) = @_;
985            
986 179         204 $$depth_r++;
987 179 50       270 if ($$depth_r < 50) { # Temporary added by Thierry Hamon 09/02/2012
988 179 100 66     250 if ((blessed($this->getLeftEdge)) && ($this->getLeftEdge->isa('Lingua::YaTeA::InternalNode')))
989             {
990 28         55 $this->getLeftEdge->buildIF($if_r,$words_a,$depth_r);
991             }
992             else
993             {
994 151         254 $$if_r .= $this->getLeftEdge->getIF($words_a) . " ";
995             }
996            
997 179 100       364 if(defined $this->getPreposition)
998             {
999 47         80 $$if_r .= $this->getPreposition->getIF($words_a) . " ";
1000             }
1001              
1002              
1003 179 100       294 if(defined $this->getDeterminer)
1004             {
1005 14         37 $$if_r .= $this->getDeterminer->getIF($words_a) . " ";
1006             }
1007              
1008 179 100 66     293 if ((blessed($this->getRightEdge)) && ($this->getRightEdge->isa('Lingua::YaTeA::InternalNode')))
1009             {
1010 66         99 $this->getRightEdge->buildIF($if_r,$words_a,$depth_r);
1011             }
1012             else
1013             {
1014 113         186 $$if_r .= $this->getRightEdge->getIF($words_a) . " ";
1015             }
1016             } else {
1017 0         0 warn "buildIF: Going out a deep recursive method call (more than 50 calls)\n";
1018 0         0 return undef;
1019             }
1020            
1021             }
1022              
1023             sub buildParenthesised
1024             {
1025 46     46 1 66 my ($this,$analysis_r,$words_a) = @_;
1026 46         125 my %abr = ("MODIFIER" => "M", "HEAD" => "H", "COORDONNE1" => "C1", "COORDONNE2" => "C2");
1027 46         70 $$analysis_r .= "( ";
1028 46 100 66     74 if ((blessed($this->getLeftEdge)) && ($this->getLeftEdge->isa('Lingua::YaTeA::InternalNode')))
1029             {
1030 1         2 $this->getLeftEdge->buildParenthesised($analysis_r,$words_a);
1031             }
1032             else
1033             {
1034             #$$analysis_r .= $this->getLeftEdge->getIF($words_a) . "<=" .$abr{$this->getLeftEdgeStatus} . "=" . $this->getLeftEdge->getPOS($words_a) . "> ";
1035 45         77 $$analysis_r .= $this->getLeftEdge->getIF($words_a) . "<=" .$abr{$this->getLeftEdgeStatus} . "> ";
1036             }
1037            
1038 46 100       107 if(defined $this->getPreposition)
1039             {
1040             #$$analysis_r .= $this->getPreposition->getIF($words_a) . " ";
1041 10         27 $$analysis_r .= $this->getPreposition->getIF($words_a) . "<=P> ";
1042             }
1043              
1044              
1045 46 100       86 if(defined $this->getDeterminer)
1046             {
1047             # $$analysis_r .= $this->getDeterminer->getIF($words_a) . " ";
1048 2         6 $$analysis_r .= $this->getDeterminer->getIF($words_a) . "<=D> ";
1049             }
1050              
1051 46 50 33     78 if ((blessed($this->getRightEdge)) && ($this->getRightEdge->isa('Lingua::YaTeA::InternalNode')))
1052             {
1053 0         0 $this->getRightEdge->buildParenthesised($analysis_r,$words_a);
1054             }
1055             else
1056             {
1057             # $$analysis_r .= $this->getRightEdge->getIF($words_a) . "<=" .$abr{$this->getRightEdgeStatus} . "=" . $this->getRightEdge->getPOS($words_a) . "> ";
1058 46         72 $$analysis_r .= $this->getRightEdge->getIF($words_a) . "<=" .$abr{$this->getRightEdgeStatus} . "> ";
1059             }
1060 46 100 66     240 if((blessed($this)) && ($this->isa('Lingua::YaTeA::InternalNode')))
1061             {
1062             # $$analysis_r .= ")<=" . $abr{$this->getNodeStatus} . "=" .$this->searchHead(0)->getPOS($words_a) . "> ";
1063 1         6 $$analysis_r .= ")<=" . $abr{$this->getNodeStatus} . "> ";
1064             }
1065             else
1066             {
1067 45         147 $$analysis_r .= ")";
1068             }
1069             }
1070              
1071              
1072              
1073              
1074             sub searchLeaf
1075             {
1076 80     80 1 149 my ($this,$index,$depth_r) = @_;
1077 80         108 my $node;
1078             my $position;
1079             # print STDERR "SL1\n";
1080 80         108 $$depth_r++;
1081 80 50       133 if ($$depth_r < 50) { # Temporary added by sophie Aubin 14/01/2008
1082            
1083 80 100 66     137 if(( blessed($this->getLeftEdge)) && ($this->getLeftEdge->isa('Lingua::YaTeA::Node')))
1084             {
1085             # print STDERR "SL2a\n";
1086 3         8 ($node,$position) = $this->getLeftEdge->searchLeaf($index,$depth_r);
1087             }
1088             else
1089             {
1090             # print STDERR "SL2b\n";
1091 77 100       140 if($this->getLeftEdge->getIndex == $index)
1092             {
1093 28         96 return ($this,"LEFT");
1094             }
1095             }
1096             # print STDERR "SL3\n";
1097            
1098 52 100       129 if(!defined $node)
1099             {
1100 51 100 66     90 if ((blessed($this->getRightEdge)) && ($this->getRightEdge->isa('Lingua::YaTeA::Node')))
1101             {
1102             # print STDERR "SL4a\n";
1103 6         14 ($node,$position) = $this->getRightEdge->searchLeaf($index,$depth_r);
1104             }
1105             else
1106             {
1107             # print STDERR "SL4b\n";
1108 45 100       71 if($this->getRightEdge->getIndex == $index)
1109             {
1110 41         258 return ($this,"RIGHT");
1111             }
1112             }
1113             }
1114             }
1115             else
1116             {
1117 0         0 warn "searchLeaf: Going out a deep recursive method call (more than 50 calls)\n";
1118 0         0 return undef;
1119             }
1120             # print STDERR "SL5\n";
1121 11         27 return ($node,$position);
1122             }
1123              
1124             sub updateLeaves
1125             {
1126 11     11 1 25 my ($this,$counter_r,$index_set) = @_;
1127            
1128 11 50 33     24 if ((blessed($this->getLeftEdge)) && ($this->getLeftEdge->isa('Lingua::YaTeA::TermLeaf')))
1129              
1130             {
1131 11         34 $this->{LEFT_EDGE} = Lingua::YaTeA::TermLeaf->new($index_set->getIndex($$counter_r++));
1132             }
1133             else
1134             {
1135 0         0 $this->getLeftEdge->updateLeaves($counter_r,$index_set);
1136             }
1137            
1138 11 50       31 if (defined $this->getPreposition)
1139             {
1140 0         0 $this->{PREP} = Lingua::YaTeA::TermLeaf->new($index_set->getIndex($$counter_r++));
1141             }
1142 11 50       25 if (defined $this->getDeterminer)
1143             {
1144 0         0 $this->{DET} = Lingua::YaTeA::TermLeaf->new($index_set->getIndex($$counter_r++));
1145             }
1146 11 100 66     21 if ((blessed($this->getRightEdge)) && ($this->getRightEdge->isa('Lingua::YaTeA::TermLeaf')))
1147             {
1148 9         27 $this->{RIGHT_EDGE} = Lingua::YaTeA::TermLeaf->new($index_set->getIndex($$counter_r++));
1149             }
1150             else
1151             {
1152 2         5 $this->getRightEdge->updateLeaves($counter_r,$index_set);
1153             }
1154             }
1155              
1156              
1157             sub buildTermList
1158             {
1159 118     118 1 213 my ($this,$term_candidates_a,$words_a,$phrase_occurrences_a,$phrase_island_set,$offset,$maximal) = @_;
1160            
1161 118         144 my $left;
1162             my $right;
1163              
1164             # map {print STDERR "++>" . $_->getIF()} @$words_a;
1165            
1166 118         274 my $term_candidate = Lingua::YaTeA::MultiWordTermCandidate->new;
1167             # print STDERR "\nID : " . $term_candidate->getID . "\n";
1168              
1169 118         357 my %abr = ("MODIFIER" => "M", "HEAD" => "H", "COORDONNE1" => "C1", "COORDONNE2" => "C2");
1170            
1171 118         290 $term_candidate->editKey("( ");
1172            
1173 118         261 $term_candidate->setOccurrences($phrase_occurrences_a,$$offset,$maximal);
1174              
1175 118         151 my $old_offset = $$offset;
1176              
1177 118         138 $$offset = 0;
1178              
1179             # left edge is a term leaf
1180 118 100 66     200 if ((blessed($this->getLeftEdge)) && ($this->getLeftEdge->isa('Lingua::YaTeA::TermLeaf')))
1181             {
1182             # print STDERR $this->getLeftEdge->getIF($words_a) . "\n";
1183 109         178 $term_candidate->editKey($this->getLeftEdge->getIF($words_a) . "<=" . $abr{$this->getLeftEdgeStatus} . "=" . $this->getLeftEdge->getPOS($words_a) . "=" . $this->getLeftEdge->getLF($words_a). "> ");
1184              
1185 109         322 my $mono = Lingua::YaTeA::MonolexicalTermCandidate->new;
1186 109         187 $mono->editKey("( " . $this->getLeftEdge->getIF($words_a)."<=S=".$this->getLeftEdge->getPOS($words_a) . "=" . $this->getLeftEdge->getLF($words_a). "> )");
1187 109         224 $mono->addWord($this->getLeftEdge,$words_a);
1188              
1189 109         212 $mono->setOccurrences($phrase_occurrences_a,$$offset+$old_offset,$this->getLeftEdge->getLength($words_a),0);
1190              
1191 109         152 push @$term_candidates_a, $mono;
1192              
1193 109         193 $term_candidate->addWord($this->getLeftEdge,$words_a);
1194 109         225 $term_candidate->getIndexSet->addIndex($this->getLeftEdge->getIndex);
1195            
1196 109         165 $left = $mono;
1197             # print STDERR "==>$$offset\n";
1198 109         161 $$offset += $this->getLeftEdge->getLength($words_a) +1;
1199             # print STDERR "====>$$offset\n";
1200              
1201             }
1202             # left edge is a node
1203             else
1204             {
1205             # $$offset = 0;
1206              
1207 9         16 $$offset += $old_offset;
1208 9         15 $left = $this->getLeftEdge->buildTermList($term_candidates_a,$words_a,$phrase_occurrences_a,$phrase_island_set,$offset,0);
1209 9         16 $$offset -= $old_offset;
1210 9         20 $term_candidate->editKey($left->getKey . "<=" . $abr{$this->getLeftEdge->getNodeStatus} . "=" .$this->getLeftEdge->searchHead(0)->getPOS($words_a) . "> ");
1211 9         18 push @{$term_candidate->getWords},@{$left->getWords};
  9         19  
  9         19  
1212 9         21 $term_candidate->addIndexSet($left->getIndexSet);
1213              
1214             # $$offset += $old_offset;
1215              
1216             }
1217 118 100       229 if (defined $this->getPreposition)
1218             {
1219 26         41 $term_candidate->editKey($this->getPreposition->getIF($words_a) . "<=".$this->getPreposition->getPOS($words_a) . "=" . $this->getPreposition->getLF($words_a) . "> ");
1220 26         67 $$offset += $this->getPreposition->getLength($words_a) +1;
1221 26         44 $term_candidate->{PREPOSITION} = $this->getPreposition->getWord($words_a);
1222 26         46 $term_candidate->addWord($this->getPreposition,$words_a);
1223 26         53 $term_candidate->getIndexSet->addIndex($this->getPreposition->getIndex);
1224             }
1225 118 100       198 if (defined $this->getDeterminer)
1226             {
1227 6         25 $term_candidate->editKey($this->getDeterminer->getIF($words_a) . "<=" . $this->getDeterminer->getPOS($words_a) . "=" . $this->getDeterminer->getLF($words_a) . "> ");
1228 6         15 $$offset += $this->getDeterminer->getLength($words_a) +1;
1229 6         16 $term_candidate->{DETERMINER} = $this->getDeterminer->getWord($words_a);
1230 6         12 $term_candidate->addWord($this->getDeterminer,$words_a);
1231 6         13 $term_candidate->getIndexSet->addIndex($this->getDeterminer->getIndex);
1232             }
1233 118 100 66     185 if ((blessed($this->getRightEdge)) && ($this->getRightEdge->isa('Lingua::YaTeA::TermLeaf')))
1234             {
1235 79         123 $term_candidate->editKey($this->getRightEdge->getIF($words_a) . "<=" . $abr{$this->getRightEdgeStatus} . "=" . $this->getRightEdge->getPOS($words_a) . "=" . $this->getRightEdge->getLF($words_a). "> ");
1236              
1237 79         227 my $mono = Lingua::YaTeA::MonolexicalTermCandidate->new;
1238 79         146 $mono->editKey("( " . $this->getRightEdge->getIF($words_a). "<=S=".$this->getRightEdge->getPOS($words_a) . "=" . $this->getRightEdge->getLF($words_a). "> )");
1239 79         146 $mono->addWord($this->getRightEdge,$words_a);
1240 79         153 $mono->setOccurrences($phrase_occurrences_a,$$offset+$old_offset,$this->getRightEdge->getLength($words_a),0);
1241 79         110 push @$term_candidates_a, $mono;
1242              
1243 79         130 $term_candidate->addWord($this->getRightEdge,$words_a);
1244 79         169 $term_candidate->getIndexSet->addIndex($this->getRightEdge->getIndex);
1245              
1246 79         120 $right = $mono;
1247             # print STDERR "===>$$offset\n";
1248 79         134 $$offset += $this->getRightEdge->getLength($words_a) +1;
1249             # print STDERR "==>$$offset\n";
1250             }
1251             # left edge is a node
1252             else
1253             {
1254             # print STDERR "=== Call\n";
1255 39         60 $$offset += $old_offset;
1256 39         66 $right = $this->getRightEdge->buildTermList($term_candidates_a,$words_a,$phrase_occurrences_a,$phrase_island_set,$offset,0);
1257 39         56 $$offset -= $old_offset;
1258            
1259             # print STDERR "=== End of Call\n";
1260 39         72 $term_candidate->editKey($right->getKey . "<=" . $abr{$this->getRightEdge->getNodeStatus} . "=" .$this->getRightEdge->searchHead(0)->getPOS($words_a) . "> ");
1261 39         71 push @{$term_candidate->getWords},@{$right->getWords};
  39         77  
  39         71  
1262 39         79 $term_candidate->addIndexSet($right->getIndexSet);
1263              
1264             }
1265              
1266 118         293 $term_candidate->editKey(")");
1267            
1268             # if((blessed($this)) && ($this->isa('Lingua::YaTeA::InternalNode')))
1269             # {
1270             # $term_candidate->editKey("<=" . $abr{$this->getNodeStatus} . "=" .$this->searchHead(0)->getPOS($words_a) . "> ");
1271             # }
1272            
1273 118 100       238 if($this->getHeadPosition eq "LEFT")
1274             {
1275 26         45 $term_candidate->{ROOT_HEAD} = $left;
1276 26         29 $term_candidate->{ROOT_MODIFIER} = $right;
1277 26         32 $term_candidate->{MODIFIER_POSITION} = "AFTER";
1278              
1279 26         60 $left->setROOT($term_candidate);
1280 26         59 $right->setROOT($term_candidate);
1281             }
1282             else
1283             {
1284 92         115 $term_candidate->{ROOT_HEAD} = $right;
1285 92         321 $term_candidate->{ROOT_MODIFIER} = $left;
1286 92         115 $term_candidate->{MODIFIER_POSITION} = "BEFORE";
1287 92         214 $left->setROOT($term_candidate);
1288 92         168 $right->setROOT($term_candidate);
1289             }
1290              
1291             # print STDERR "\nID : " . $term_candidate->getID . "(" . $$offset . ")\n";
1292            
1293 118         268 $term_candidate->completeOccurrences($$offset);
1294              
1295             # print STDERR ">>>exit\n";
1296 118         264 $term_candidate->setIslands($phrase_island_set,$left,$right);
1297              
1298 118         154 push @$term_candidates_a, $term_candidate;
1299              
1300 118         162 $$offset += $old_offset;
1301              
1302 118         315 return $term_candidate;
1303             }
1304              
1305              
1306              
1307              
1308             sub getHeadPosition
1309             {
1310 118     118 1 190 my ($this) = @_;
1311 118 100       219 if($this->{LEFT_STATUS} eq "HEAD")
1312             {
1313 26         63 return "LEFT";
1314             }
1315 92         178 return "RIGHT";
1316             }
1317              
1318             sub getModifierPosition
1319             {
1320 0     0 1 0 my ($this) = @_;
1321 0 0       0 if($this->{LEFT_STATUS} eq "MODIFIER")
1322             {
1323 0         0 return "LEFT";
1324             }
1325 0         0 return "RIGHT";
1326             }
1327              
1328              
1329             sub searchLeftMostNode
1330             {
1331 0     0 1 0 my ($this) = @_;
1332            
1333 0         0 my $left;
1334            
1335 0         0 $left = $this->getLeftEdge;
1336 0 0 0     0 if ((blessed($left)) && ($left->isa('Lingua::YaTeA::Node')))
1337             {
1338 0         0 $left = $left->searchLeftMostNode;
1339             }
1340 0         0 return $this;
1341             }
1342              
1343             sub searchRightMostNode
1344             {
1345 0     0 1 0 my ($this) = @_;
1346            
1347 0         0 my $right;
1348            
1349 0         0 $right = $this->getRightEdge;
1350 0 0 0     0 if ((blessed($right)) && ($right->isa('Lingua::YaTeA::Node')))
1351             {
1352 0         0 $right = $right->searchRightMostNode;
1353             }
1354 0         0 return $this;
1355             }
1356              
1357             sub fillIndexSet
1358             {
1359 383     383 1 573 my ($this,$index_set, $depth) = @_;
1360 383         445 $depth++;
1361 383 50       558 if ($depth < 50) { # Temporary added by thierry Hamon 02/03/2007
1362 383 100 66     579 if ((blessed($this->getLeftEdge)) && ($this->getLeftEdge->isa('Lingua::YaTeA::TermLeaf')))
1363             {
1364 332         482 $index_set->addIndex($this->getLeftEdge->getIndex);
1365             }
1366             else
1367             {
1368 51         89 $this->getLeftEdge->fillIndexSet($index_set,$depth);
1369             }
1370 383 100       781 if (defined $this->getPreposition)
1371             {
1372 114         183 $index_set->addIndex($this->getPreposition->getIndex);
1373             }
1374 383 100       643 if (defined $this->getDeterminer)
1375             {
1376 36         62 $index_set->addIndex($this->getDeterminer->getIndex);
1377             }
1378 383 100 66     629 if ((blessed($this->getRightEdge)) && ($this->getRightEdge->isa('Lingua::YaTeA::TermLeaf')))
1379             {
1380 225         365 $index_set->addIndex($this->getRightEdge->getIndex);
1381             }
1382             else
1383             {
1384 158 50       232 if(defined $this->getRightEdge)
1385             {
1386             # warn "vvvvv\n";
1387             # warn $this->getRightEdge->getRightEdge . "\n";
1388             # warn "$this\n";
1389             # warn "-----\n";
1390 158         248 $this->getRightEdge->fillIndexSet($index_set,$depth);
1391             }
1392             }
1393             } else {
1394 0         0 warn "fillIndexSet: Going out a deep recursive method call (more than 50 calls)\n";
1395             }
1396             }
1397              
1398             sub plugInternalNode
1399             {
1400 0     0 1 0 my ($this,$internal_node,$previous_index,$next_index,$parsing_pattern_set,$words_a,$parsing_direction,$tag_set,$fh) = @_;
1401 0         0 my $record;
1402             my $intermediate_node_set;
1403 0         0 my $new_previous_index;
1404 0         0 my $new_next_index;
1405             # print $fh "plugInternalNode\n";
1406             # print $fh "previous : ". $previous_index . "\n";
1407             # print $fh "above:";
1408             # $this->printRecursively($words_a,$fh);
1409             # print $fh "internal node :" ;
1410             # $internal_node->printRecursively($words_a,$fh);
1411 0         0 my ($node,$place) = $this->searchRoot->getNodeOfLeaf($previous_index,$internal_node->searchHead(0)->getIndex,$words_a,$fh);
1412            
1413             # print $fh $node->getID . " -> place : ". $place . "\n";
1414 0 0       0 if($place =~ /LEFT|RIGHT/)
1415             {
1416 0 0       0 if(!defined $node)
1417             {
1418 0         0 die;
1419             }
1420             else{
1421              
1422 0 0 0     0 if(
      0        
      0        
1423             ((blessed($node->getEdge($place))) && ($node->getEdge($place)->isa('Lingua::YaTeA::Node')))
1424             ||
1425             ($node->getEdge($place)->getIndex != $previous_index)
1426             ||
1427             ($node->getEdgeStatus($place) ne "HEAD")
1428             )
1429             {
1430 0 0       0 if (defined $node->searchHead(0)) {
1431 0         0 $new_previous_index = $node->searchHead(0)->getIndex;
1432 0 0       0 if($new_previous_index < $internal_node->searchHead(0)->getIndex)
1433             {
1434 0         0 $previous_index = $new_previous_index;
1435             }
1436             } else {
1437 0         0 warn "undefined head (previous)\n";
1438             }
1439             }
1440             }
1441             }
1442 0         0 ($node,$place) = $this->searchRoot->getNodeOfLeaf($next_index,$internal_node->searchHead(0)->getIndex,$words_a,$fh);
1443             # print $fh "second choix:" . $node->getID . " -> place : ". $place . "(next=" .$next_index .")\n";
1444 0 0       0 if($place =~ /LEFT|RIGHT/)
1445             {
1446 0 0 0     0 if(
      0        
      0        
1447             ((blessed($node->getEdge($place))) && ($node->getEdge($place)->isa('Lingua::YaTeA::Node')))
1448             ||
1449             ($node->getEdge($place)->getIndex != $next_index)
1450             ||
1451             ($node->getEdgeStatus($place) ne "HEAD")
1452             )
1453             {
1454 0 0       0 if (defined $node->searchHead(0)) {
1455 0         0 $new_next_index = $node->searchHead(0)->getIndex;
1456 0 0       0 if($new_next_index > $internal_node->searchHead(0)->getIndex)
1457             {
1458 0         0 $next_index = $new_next_index;
1459             }
1460             } else {
1461 0         0 warn "undefined head (next)\n";
1462             }
1463             }
1464             # print $fh "nouveau next? : " .$next_index ."\n";
1465             }
1466              
1467 0         0 my $left_index_set = Lingua::YaTeA::IndexSet->new;
1468 0         0 $left_index_set->addIndex($previous_index);
1469 0         0 $left_index_set->addIndex($internal_node->searchHead(0)->getIndex);
1470 0         0 my $right_index_set = Lingua::YaTeA::IndexSet->new;
1471 0         0 $right_index_set->addIndex($internal_node->searchHead(0)->getIndex);
1472 0         0 $right_index_set->addIndex($next_index);
1473            
1474 0         0 my $attached = 0;
1475 0         0 my $depth = 0;
1476 0         0 my $pos = $words_a->[$previous_index]->getPOS . " " .$words_a->[$internal_node->searchHead(0)->getIndex]->getPOS ;
1477             # print $fh "nouveau pos: ". $pos . "\n";
1478 0 0       0 if ($record = $parsing_pattern_set->existRecord($left_index_set->buildPOSSequence($words_a,$tag_set)))
1479             {
1480 0         0 $intermediate_node_set = $this->getParseFromPattern($left_index_set,$record,$parsing_direction,$words_a);
1481              
1482 0         0 $intermediate_node_set->getRoot->hitch('RIGHT',$internal_node,$words_a);
1483 0         0 ($node,$place) = $this->getNodeOfLeaf($previous_index,$internal_node->searchRightMostLeaf(\$depth)->getIndex,$words_a,$fh);
1484 0 0       0 if(defined $node)
1485             {
1486 0 0 0     0 if(
1487             # prevent syntactic break
1488             ($place ne "PREP")
1489             &&
1490             ($place ne "DET")
1491             )
1492             {
1493 0 0       0 if($node->hitch($place,$intermediate_node_set->getRoot,$words_a))
1494             {
1495 0         0 $attached = 1;
1496             }
1497             else
1498             {
1499 0         0 $internal_node->freeFromFather;
1500             }
1501             }
1502             }
1503             }
1504 0 0       0 if($attached == 0)
1505             {
1506 0         0 $pos = $words_a->[$internal_node->searchHead(0)->getIndex]->getPOS . " " . $words_a->[$next_index]->getPOS ;
1507             # print $fh "nouveau pos2: ". $pos . "\n";
1508             # print $fh "right index set:";
1509             # $right_index_set->print($fh);
1510             # print $fh "\n";
1511 0 0       0 if ($record = $parsing_pattern_set->existRecord($right_index_set->buildPOSSequence($words_a,$tag_set)))
1512             {
1513             # print $fh "trouve pattern\n";
1514 0         0 $intermediate_node_set = $this->getParseFromPattern($right_index_set,$record,$parsing_direction,$words_a);
1515 0         0 $intermediate_node_set->getRoot->hitch('LEFT',$internal_node,$words_a,$fh);
1516             # print $fh "apres oermier hitch\n";
1517             # $intermediate_node_set->getRoot->printRecursively($words_a,$fh);
1518             # print $fh "next index::" . $next_index . "\n";
1519 0         0 ($node,$place) = $this->getNodeOfLeaf($next_index,$internal_node->searchRightMostLeaf->getIndex,$words_a,$fh);
1520              
1521 0 0       0 if(defined $node)
1522             {
1523             # print $fh "second hitch " . $node->getID . "\n";
1524 0 0       0 if($node->hitch($place,$intermediate_node_set->getRoot,$words_a,$fh))
1525             {
1526 0         0 $attached = 1;
1527             }
1528             else
1529             {
1530 0         0 $internal_node->freeFromFather;
1531             }
1532             }
1533             }
1534             }
1535             # print $fh "resultat:";
1536             # $this->printRecursively($words_a,$fh);
1537 0         0 return ($attached,$intermediate_node_set);
1538             }
1539              
1540              
1541             sub getHigherHookNode
1542             {
1543 0     0 0 0 my ($this,$index,$position,$to_insert,$fh) = @_;
1544 0         0 my $node = $this;
1545             # if(defined $fh)
1546             # {
1547             # print $fh "entree higher:" . $node->getID . " p: ". $position . "\n";
1548            
1549             # }
1550 0 0       0 if($index < $to_insert)
1551             {
1552             # if(defined $fh)
1553             # {
1554             # print $fh "post_insertion\n";
1555             # }
1556 0 0 0     0 if (
      0        
      0        
      0        
1557             ((blessed($node)) && ($node->isa('Lingua::YaTeA::InternalNode')))
1558             &&
1559             ($node->getFather->getEdgeStatus($position) eq "HEAD")
1560             &&
1561             (
1562             (
1563             ($position eq "LEFT")
1564             &&
1565             ($node->getRightEdge->searchLeftMostLeaf->getIndex < $to_insert)
1566             )
1567             ||
1568             (
1569             ($position eq "RIGHT")
1570             &&
1571             ($node->getFather->getRightEdge->searchLeftMostLeaf->getIndex < $to_insert)
1572             )
1573             )
1574             )
1575             {
1576 0         0 ($node,$position) = $this->getFather->getHigherHookNode($index,$position,$to_insert,$fh);
1577             }
1578            
1579             }
1580             else
1581             {
1582 0 0       0 if($index > $to_insert)
1583             {
1584             # if(defined $fh)
1585             # {
1586             # print $fh "ante_insertion\n";
1587             # }
1588 0 0 0     0 if (
      0        
      0        
      0        
1589             ((blessed($node)) && ($node->isa('Lingua::YaTeA::InternalNode')))
1590             &&
1591             ($node->getEdgeStatus($position) eq "HEAD")
1592             &&
1593             (
1594             (
1595             ($position eq "LEFT")
1596             &&
1597             ($node->getFather->getLeftEdge->searchRightMostLeaf->getIndex > $to_insert)
1598             )
1599             ||
1600             (
1601             ($position eq "RIGHT")
1602             &&
1603             ($node->getLeftEdge->searchRightMostLeaf->getIndex > $to_insert)
1604             )
1605             )
1606             )
1607             {
1608 0         0 $position = $this->getNodePosition;
1609 0         0 ($node,$position) = $this->getFather->getHigherHookNode($index,$position,$to_insert,$fh);
1610             }
1611             }
1612             }
1613 0         0 return ($node,$position);
1614             }
1615              
1616              
1617             sub getNodeOfLeaf
1618             {
1619 0     0 1 0 my ($this,$index,$to_insert,$words_a,$fh) = @_;
1620 0         0 my $node;
1621             my $position;
1622            
1623             #$fh = \*STDERR;
1624             # if(defined $fh)
1625             # {
1626             # print $fh "getNodeOfLeaf -- " .$this->getID ." index :" . $index . " insert: ".$to_insert . "\n";
1627             # }
1628 0 0 0     0 if ((blessed($this->getLeftEdge)) && ($this->getLeftEdge->isa('Lingua::YaTeA::TermLeaf')))
1629             {
1630             # if(defined $fh)
1631             # {
1632             # print $fh $this->getID . ": leftedge est une feuille\n";
1633            
1634             # }
1635 0 0       0 if ($this->getLeftEdge->getIndex == $index)
1636             {
1637             # if(defined $fh)
1638             # {
1639             # print $fh "TROUVE1 " .$index . "\n";
1640             # }
1641 0         0 ($node,$position) = $this->getHigherHookNode($index,"LEFT",$to_insert,$fh);
1642            
1643             }
1644            
1645             }
1646             else
1647             {
1648             # if(defined $fh)
1649             # {
1650             # print $fh $this->getID . ": leftedge est un noeud \n";
1651             # }
1652 0         0 ($node,$position) = $this->getLeftEdge->getNodeOfLeaf($index,$to_insert,$words_a,$fh);
1653             }
1654            
1655 0 0       0 if (defined $this->getPreposition)
1656             {
1657 0 0       0 if($this->getPreposition->getIndex == $index)
1658             {
1659 0         0 return ($this,"PREP");
1660             }
1661             }
1662 0 0       0 if (defined $this->getDeterminer)
1663             {
1664 0 0       0 if($this->getDeterminer->getIndex == $index)
1665             {
1666 0         0 return ($this,"DET");
1667             }
1668             }
1669            
1670 0 0 0     0 if (! ((blessed($node)) && ($node->isa('Lingua::YaTeA::Node'))))
1671             {
1672 0 0 0     0 if ((blessed($this->getRightEdge)) && ($this->getRightEdge->isa('Lingua::YaTeA::TermLeaf')))
1673             {
1674             # if(defined $fh)
1675             # {
1676             # print $fh $this->getID . ": rightedge est une feuille\n";
1677             # }
1678 0 0       0 if($this->getRightEdge->getIndex == $index)
1679             {
1680             # if(defined $fh)
1681             # {
1682             # print $fh "TROUVE2 " .$index . "\n";
1683             # }
1684 0         0 ($node,$position) = $this->getHigherHookNode($index,"RIGHT",$to_insert,$fh);
1685             }
1686             }
1687             else
1688             {
1689             # if(defined $fh)
1690             # {
1691             # print $fh $this->getID . ": rightedge est un noeud \n";
1692             # }
1693 0         0 ($node,$position) = $this->getRightEdge->getNodeOfLeaf($index,$to_insert,$words_a,$fh);
1694             }
1695             }
1696             # if
1697             # (
1698             # (defined $fh)
1699             # &&
1700             # (defined $node)
1701             # )
1702             # {
1703             # print $fh "le gagnant est: " . $node->getID . " place: ".$position . "\n";
1704              
1705             # }
1706 0         0 return ($node,$position);
1707             }
1708              
1709              
1710              
1711             sub getParseFromPattern
1712             {
1713 0     0 1 0 my ($this,$index_set,$pattern_record,$parsing_direction,$words_a) = @_;
1714 0         0 my $pattern;
1715             my $node_set;
1716 0         0 $pattern = $this->chooseBestPattern($pattern_record->{PARSING_PATTERNS},$parsing_direction);
1717 0         0 $node_set = $pattern->getNodeSet->copy;
1718 0         0 $node_set->fillNodeLeaves($index_set);
1719            
1720 0         0 return $node_set;
1721             }
1722              
1723              
1724              
1725             sub chooseBestPattern
1726             {
1727 0     0 1 0 my ($this,$patterns_a,$parsing_direction) = @_;
1728            
1729 0         0 my @tmp = sort {$this->sortPatternsByPriority($a,$b,$parsing_direction)} @$patterns_a;
  0         0  
1730            
1731 0         0 my @sorted = @tmp;
1732              
1733 0         0 return $sorted[0];
1734             }
1735              
1736              
1737              
1738             sub isDiscontinuous
1739             {
1740 22     22 1 40 my ($this,$previous_r,$words_a,$fh) = @_;
1741 22         34 my $next_node;
1742             my $infos_a;
1743             # print $fh "Test discontinu:" . $this->getID . "\n";
1744            
1745 22 50 33     41 if((blessed($this->getLeftEdge)) && ($this->getLeftEdge->isa('Lingua::YaTeA::TermLeaf')))
1746             {
1747             # print $fh "left : TermLeaf\n";
1748 22 50 66     68 if(
1749             ($$previous_r != -1)
1750             &&
1751             ($this->getLeftEdge->getIndex > $$previous_r +1)
1752             )
1753             {
1754 0         0 $infos_a->[0] = -1;
1755 0         0 $infos_a->[1] = $$previous_r;
1756 0         0 $infos_a->[2] = $this->getLeftEdge->getIndex;
1757 0         0 return $infos_a;
1758             }
1759             else
1760             {
1761 22         33 $$previous_r = $this->getLeftEdge->getIndex;
1762             # print $fh "nouveau previous1: " . $$previous_r . "\n";
1763             }
1764             }
1765             else
1766             {
1767             # print $fh "left : node\n";
1768 0         0 $infos_a = $this->getLeftEdge->isDiscontinuous($previous_r,$words_a,$fh);
1769 0 0       0 if($infos_a->[0] == -1)
1770             {
1771             # print $fh " retour: celui la est disconoinut\n";
1772 0         0 $infos_a->[0] = $this;
1773             }
1774             else
1775             {
1776 0 0 0     0 if ((blessed($infos_a->[0])) && ($infos_a->[0]->isa('Lingua::YaTeA::Node')))
1777             {
1778            
1779 0         0 return $infos_a;
1780             }
1781             }
1782             }
1783              
1784 22 50       49 if (defined $this->getPreposition)
1785             {
1786             # print $fh "y a prep\n";
1787 0 0 0     0 if(
1788             ($$previous_r != -1)
1789             &&
1790             ($this->getPreposition->getIndex > $$previous_r +1)
1791             )
1792             {
1793 0         0 $infos_a->[0] = $this;
1794 0         0 $infos_a->[1] = $$previous_r;
1795 0         0 $infos_a->[2] = $this->getPreposition->getIndex;
1796 0         0 return $infos_a;
1797             }
1798             else
1799             {
1800 0         0 $$previous_r = $this->getPreposition->getIndex;
1801             # print $fh "nouveau previous2: " . $$previous_r . "\n";
1802             }
1803             }
1804              
1805 22 50       41 if (defined $this->getDeterminer)
1806             {
1807             # print $fh "y a det\n";
1808 0 0 0     0 if(
1809             ($$previous_r != -1)
1810             &&
1811             ($this->getDeterminer->getIndex > $$previous_r +1)
1812             )
1813             {
1814 0         0 $infos_a->[0] = $this;
1815 0         0 $infos_a->[1] = $$previous_r;
1816 0         0 $infos_a->[2] = $this->getDeterminer->getIndex;
1817             # print $fh "sortie dans det\n";
1818 0         0 return $infos_a;
1819             }
1820             else
1821             {
1822 0         0 $$previous_r = $this->getDeterminer->getIndex;
1823             # print $fh "nouveau previous3: " . $$previous_r . "\n";
1824             }
1825             }
1826              
1827 22 100 66     34 if ((blessed($this->getRightEdge)) && ($this->getRightEdge->isa('Lingua::YaTeA::TermLeaf')))
1828             {
1829             # print $fh "right : TermLeaf\n";
1830             # print $fh $this->getRightEdge . " -" ;
1831             # print $fh $this->getRightEdge->getIndex . "_ ";
1832             # print $fh $$previous_r . "\n";
1833 18 50 33     74 if(
1834             ($$previous_r != -1)
1835             &&
1836             ($this->getRightEdge->getIndex > $$previous_r +1)
1837             )
1838             {
1839 0         0 $infos_a->[0] = $this;
1840 0         0 $infos_a->[1] = $$previous_r;
1841 0         0 $infos_a->[2] = $this->getRightEdge->getIndex;
1842 0         0 return $infos_a;
1843             }
1844             else
1845             {
1846            
1847 18         36 $$previous_r = $this->getRightEdge->getIndex;
1848             # print $fh "nouveau previous4: " . $$previous_r . "\n";
1849             }
1850             }
1851             else
1852             {
1853             # print $fh "right : Node\n";
1854 4 50 33     7 if((blessed($this->getRightEdge)) && ($this->getRightEdge->isa('Lingua::YaTeA::Node')))
1855             {
1856 4 50       8 if($this->getRightEdge->searchLeftMostLeaf->getIndex > $$previous_r+1)
1857             {
1858 0         0 $infos_a->[0] = $this;
1859 0         0 $infos_a->[1] = $$previous_r;
1860 0         0 $infos_a->[2] = $this->getRightEdge->searchLeftMostLeaf->getIndex;
1861 0         0 return $infos_a;
1862             # print $fh "sortie dans right\n";
1863             }
1864 4         8 $infos_a = $this->getRightEdge->isDiscontinuous($previous_r,$words_a,$fh);
1865             }
1866             else
1867             {
1868 0         0 $infos_a->[0] = 0;
1869             }
1870              
1871              
1872 4 50       10 if($infos_a->[0] == -1)
1873             {
1874 0         0 $infos_a->[0] = $this;
1875             }
1876 4 50 33     19 if ((blessed($infos_a->[0])) && ($infos_a->[0]->isa('Lingua::YaTeA::Node')))
1877             {
1878 0         0 return $infos_a;
1879             }
1880             }
1881 22         46 $infos_a->[0] = 0;
1882 22         45 return $infos_a;
1883             }
1884              
1885              
1886             sub adjustPreviousAndNext
1887             {
1888 0     0 1 0 my ($this,$previous,$next,$tree) = @_;
1889 0         0 my $new_prev;
1890             my $new_next;
1891 0         0 my $node;
1892 0         0 my $place;
1893 0         0 my $depth = 0;
1894 0 0       0 if($this->getLeftEdge->searchHead(0)->getIndex != $previous)
1895             {
1896              
1897 0         0 ($node,$place) = $this->searchLeaf($previous,\$depth);
1898 0 0       0 if(defined $node)
1899             {
1900 0   0     0 while
      0        
      0        
1901             (
1902             ((blessed($node)) && ($node->isa('Lingua::YaTeA::InternalNode')))
1903             &&
1904             (!defined $node->getPreposition)
1905             &&
1906             ($node->getFather->getID != $this->getID)
1907             )
1908             {
1909 0         0 $node = $node->getFather;
1910             }
1911            
1912 0         0 $previous = $node->searchHead(0)->getIndex;
1913             }
1914             }
1915             else
1916             {
1917 0         0 $new_prev = $previous;
1918             }
1919 0 0       0 if($this->getRightEdge->searchHead(0)->getIndex != $next)
1920             {
1921 0         0 ($node,$place) = $this->searchLeaf($next,\$depth);
1922 0 0       0 if(defined $node)
1923             {
1924 0   0     0 while
      0        
      0        
1925             (
1926             ((blessed($node)) && ($node->isa('Lingua::YaTeA::InternalNode')))
1927             &&
1928             (!defined $node->getPreposition)
1929             &&
1930             ($node->getFather->getID != $this->getID)
1931             )
1932             {
1933 0         0 $node = $node->getFather;
1934             }
1935 0         0 $next = $node->searchHead(0)->getIndex;
1936             }
1937             }
1938             else
1939             {
1940 0         0 $new_next = $next;
1941             }
1942 0         0 return ($new_prev,$new_next);
1943             }
1944              
1945              
1946             sub completeGap
1947             {
1948 0     0 1 0 my ($this,$previous,$next,$tree,$parsing_pattern_set,$parsing_direction,$tag_set,$words_a,$fh) = @_;
1949 0         0 my $index = $previous +1;
1950 0         0 my $gap_index_set = Lingua::YaTeA::IndexSet->new;
1951 0         0 my $sub_pos;
1952             my $pattern;
1953 0         0 my $position;
1954 0         0 my $node_set;
1955 0         0 my $additional_node_set;
1956 0         0 my $partial_index_set;
1957 0         0 my $success = 0;
1958             # print $fh "\n----------------------------------------\ncompleteGap " .$this->getID ." --> p=" .$previous . " n=" .$next . "\n";
1959             # $this->printRecursively($words_a,$fh);
1960 0         0 while ($index < $next)
1961             {
1962 0         0 $gap_index_set->addIndex($index++);
1963             }
1964              
1965            
1966 0 0       0 if($gap_index_set->getSize > 1) # multi-word gap
1967             {
1968 0         0 $sub_pos = $gap_index_set->buildPOSSequence($words_a,$tag_set);
1969             # print $fh "pos seq: " .$sub_pos . "\n";
1970 0         0 ($pattern,$position) = $this->getPartialPattern($gap_index_set,$tag_set,$parsing_direction,$parsing_pattern_set,$words_a);
1971 0 0 0     0 if ((blessed($pattern)) && ($pattern->isa('Lingua::YaTeA::ParsingPattern')))
1972             {
1973 0         0 $partial_index_set = $gap_index_set->getPartial($pattern->getLength,$position);
1974 0         0 $node_set = $pattern->getNodeSet->copy;
1975 0         0 $node_set->fillNodeLeaves($partial_index_set);
1976 0         0 ($success,$additional_node_set) = $this->plugInternalNode($node_set->getRoot,$previous,$next,$parsing_pattern_set,$words_a,$parsing_direction,$tag_set,$fh);
1977 0 0       0 if($success == 1)
1978             {
1979 0         0 $tree->addNodes($node_set);
1980 0         0 $tree->addNodes($additional_node_set);
1981 0 0       0 if ($tree->getSimplifiedIndexSet->simplify($partial_index_set,$additional_node_set,$tree,-1) == -1 ) {return 0;}
  0         0  
1982 0 0       0 if ($gap_index_set->simplify($partial_index_set,$additional_node_set,$tree,-1) == -1 ) {return 0;}
  0         0  
1983 0         0 $tree->updateRoot;
1984 0         0 return 1;
1985             }
1986            
1987             }
1988             else
1989             {
1990 0         0 $success = 0;
1991             }
1992 0 0       0 if($success == 0)
1993             {
1994 0         0 $success = $this->insertProgressively($previous,$next,$parsing_direction,$gap_index_set,$tree,$tag_set,$parsing_pattern_set,$words_a,$fh);
1995 0 0       0 if($success == 0)
1996             {
1997 0         0 return 0;
1998             }
1999             # print $fh "apres insertProgressiveley\n";
2000             # $this->printRecursively($words_a,$fh);
2001 0         0 return 1;
2002             }
2003            
2004             }
2005             else # one word gap
2006             {
2007 0         0 $success = $this->insertOneWord($gap_index_set->getFirst,$previous,$next,$parsing_direction,$tree,$tag_set,$parsing_pattern_set,$words_a,$fh);
2008 0 0       0 if($success == 1)
2009             {
2010 0         0 $gap_index_set->removeIndex($gap_index_set->getFirst);
2011             # print $fh "apres insertOneWord\n";
2012             # $this->printRecursively($words_a,$fh);
2013             }
2014             # else
2015             # {
2016             # print $fh "echec insertOneWord\n";
2017             # }
2018            
2019 0         0 return $success;
2020             }
2021             # print $fh "fin complete Gap2\n";
2022             # $this->printRecursively($words_a,$fh);
2023            
2024 0         0 return 1;
2025            
2026             }
2027              
2028             sub insertProgressively
2029             {
2030 0     0 1 0 my ($this,$previous,$next,$parsing_direction,$gap_index_set,$tree,$tag_set,$parsing_pattern_set,$words_a,$fh) = @_;
2031 0         0 my $success;
2032             # print $fh "insertProgresivley " . $previous . " n :" . $next . "\n";
2033 0 0       0 if($parsing_direction eq "LEFT")
2034             {
2035 0         0 $success = $this->insertOneWord($gap_index_set->getFirst,$previous,$next,$parsing_direction,$tree,$tag_set,$parsing_pattern_set,$words_a,$fh);
2036 0 0       0 if($success == 0)
2037             {
2038 0         0 $success = $this->insertOneWord($gap_index_set->getLast,$previous,$next,$parsing_direction,$tree,$tag_set,$parsing_pattern_set,$words_a,$fh);
2039 0 0       0 if($success == 1)
2040             {
2041 0         0 $gap_index_set->removeIndex($gap_index_set->getLast);
2042             }
2043             }
2044             else
2045             {
2046 0         0 $gap_index_set->removeIndex($gap_index_set->getFirst);
2047             }
2048             }
2049            
2050 0 0       0 if($parsing_direction eq "RIGHT")
2051             {
2052 0         0 $success = $this->insertOneWord($gap_index_set->getLast,$previous,$next,$parsing_direction,$tree,$tag_set,$parsing_pattern_set,$words_a,$fh);
2053 0 0       0 if($success == 0)
2054             {
2055 0         0 $success = $this->insertOneWord($gap_index_set->getFirst,$previous,$next,$parsing_direction,$tree,$tag_set,$parsing_pattern_set,$words_a,$fh);
2056 0 0       0 if($success == 1)
2057             {
2058 0         0 $gap_index_set->removeIndex($gap_index_set->getFirst);
2059             }
2060             }
2061             else
2062             {
2063 0         0 $gap_index_set->removeIndex($gap_index_set->getLast);
2064             }
2065             }
2066              
2067 0         0 return $success;
2068            
2069             }
2070              
2071             sub insertOneWord
2072             {
2073 0     0 1 0 my ($this,$index,$previous,$next,$parsing_direction,$tree,$tag_set,$parsing_pattern_set,$words_a,$fh) = @_;
2074 0         0 my $pos;
2075             my $record;
2076 0         0 my $node_set;
2077 0         0 my $index_set;
2078 0         0 my $above;
2079 0         0 my $hook_node;
2080 0         0 my $place;
2081 0         0 my $attached = 0;
2082 0         0 my $node;
2083             my $new_previous;
2084 0         0 my $new_next;
2085 0         0 my %other_place = ("LEFT" => "RIGHT", "RIGHT" => "LEFT");
2086             # print $fh "insertion mot n: " . $index . " entre " . $previous . " et " . $next . "\n";
2087              
2088 0 0       0 if($tag_set->existTag('DETERMINERS',$words_a->[$index]->getPOS))
2089             {
2090 0         0 while($this->searchLeftMostLeaf->getIndex > $index)
2091             {
2092 0 0 0     0 if ((blessed($this)) && ($this->isa('Lingua::YaTeA::InternalNode')))
2093             {
2094 0         0 $this = $this->getFather
2095             }
2096             else
2097             {
2098 0         0 return 0;
2099             }
2100             }
2101 0 0       0 if(!defined $this->getDeterminer)
2102             {
2103 0         0 $this->addDeterminer($index);
2104 0         0 $tree->getSimplifiedIndexSet->removeIndex($index);
2105 0         0 $tree->getIndexSet->addIndex($index);
2106             # print $fh "reussi\n";
2107 0         0 return 1;
2108             }
2109             else
2110             {
2111 0         0 return 0;
2112             }
2113             }
2114             else
2115             {
2116 0 0       0 if(! $tag_set->existTag('PREPOSITIONS',$words_a->[$index]->getIF))
2117             {
2118              
2119 0         0 ($node,$place) = $this->searchRoot->getNodeOfLeaf($previous,$index,$words_a);
2120             # print $fh "dans le noeud courant:" . $node->getID . " p:" . $place . "\n";
2121 0 0 0     0 if ((defined $place) && ($place =~ /EDGE/))
2122             {
2123 0 0       0 if(!defined $node)
2124             {
2125 0         0 die;
2126             }
2127             else{
2128 0 0 0     0 if(
      0        
      0        
2129             ((blessed($node->getEdge($place))) && ($node->getEdge($place)->isa('Lingua::YaTeA::Node')))
2130             ||
2131             ($node->getEdge($place)->getIndex != $previous)
2132             ||
2133             ($node->getEdgeStatus($place) ne "HEAD")
2134             )
2135             {
2136 0         0 $new_previous = $node->getEdge($place)->searchHead(0);
2137 0 0       0 if($new_previous->getIndex < $index)
2138             {
2139 0         0 $previous = $new_previous->getIndex;
2140             }
2141             }
2142             # print $fh "nouveau previous? : " .$previous ."\n";
2143              
2144             }
2145             }
2146 0         0 ($node,$place) = $this->searchRoot->getNodeOfLeaf($next,$index,$words_a,$fh);
2147             # print $fh "dans le noeud tete:" . $node->getID . " p:" . $place . "\n";
2148 0 0       0 if(!defined $node)
2149             {
2150 0         0 die;
2151             }
2152 0 0 0     0 if (
2153             (defined $node)
2154             &&
2155             ($place =~ /(LEFT|RIGHT)/)
2156             # (isa($node,'Lingua::YaTeA::Edge'))
2157             )
2158             {
2159            
2160             # print $fh "place : " . $place ." (next=" .$next .")\n";
2161             # print $fh "statut de " . $place . " dans " . $node->getID ." = " .$node->getEdgeStatus($place) . "\n";
2162              
2163 0 0 0     0 if(
      0        
      0        
2164             ((blessed($node->getEdge($place))) && ($node->getEdge($place)->isa('Lingua::YaTeA::Node')))
2165             ||
2166             ($node->getEdge($place)->getIndex != $next)
2167             ||
2168             ($node->getEdgeStatus($place) ne "HEAD")
2169             )
2170             {
2171 0         0 $new_next = $node->searchHead(0);
2172 0 0 0     0 if ((defined $new_next)
2173             &&
2174             ($new_next->getIndex > $index)
2175             )
2176             {
2177 0         0 $next = $new_next->getIndex;
2178             }
2179             else
2180             {
2181 0         0 return 0;
2182             }
2183             }
2184            
2185             # print $fh "nouveau next? : " .$next ."\n";
2186             }
2187 0 0       0 if($parsing_direction eq "LEFT") # left-first search
2188             {
2189 0         0 $index_set = Lingua::YaTeA::IndexSet->new;
2190 0         0 $index_set->addIndex($previous);
2191 0         0 $index_set->addIndex($index);
2192 0         0 $pos = $index_set->buildPOSSequence($words_a,$tag_set);
2193             # print $fh "POS: " . $pos . "\n";
2194 0 0       0 if ($record = $parsing_pattern_set->existRecord($pos))
2195             {
2196            
2197 0         0 $node_set = $this->getParseFromPattern($index_set,$record,$parsing_direction,$words_a);
2198 0         0 ($hook_node,$place) = $this->getNodeOfLeaf($previous,$index,$words_a);
2199 0 0 0     0 if((defined $hook_node) && ($hook_node->hitch($place,$node_set->getRoot,$words_a)))
2200             {
2201 0         0 $tree->addNodes($node_set);
2202 0         0 $tree->getSimplifiedIndexSet->removeIndex($index);
2203 0         0 $tree->getIndexSet->addIndex($index);
2204 0         0 $attached = 1;
2205             } else {
2206 0 0       0 if (!defined $hook_node) {
2207 0         0 warn "hook_node undefined";
2208             }
2209             }
2210             }
2211 0 0       0 if($attached == 0)
2212             {
2213 0         0 $index_set = Lingua::YaTeA::IndexSet->new;
2214            
2215 0         0 $index_set->addIndex($index);
2216 0         0 $index_set->addIndex($next);
2217 0         0 $pos = $index_set->buildPOSSequence($words_a,$tag_set);
2218              
2219 0 0       0 if ($record = $parsing_pattern_set->existRecord($pos))
2220             {
2221            
2222 0         0 $node_set = $this->getParseFromPattern($index_set,$record,$parsing_direction,$words_a);
2223 0         0 ($hook_node,$place) = $this->getNodeOfLeaf($next,$index,$words_a);
2224 0 0       0 if($hook_node->hitch($place,$node_set->getRoot,$words_a))
2225             {
2226 0         0 $tree->addNodes($node_set);
2227 0         0 $tree->getSimplifiedIndexSet->removeIndex($index);
2228 0         0 $tree->getIndexSet->addIndex($index);
2229 0         0 $attached = 1;
2230             }
2231             }
2232             }
2233            
2234             }
2235 0 0 0     0 if( # right-first search
2236             ($parsing_direction eq "RIGHT")
2237             ||
2238             ($attached == 0)
2239             )
2240             {
2241 0         0 $index_set = Lingua::YaTeA::IndexSet->new;
2242            
2243 0         0 $index_set->addIndex($index);
2244 0         0 $index_set->addIndex($next);
2245             # print $fh "recherche pattern pour ";
2246             # $index_set->print($fh);
2247             # print $fh "\n";
2248 0         0 $pos = $index_set->buildPOSSequence($words_a,$tag_set);
2249             # print $fh "POS: " . $pos . "\n";
2250 0 0       0 if ($record = $parsing_pattern_set->existRecord($pos))
2251             {
2252             # print $fh "trouve\n";
2253 0         0 $node_set = $this->getParseFromPattern($index_set,$record,$parsing_direction,$words_a);
2254              
2255 0         0 ($hook_node,$place) = $this->getNodeOfLeaf($next,$index,$words_a,$fh);
2256 0 0 0     0 if ((blessed($hook_node)) && ($hook_node->isa('Lingua::YaTeA::Node')))
2257             {
2258 0 0       0 if($hook_node->hitch($place,$node_set->getRoot,$words_a))
2259             {
2260 0         0 $tree->addNodes($node_set);
2261 0         0 $tree->getSimplifiedIndexSet->removeIndex($index);
2262 0         0 $tree->getIndexSet->addIndex($index);
2263 0         0 $attached = 1;
2264             }
2265             }
2266             else
2267             {
2268 0 0       0 if($node_set->getRoot->hitch("LEFT",$this,$words_a))
2269             {
2270 0         0 $tree->addNodes($node_set);
2271 0         0 $tree->getSimplifiedIndexSet->removeIndex($index);
2272 0         0 $tree->getIndexSet->addIndex($index);
2273 0         0 $attached = 1;
2274             }
2275            
2276             }
2277             }
2278 0 0       0 if($attached == 0)
2279             {
2280 0         0 $index_set = Lingua::YaTeA::IndexSet->new;
2281 0         0 $index_set->addIndex($previous);
2282 0         0 $index_set->addIndex($index);
2283            
2284             # print $fh "recherche pattern pour ";
2285             # $index_set->print($fh);
2286             # print $fh "\n";
2287 0         0 $pos = $index_set->buildPOSSequence($words_a,$tag_set);
2288             # print $fh "POS: " . $pos . "\n";
2289 0 0       0 if ($record = $parsing_pattern_set->existRecord($pos))
2290             {
2291 0         0 $node_set = $this->getParseFromPattern($index_set,$record,$parsing_direction,$words_a,$fh);
2292              
2293 0         0 ($hook_node,$place) = $this->getNodeOfLeaf($previous,$index,$words_a,$fh);
2294              
2295 0 0 0     0 if ((blessed($hook_node)) && ($hook_node->isa('Lingua::YaTeA::Node')))
2296             {
2297             # print $fh "hook: ". $hook_node->getID . " place:".$place."\n";
2298             # print $fh "root :" . $node_set->getRoot->getID . "\n";
2299 0 0       0 if($hook_node->hitch($place,$node_set->getRoot,$words_a,$fh))
2300             {
2301 0         0 $tree->addNodes($node_set);
2302 0         0 $tree->getSimplifiedIndexSet->removeIndex($index);
2303 0         0 $tree->getIndexSet->addIndex($index);
2304 0         0 $attached = 1;
2305             }
2306             }
2307             else
2308             {
2309            
2310 0 0       0 if($node_set->getRoot->hitch("RIGHT",$this,$words_a))
2311             {
2312 0         0 $tree->addNodes($node_set);
2313 0         0 $tree->getSimplifiedIndexSet->removeIndex($index);
2314 0         0 $tree->getIndexSet->addIndex($index);
2315 0         0 $attached = 1;
2316             }
2317            
2318             }
2319             }
2320             }
2321             }
2322             }
2323             }
2324             # print $fh "reussi " .$attached . " \n";
2325 0         0 return $attached;
2326             }
2327              
2328             sub getPartialPattern
2329             {
2330 0     0 1 0 my ($this,$simplified_index_set,$tag_set,$parsing_direction,$parsing_pattern_set,$words_a) = @_;
2331 0         0 my $pattern;
2332             my $position;
2333 0         0 my $POS = $simplified_index_set->buildPOSSequence($words_a,$tag_set);
2334 0 0       0 if($parsing_direction eq "LEFT")
2335             {
2336 0         0 ($pattern,$position) = $this->getPatternsLeftFirst($POS,$parsing_pattern_set,$parsing_direction);
2337             }
2338             else{
2339 0         0 ($pattern,$position) = $this->getPatternsRightFirst($POS,$parsing_pattern_set,$parsing_direction);
2340             }
2341 0         0 return ($pattern,$position);
2342             }
2343              
2344              
2345              
2346             sub getPatternsLeftFirst
2347             {
2348 0     0 1 0 my ($this,$POS,$parsing_pattern_set,$parsing_direction) = @_;
2349 0         0 my $pattern;
2350 0         0 my $position = "LEFT";
2351 0 0 0     0 if (
2352             ($pattern = $this->getPatternOnTheLeft($POS,$parsing_pattern_set,$parsing_direction))
2353             &&
2354             ($pattern == 0)
2355             )
2356             {
2357 0         0 $pattern = $this->getPatternOnTheRight($POS,$parsing_pattern_set,$parsing_direction);
2358 0         0 $position = "RIGHT";
2359             }
2360 0         0 return ($pattern,$position);
2361             }
2362              
2363             sub getPatternsRightFirst
2364             {
2365 0     0 1 0 my ($this,$POS,$parsing_pattern_set,$parsing_direction) = @_;
2366 0         0 my $pattern;
2367 0         0 my $position = "RIGHT";
2368 0 0 0     0 if (
2369             ($pattern = $this->getPatternOnTheRight($POS,$parsing_pattern_set,$parsing_direction))
2370             &&
2371             ($pattern == 0)
2372             )
2373             {
2374 0         0 $pattern = $this->getPatternOnTheLeft($POS,$parsing_pattern_set,$parsing_direction);
2375 0         0 $position = "LEFT";
2376             }
2377            
2378 0         0 return ($pattern,$position);
2379             }
2380              
2381             sub getPatternOnTheLeft
2382             {
2383 0     0 1 0 my ($this,$POS,$parsing_pattern_set,$parsing_direction) = @_;
2384 0         0 my @selection;
2385             my $key;
2386 0         0 my $record;
2387 0         0 my $pattern;
2388 0         0 my $qm_key;
2389              
2390 0         0 while (($key,$record) = each %{$parsing_pattern_set->getRecordSet})
  0         0  
2391             {
2392 0         0 $qm_key = quotemeta($key);
2393 0 0       0 if ($POS =~ /^$qm_key/)
2394             {
2395 0         0 foreach $pattern (@{$record->getPatterns})
  0         0  
2396             {
2397 0         0 push @selection, $pattern;
2398             }
2399             }
2400             }
2401 0         0 $pattern = $this->chooseBestPattern(\@selection,$parsing_direction);
2402 0         0 return $pattern;
2403             }
2404              
2405             sub getPatternOnTheRight
2406             {
2407 0     0 1 0 my ($this,$POS,$parsing_pattern_set,$parsing_direction) = @_;
2408 0         0 my @selection;
2409             my $key;
2410 0         0 my $record;
2411 0         0 my $pattern;
2412 0         0 my $qm_key;
2413              
2414 0         0 while (($key,$record) = each %{$parsing_pattern_set->getRecordSet})
  0         0  
2415             {
2416 0         0 $qm_key = quotemeta($key);
2417 0 0       0 if ($POS =~ /$qm_key$/)
2418             {
2419 0         0 foreach $pattern (@{$record->getPatterns})
  0         0  
2420             {
2421 0         0 push @selection, $pattern;
2422             }
2423             }
2424             }
2425 0         0 $pattern = $this->chooseBestPattern(\@selection,$parsing_direction);
2426 0         0 return $pattern;
2427             }
2428              
2429              
2430             # sub chooseBestPattern
2431             # {
2432             # my ($this,$patterns_a,$parsing_direction) = @_;
2433            
2434             # my @tmp = sort {$this->sortPatternsByPriority($a,$b,$parsing_direction)} @$patterns_a;
2435             # my @sorted = @tmp;
2436            
2437             # return $sorted[0];
2438             # }
2439              
2440             sub sortPatternsByPriority
2441             {
2442 0     0 1 0 my ($this,$first,$second,$parsing_direction) = @_;
2443              
2444 0 0       0 if($first->getDirection eq $parsing_direction)
2445             {
2446 0 0       0 if($second->getDirection eq $parsing_direction)
2447             {
2448 0 0       0 if($first->getNumContentWords > $second->getNumContentWords)
2449             {
2450 0         0 return -1;
2451             }
2452             else
2453             {
2454 0 0       0 if($first->getNumContentWords < $second->getNumContentWords)
2455             {
2456 0         0 return 1;
2457             }
2458             else
2459             {
2460 0         0 return ($second->getPriority <=> $first->getPriority);
2461             }
2462             }
2463             }
2464             else
2465             {
2466 0         0 return -1;
2467             }
2468             }
2469             else
2470             {
2471 0 0       0 if($second->getDirection eq $parsing_direction)
2472             {
2473 0         0 return 1;
2474             }
2475             else
2476             {
2477 0 0       0 if($first->getNumContentWords > $second->getNumContentWords)
2478             {
2479 0         0 return -1;
2480             }
2481             else
2482             {
2483 0 0       0 if($first->getNumContentWords < $second->getNumContentWords)
2484             {
2485 0         0 return 1;
2486             }
2487             else
2488             {
2489 0         0 return ($second->getPriority <=> $first->getPriority);
2490             }
2491             }
2492             }
2493             }
2494             }
2495              
2496             sub addDeterminer
2497             {
2498 0     0 1 0 my ($this,$index) = @_;
2499 0         0 my $new_leaf = Lingua::YaTeA::TermLeaf->new($index);
2500 0         0 $this->{DET} = $new_leaf;
2501             }
2502              
2503             sub getHookNode
2504             {
2505 23     23 1 49 my ($this,$insertion_type,$place,$below_index_set,$fh) = @_;
2506 23         32 my $hook = $this;
2507 23         32 my $intermediate;
2508 23         34 my $depth = 0;
2509 23         33 my $right_most;
2510 23         76 my %other_place = ("LEFT"=>"RIGHT", "RIGHT"=>"LEFT");
2511             # print $fh "type insertion : " . $insertion_type . "\n";
2512 23 100       90 if($insertion_type eq "RIGHT")
2513             {
2514             ##### SA debug 14/01/2008
2515             # print $fh "right most : " .$hook->getLeftEdge->searchRightMostLeaf->getIndex . "\n";
2516              
2517 19 50 66     64 if(
2518             ($hook->getEdgeStatus($place) eq "MODIFIER")
2519             &&
2520             ($hook->getEdge($other_place{$place})->searchRightMostLeaf->getIndex > $below_index_set->getFirst)
2521             )
2522             {
2523 0         0 undef $hook;
2524             }
2525             else
2526             {
2527             # if(! isa($hook,'Lingua::YaTeA::RootNode'))
2528             # {
2529             # print $fh "status :". $hook->getEdgeStatus($place) . "\n";
2530             # print $fh "frere: " . $hook->getEdge($other_place{$place})->searchRightMostLeaf->getIndex . "\n";
2531             # }
2532 19   33     115 while (
      0        
      33        
      0        
2533             (! ((blessed($hook)) && ($hook->isa('Lingua::YaTeA::RootNode'))))
2534             &&
2535             (
2536             (
2537             ($place eq "RIGHT")
2538             &&
2539             ($hook->getEdge($other_place{$place})->searchRightMostLeaf->getIndex > $below_index_set->getFirst)
2540             )
2541             ||
2542             (
2543             ($place eq "LEFT")
2544             &&
2545             ($hook->getFather->getLeftEdge->searchRightMostLeaf->getIndex > $below_index_set->getFirst)
2546             )
2547             )
2548             &&
2549             ($hook->getEdgeStatus($place) eq "HEAD")
2550             )
2551             {
2552 0         0 $intermediate = $hook;
2553             # print $fh "on entre la\n";
2554 0 0 0     0 if ((blessed($hook)) && ($hook->isa('Lingua::YaTeA::InternalNode')))
2555             {
2556 0         0 $place = $hook->getNodePosition;
2557 0         0 $hook = $hook->getFather;
2558             }
2559             else
2560             {
2561 0         0 undef $hook;
2562 0         0 last;
2563             }
2564             # print $fh "right most : " .$hook->getLeftEdge->searchRightMostLeaf->getIndex . "\n";
2565             }
2566 19 50       49 if(defined $intermediate)
2567             {
2568 0 0       0 if($intermediate->searchLeftMostLeaf->getIndex < $below_index_set->getFirst)
2569             {
2570 0         0 undef $hook;
2571             }
2572             }
2573             }
2574             }
2575              
2576 23 50       57 if($insertion_type eq "LEFT")
2577             {
2578             # print $fh "left most : " .$hook->getRightEdge->searchLeftMostLeaf->getIndex . "\n";
2579 0         0 while ($hook->getRightEdge->searchLeftMostLeaf->getIndex < $below_index_set->getFirst)
2580             {
2581 0         0 $intermediate = $hook;
2582 0 0 0     0 if ((blessed($hook)) && ($hook->isa('Lingua::YaTeA::InternalNode')))
2583             {
2584 0         0 $hook = $hook->getFather;
2585             }
2586             else
2587             {
2588 0         0 undef $hook;
2589 0         0 last;
2590             }
2591             }
2592 0 0       0 if(defined $intermediate)
2593             {
2594 0 0       0 if($intermediate->searchRightMostLeaf(\$depth)->getIndex > $below_index_set->getLast)
2595             {
2596 0         0 undef $hook;
2597             }
2598             }
2599             }
2600            
2601 23         79 return ($hook,$intermediate,$place);
2602             }
2603              
2604             sub linkToIsland
2605             {
2606 11     11 1 24 my ($this) = @_;
2607 11         18 $this->{"LINKED_TO_ISLAND"} = 1;
2608 11 50 33     26 if ((blessed($this->getLeftEdge)) && ($this->getLeftEdge->isa('Lingua::YaTeA::Node')))
2609             {
2610 0         0 $this->getLeftEdge->linkToIsland;
2611             }
2612 11 100 66     31 if ((blessed($this->getRightEdge)) && ($this->getRightEdge->isa('Lingua::YaTeA::Node')))
2613             {
2614 2         4 $this->getRightEdge->linkToIsland;
2615             }
2616            
2617             }
2618              
2619             1;
2620              
2621             __END__