line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::YaTeA::NodeSet; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
33
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
135
|
|
4
|
5
|
|
|
5
|
|
37
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
111
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
2198
|
use UNIVERSAL; |
|
5
|
|
|
|
|
54
|
|
|
5
|
|
|
|
|
24
|
|
7
|
5
|
|
|
5
|
|
163
|
use Scalar::Util qw(blessed); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
13747
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION=$Lingua::YaTeA::VERSION; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new |
12
|
|
|
|
|
|
|
{ |
13
|
484
|
|
|
484
|
1
|
1007
|
my ($class) = @_; |
14
|
484
|
|
|
|
|
992
|
my $this = {}; |
15
|
484
|
|
|
|
|
871
|
bless ($this,$class); |
16
|
484
|
|
|
|
|
1091
|
$this->{ROOT_NODE} = (); |
17
|
484
|
|
|
|
|
946
|
$this->{NODES} = []; |
18
|
484
|
|
|
|
|
1084
|
return $this; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub addNode |
24
|
|
|
|
|
|
|
{ |
25
|
638
|
|
|
638
|
1
|
1205
|
my ($this,$node) = @_; |
26
|
638
|
|
|
|
|
1002
|
push @{$this->{NODES}}, $node; |
|
638
|
|
|
|
|
1396
|
|
27
|
638
|
|
|
|
|
1534
|
$this->updateRoot; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub getNodes |
31
|
|
|
|
|
|
|
{ |
32
|
2438
|
|
|
2438
|
1
|
3934
|
my ($this) = @_; |
33
|
2438
|
|
|
|
|
5411
|
return $this->{NODES}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub setRoot |
38
|
|
|
|
|
|
|
{ |
39
|
606
|
|
|
606
|
1
|
1011
|
my ($this) = @_; |
40
|
606
|
|
|
|
|
885
|
my $node; |
41
|
606
|
|
|
|
|
808
|
foreach $node (@{$this->getNodes}) |
|
606
|
|
|
|
|
1020
|
|
42
|
|
|
|
|
|
|
{ |
43
|
700
|
100
|
66
|
|
|
4172
|
if ((blessed($node)) && ($node->isa('Lingua::YaTeA::RootNode'))) |
44
|
|
|
|
|
|
|
{ |
45
|
606
|
|
|
|
|
1265
|
$this->{ROOT_NODE} = $node; |
46
|
606
|
|
|
|
|
1695
|
return; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
0
|
die "No root node\n"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub getRoot |
54
|
|
|
|
|
|
|
{ |
55
|
3203
|
|
|
3203
|
1
|
5416
|
my ($this,$root) = @_; |
56
|
3203
|
|
|
|
|
11715
|
return $this->{ROOT_NODE}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub getNode |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
0
|
1
|
0
|
my ($this,$index) = @_; |
65
|
0
|
|
|
|
|
0
|
return $this->getNodes->[$index]; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub updateRoot |
69
|
|
|
|
|
|
|
{ |
70
|
710
|
|
|
710
|
1
|
1210
|
my ($this) = @_; |
71
|
710
|
|
|
|
|
1082
|
my %nodes_id; |
72
|
|
|
|
|
|
|
my $node; |
73
|
710
|
|
|
|
|
973
|
foreach $node (@{$this->getNodes}) |
|
710
|
|
|
|
|
1327
|
|
74
|
|
|
|
|
|
|
{ |
75
|
1156
|
|
|
|
|
2736
|
$nodes_id{$node->getID}++; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
710
|
50
|
|
|
|
1157
|
if(scalar @{$this->getNodes} == 0) |
|
710
|
|
|
|
|
1249
|
|
79
|
|
|
|
|
|
|
{ |
80
|
0
|
|
|
|
|
0
|
undef $this->{ROOT_NODE}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
else |
83
|
|
|
|
|
|
|
{ |
84
|
710
|
100
|
66
|
|
|
1393
|
if |
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
85
|
|
|
|
|
|
|
( |
86
|
|
|
|
|
|
|
(!defined $this->getRoot) |
87
|
|
|
|
|
|
|
|| |
88
|
|
|
|
|
|
|
(!exists $nodes_id{$this->getRoot->getID}) |
89
|
|
|
|
|
|
|
|| |
90
|
|
|
|
|
|
|
((blessed($this->getRoot)) && (!$this->getRoot->isa('Lingua::YaTeA::RootNode'))) |
91
|
|
|
|
|
|
|
) |
92
|
|
|
|
|
|
|
{ |
93
|
|
|
|
|
|
|
|
94
|
326
|
|
|
|
|
650
|
$this->setRoot; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub copy |
102
|
|
|
|
|
|
|
{ |
103
|
204
|
|
|
204
|
1
|
405
|
my ($this) = @_; |
104
|
204
|
|
|
|
|
507
|
my $new_set = Lingua::YaTeA::NodeSet->new; |
105
|
204
|
|
|
|
|
499
|
my $node = $this->getRoot; |
106
|
204
|
|
|
|
|
357
|
my $depth = 0; |
107
|
|
|
|
|
|
|
|
108
|
204
|
|
|
|
|
801
|
$node->copyRecursively($new_set, $depth); |
109
|
204
|
|
|
|
|
580
|
$this->addFreeNodes($new_set); |
110
|
204
|
|
|
|
|
618
|
return $new_set; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub addFreeNodes |
114
|
|
|
|
|
|
|
{ |
115
|
204
|
|
|
204
|
1
|
404
|
my ($this,$new_set) = @_; |
116
|
204
|
|
|
|
|
323
|
my $node; |
117
|
|
|
|
|
|
|
|
118
|
204
|
|
|
|
|
290
|
foreach $node (@{$this->getNodes}) |
|
204
|
|
|
|
|
426
|
|
119
|
|
|
|
|
|
|
{ |
120
|
|
|
|
|
|
|
|
121
|
271
|
100
|
66
|
|
|
1553
|
if ((blessed($node)) && ($node->isa('Lingua::YaTeA::RootNode')) |
|
|
|
100
|
|
|
|
|
122
|
|
|
|
|
|
|
&& |
123
|
|
|
|
|
|
|
($node ne $this->getRoot) |
124
|
|
|
|
|
|
|
) |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
{ |
127
|
4
|
|
|
|
|
12
|
$node->copyRecursively($new_set); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub fillNodeLeaves |
134
|
|
|
|
|
|
|
{ |
135
|
110
|
|
|
110
|
1
|
261
|
my ($this,$index_set) = @_; |
136
|
110
|
|
|
|
|
184
|
my $counter = 0; |
137
|
|
|
|
|
|
|
|
138
|
110
|
|
|
|
|
201
|
$this->getRoot->fillLeaves(\$counter,$index_set, 0); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub updateLeaves |
144
|
|
|
|
|
|
|
{ |
145
|
9
|
|
|
9
|
1
|
27
|
my ($this,$index_set) = @_; |
146
|
9
|
|
|
|
|
21
|
my $counter = 0; |
147
|
9
|
|
|
|
|
26
|
$this->getRoot->updateLeaves(\$counter,$index_set); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub searchFreeNodes |
151
|
|
|
|
|
|
|
{ |
152
|
76
|
|
|
76
|
1
|
173
|
my ($this,$words_a) = @_; |
153
|
76
|
|
|
|
|
135
|
my $node; |
154
|
|
|
|
|
|
|
my @free_nodes; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# print STDERR "sFN1\n"; |
157
|
|
|
|
|
|
|
|
158
|
76
|
|
|
|
|
129
|
foreach $node (@{$this->getNodes}) |
|
76
|
|
|
|
|
162
|
|
159
|
|
|
|
|
|
|
{ |
160
|
|
|
|
|
|
|
# print STDERR "sFN2\n"; |
161
|
219
|
100
|
66
|
|
|
1132
|
if((blessed($node)) && ($node->isa('Lingua::YaTeA::RootNode'))) |
162
|
|
|
|
|
|
|
{ |
163
|
81
|
|
|
|
|
218
|
push @free_nodes, $node; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# print STDERR "sFN3\n"; |
168
|
|
|
|
|
|
|
|
169
|
76
|
|
|
|
|
395
|
return \@free_nodes; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub removeNodes{ |
175
|
0
|
|
|
0
|
0
|
0
|
my ($this,$root_node,$words_a,$fh) = @_; |
176
|
0
|
|
|
|
|
0
|
my @tmp; |
177
|
|
|
|
|
|
|
my $node; |
178
|
0
|
|
|
|
|
0
|
my @unplugged; |
179
|
0
|
|
|
|
|
0
|
my $previous; |
180
|
0
|
|
|
|
|
0
|
while ($node = pop @{$this->getNodes}) |
|
0
|
|
|
|
|
0
|
|
181
|
|
|
|
|
|
|
{ |
182
|
0
|
0
|
|
|
|
0
|
if($node->getID == $root_node->getID) |
183
|
|
|
|
|
|
|
{ |
184
|
0
|
0
|
0
|
|
|
0
|
if ((blessed($node)) && ($node->isa('Lingua::YaTeA::InternalNode'))) |
185
|
|
|
|
|
|
|
{ |
186
|
0
|
0
|
0
|
|
|
0
|
if( |
|
|
|
0
|
|
|
|
|
187
|
|
|
|
|
|
|
(blessed($node->getFather->getLeftEdge)) && ($node->getFather->getLeftEdge->isa('Lingua::YaTeA::InternalNode' ) |
188
|
|
|
|
|
|
|
&& |
189
|
|
|
|
|
|
|
($node->getFather->getLeftEdge->getID == $node->getID) |
190
|
|
|
|
|
|
|
) |
191
|
|
|
|
|
|
|
) |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
{ |
194
|
0
|
|
|
|
|
0
|
$node->{FATHER}->{LEFT_EDGE} = $node->searchHead(0); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
else |
197
|
|
|
|
|
|
|
{ |
198
|
0
|
0
|
0
|
|
|
0
|
if( |
|
|
|
0
|
|
|
|
|
199
|
|
|
|
|
|
|
(blessed($node->getFather->getRightEdge)) && ($node->getFather->getRightEdge->isa('Lingua::YaTeA::InternalNode' ) |
200
|
|
|
|
|
|
|
&& |
201
|
|
|
|
|
|
|
($node->getFather->getRightEdge->getID == $node->getID) |
202
|
|
|
|
|
|
|
) |
203
|
|
|
|
|
|
|
) |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
{ |
206
|
0
|
|
|
|
|
0
|
$node->{FATHER}->{RIGHT_EDGE} = $node->searchHead(0); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
} |
210
|
0
|
0
|
0
|
|
|
0
|
if ((blessed($node->getLeftEdge)) && ($node->getLeftEdge->isa('Lingua::YaTeA::Node'))) |
211
|
|
|
|
|
|
|
{ |
212
|
|
|
|
|
|
|
# print $fh "rebless left:" . $node->getLeftEdge->getID . "\n"; |
213
|
0
|
|
|
|
|
0
|
undef $node->getLeftEdge->{FATHER}; |
214
|
0
|
|
|
|
|
0
|
bless($node->getLeftEdge,'Lingua::YaTeA::RootNode'); |
215
|
0
|
|
|
|
|
0
|
$previous = -1; |
216
|
0
|
0
|
|
|
|
0
|
if($node->getLeftEdge->isDiscontinuous(\$previous,$words_a,$fh)->[0] == -1) |
217
|
|
|
|
|
|
|
{ |
218
|
0
|
|
|
|
|
0
|
push @unplugged,$node->getLeftEdge; |
219
|
|
|
|
|
|
|
} |
220
|
0
|
|
|
|
|
0
|
$node->{LEFT_EDGE} = $node->getLeftEdge->searchHead(0); |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
} |
223
|
0
|
0
|
0
|
|
|
0
|
if ((blessed($node->getRightEdge)) && ($node->getRightEdge->isa('Lingua::YaTeA::Node'))) |
224
|
|
|
|
|
|
|
{ |
225
|
|
|
|
|
|
|
# print $fh "rebless right:" . $node->getRightEdge->getID . "\n"; |
226
|
0
|
|
|
|
|
0
|
undef $node->getRightEdge->{FATHER}; |
227
|
0
|
|
|
|
|
0
|
bless($node->getRightEdge,'Lingua::YaTeA::RootNode'); |
228
|
|
|
|
|
|
|
# $node->getRightEdge->printRecursively($words_a,$fh); |
229
|
0
|
|
|
|
|
0
|
$previous = -1; |
230
|
0
|
0
|
|
|
|
0
|
if($node->getRightEdge->isDiscontinuous(\$previous,$words_a,$fh)->[0] == -1) |
231
|
|
|
|
|
|
|
{ |
232
|
0
|
|
|
|
|
0
|
push @unplugged,$node->getRightEdge; |
233
|
|
|
|
|
|
|
} |
234
|
0
|
|
|
|
|
0
|
$node->{RIGHT_EDGE} = $node->getRightEdge->searchHead(0); |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
else |
238
|
|
|
|
|
|
|
{ |
239
|
0
|
|
|
|
|
0
|
push @tmp,$node; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
0
|
@{$this->getNodes} = @tmp; |
|
0
|
|
|
|
|
0
|
|
245
|
0
|
|
|
|
|
0
|
$this->updateRoot; |
246
|
0
|
|
|
|
|
0
|
return \@unplugged; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
sub hitchMore |
252
|
|
|
|
|
|
|
{ |
253
|
0
|
|
|
0
|
1
|
0
|
my ($this,$added_node_set,$added_index_set,$words_a,$fh) = @_; |
254
|
0
|
|
|
|
|
0
|
my $free_nodes_a = $this->searchFreeNodes($words_a); |
255
|
0
|
|
|
|
|
0
|
my $node; |
256
|
|
|
|
|
|
|
my $pivot; |
257
|
0
|
|
|
|
|
0
|
my $hook_node; |
258
|
0
|
|
|
|
|
0
|
my $hook_place; |
259
|
0
|
|
|
|
|
0
|
my $below; |
260
|
0
|
|
|
|
|
0
|
my %integrated; |
261
|
|
|
|
|
|
|
|
262
|
0
|
0
|
|
|
|
0
|
if(scalar @$free_nodes_a != 0) |
263
|
|
|
|
|
|
|
{ |
264
|
0
|
|
|
|
|
0
|
foreach $node (@$free_nodes_a) |
265
|
|
|
|
|
|
|
{ |
266
|
|
|
|
|
|
|
|
267
|
0
|
0
|
0
|
|
|
0
|
if( |
268
|
|
|
|
|
|
|
($node != $added_node_set->getNode(0)->searchRoot) |
269
|
|
|
|
|
|
|
&& |
270
|
|
|
|
|
|
|
(!exists $integrated{$node->getID}) |
271
|
|
|
|
|
|
|
) |
272
|
|
|
|
|
|
|
{ |
273
|
0
|
|
|
|
|
0
|
$pivot = $node->searchHead(0)->getIndex; |
274
|
0
|
0
|
|
|
|
0
|
if($added_index_set->getLast == $pivot) |
275
|
|
|
|
|
|
|
{ |
276
|
0
|
|
|
|
|
0
|
($hook_node,$hook_place) = $node->getNodeOfLeaf($pivot,$added_index_set->getFirst,$words_a); |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
else |
279
|
|
|
|
|
|
|
{ |
280
|
0
|
0
|
|
|
|
0
|
if($added_index_set->getFirst == $pivot) |
281
|
|
|
|
|
|
|
{ |
282
|
0
|
|
|
|
|
0
|
($hook_node,$hook_place) = $node->getNodeOfLeaf($pivot,$added_index_set->getLast,$words_a); |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
|
286
|
0
|
0
|
0
|
|
|
0
|
if ((blessed($hook_node)) && ($hook_node->isa('Lingua::YaTeA::Node'))) |
287
|
|
|
|
|
|
|
{ |
288
|
0
|
0
|
|
|
|
0
|
if($hook_node->hitch($hook_place,$added_node_set->getRoot,$words_a)) |
289
|
|
|
|
|
|
|
{ |
290
|
|
|
|
|
|
|
|
291
|
0
|
|
|
|
|
0
|
$integrated{$added_node_set->getRoot->getID}= 1; |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
sub findHierarchy |
301
|
|
|
|
|
|
|
{ |
302
|
0
|
|
|
0
|
1
|
0
|
my ($this,$pivot,$added_index_set,$added_node_set) = @_; |
303
|
0
|
|
|
|
|
0
|
my $node; |
304
|
|
|
|
|
|
|
my $pivot_node; |
305
|
0
|
|
|
|
|
0
|
my $pivot_place; |
306
|
0
|
|
|
|
|
0
|
my $left_most; |
307
|
0
|
|
|
|
|
0
|
my $right_most; |
308
|
0
|
|
|
|
|
0
|
my $recorded; |
309
|
0
|
|
|
|
|
0
|
my $depth = 0; |
310
|
|
|
|
|
|
|
|
311
|
0
|
|
|
|
|
0
|
foreach $node (@{$this->getNodes}) |
|
0
|
|
|
|
|
0
|
|
312
|
|
|
|
|
|
|
{ |
313
|
0
|
|
|
|
|
0
|
$depth = 0; |
314
|
0
|
0
|
0
|
|
|
0
|
if ((blessed($node)) && ($node->isa('Lingua::YaTeA::RootNode'))) |
315
|
|
|
|
|
|
|
{ |
316
|
0
|
|
|
|
|
0
|
($pivot_node,$pivot_place) = $node->searchLeaf($pivot,\$depth); |
317
|
|
|
|
|
|
|
|
318
|
0
|
0
|
0
|
|
|
0
|
if ((blessed($pivot_node)) && ($pivot_node->isa('Lingua::YaTeA::Node'))) |
319
|
|
|
|
|
|
|
{ |
320
|
0
|
|
|
|
|
0
|
$left_most = $node->searchLeftMostLeaf; |
321
|
0
|
|
|
|
|
0
|
$depth = 0; |
322
|
0
|
|
|
|
|
0
|
$right_most = $node->searchRightMostLeaf(\$depth); |
323
|
0
|
|
|
|
|
0
|
$recorded = $node; |
324
|
0
|
|
|
|
|
0
|
last; |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
} |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
|
329
|
0
|
0
|
0
|
|
|
0
|
if( |
330
|
|
|
|
|
|
|
(defined $left_most) |
331
|
|
|
|
|
|
|
&& |
332
|
|
|
|
|
|
|
(defined $right_most) |
333
|
|
|
|
|
|
|
) |
334
|
|
|
|
|
|
|
{ |
335
|
0
|
0
|
|
|
|
0
|
if($right_most->getIndex == $added_index_set->getLast) |
336
|
|
|
|
|
|
|
{ |
337
|
0
|
0
|
|
|
|
0
|
if($left_most->getIndex > $added_index_set->getFirst) |
338
|
|
|
|
|
|
|
{ |
339
|
0
|
|
|
|
|
0
|
($pivot_node,$pivot_place) = $added_node_set->getRoot->searchLeaf($pivot,\$depth); |
340
|
0
|
|
|
|
|
0
|
return ($pivot_node,$pivot_place,$recorded); |
341
|
|
|
|
|
|
|
} |
342
|
0
|
0
|
|
|
|
0
|
if($left_most->getIndex < $added_index_set->getFirst) |
343
|
|
|
|
|
|
|
{ |
344
|
0
|
|
|
|
|
0
|
return ($pivot_node,$pivot_place,$added_node_set->getRoot); |
345
|
|
|
|
|
|
|
} |
346
|
0
|
|
|
|
|
0
|
die "not defined"; |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
|
349
|
0
|
0
|
|
|
|
0
|
if($right_most->getIndex == $added_index_set->getFirst) |
350
|
|
|
|
|
|
|
{ |
351
|
0
|
|
|
|
|
0
|
($pivot_node,$pivot_place) = $added_node_set->getRoot->searchLeaf($pivot,\$depth); |
352
|
0
|
|
|
|
|
0
|
return ($pivot_node,$pivot_place,$recorded); |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
|
355
|
0
|
0
|
|
|
|
0
|
if($left_most->getIndex == $added_index_set->getLast) |
356
|
|
|
|
|
|
|
{ |
357
|
|
|
|
|
|
|
|
358
|
0
|
0
|
|
|
|
0
|
if($added_node_set->getRoot->searchHead(0)->getIndex == $left_most->getIndex) |
359
|
|
|
|
|
|
|
{ |
360
|
0
|
|
|
|
|
0
|
return ($pivot_node,$pivot_place,$added_node_set->getRoot); |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
else |
363
|
|
|
|
|
|
|
{ |
364
|
0
|
|
|
|
|
0
|
($pivot_node,$pivot_place) = $added_node_set->getRoot->searchLeaf($pivot,\$depth); |
365
|
0
|
|
|
|
|
0
|
return ($pivot_node,$pivot_place,$recorded); |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
} |
368
|
|
|
|
|
|
|
|
369
|
0
|
0
|
|
|
|
0
|
if($left_most->getIndex == $added_index_set->getFirst) |
370
|
|
|
|
|
|
|
{ |
371
|
0
|
0
|
|
|
|
0
|
if($right_most->getIndex > $added_index_set->getLast) |
372
|
|
|
|
|
|
|
{ |
373
|
0
|
|
|
|
|
0
|
return ($pivot_node,$pivot_place,$added_node_set->getRoot); |
374
|
|
|
|
|
|
|
} |
375
|
0
|
0
|
|
|
|
0
|
if($right_most->getIndex < $added_index_set->getLast) |
376
|
|
|
|
|
|
|
{ |
377
|
0
|
|
|
|
|
0
|
($pivot_node,$pivot_place) = $added_node_set->getRoot->searchLeaf($pivot,\$depth); |
378
|
0
|
|
|
|
|
0
|
return ($pivot_node,$pivot_place,$recorded); |
379
|
|
|
|
|
|
|
} |
380
|
|
|
|
|
|
|
} |
381
|
0
|
0
|
|
|
|
0
|
if($left_most->getIndex > $added_index_set->getFirst) |
382
|
|
|
|
|
|
|
{ |
383
|
0
|
0
|
|
|
|
0
|
if($right_most->getIndex < $added_index_set->getLast) |
384
|
|
|
|
|
|
|
{ |
385
|
0
|
|
|
|
|
0
|
($pivot_node,$pivot_place) = $added_node_set->getRoot->searchLeaf($pivot,\$depth); |
386
|
0
|
|
|
|
|
0
|
return ($pivot_node,$pivot_place,$recorded); |
387
|
|
|
|
|
|
|
} |
388
|
|
|
|
|
|
|
else |
389
|
|
|
|
|
|
|
{ |
390
|
0
|
|
|
|
|
0
|
($pivot_node,$pivot_place) = $added_node_set->getRoot->searchLeaf($pivot,\$depth); |
391
|
0
|
|
|
|
|
0
|
return ($pivot_node,$pivot_place,$recorded); |
392
|
|
|
|
|
|
|
} |
393
|
0
|
|
|
|
|
0
|
die "not defined"; |
394
|
|
|
|
|
|
|
} |
395
|
|
|
|
|
|
|
|
396
|
0
|
0
|
|
|
|
0
|
if($left_most->getIndex < $added_index_set->getFirst) |
397
|
|
|
|
|
|
|
{ |
398
|
0
|
0
|
|
|
|
0
|
if($right_most->getIndex > $added_index_set->getLast) |
399
|
|
|
|
|
|
|
{ |
400
|
0
|
|
|
|
|
0
|
return ($pivot_node,$pivot_place,$added_node_set->getRoot->searchLeftMostNode); |
401
|
|
|
|
|
|
|
} |
402
|
0
|
0
|
|
|
|
0
|
if($recorded->searchHead(0)->getIndex == $pivot) |
403
|
|
|
|
|
|
|
{ |
404
|
|
|
|
|
|
|
|
405
|
0
|
|
|
|
|
0
|
($pivot_node,$pivot_place) = $added_node_set->getRoot->searchLeaf($pivot,\$depth); |
406
|
0
|
|
|
|
|
0
|
return ($pivot_node,$pivot_place,$recorded); |
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
else |
409
|
|
|
|
|
|
|
{ |
410
|
0
|
|
|
|
|
0
|
return; |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
} |
413
|
0
|
|
|
|
|
0
|
die "not defined"; |
414
|
|
|
|
|
|
|
} |
415
|
|
|
|
|
|
|
} |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
sub getNodeWithPivot |
419
|
|
|
|
|
|
|
{ |
420
|
61
|
|
|
61
|
1
|
163
|
my ($this,$pivot) = @_; |
421
|
61
|
|
|
|
|
102
|
my $node; |
422
|
|
|
|
|
|
|
|
423
|
61
|
|
|
|
|
107
|
foreach $node (@{$this->getNodes}) |
|
61
|
|
|
|
|
145
|
|
424
|
|
|
|
|
|
|
{ |
425
|
106
|
100
|
66
|
|
|
260
|
if ( |
|
|
|
100
|
|
|
|
|
426
|
|
|
|
|
|
|
(blessed($node->getLeftEdge)) && ($node->getLeftEdge->isa('Lingua::YaTeA::TermLeaf')) |
427
|
|
|
|
|
|
|
&& |
428
|
|
|
|
|
|
|
($node->getLeftEdge->getIndex == $pivot) |
429
|
|
|
|
|
|
|
) |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
{ |
432
|
32
|
|
|
|
|
120
|
return ($node,"LEFT"); |
433
|
|
|
|
|
|
|
} |
434
|
|
|
|
|
|
|
|
435
|
74
|
100
|
66
|
|
|
216
|
if ( |
|
|
|
100
|
|
|
|
|
436
|
|
|
|
|
|
|
(blessed($node->getRightEdge)) && ($node->getRightEdge->isa('Lingua::YaTeA::TermLeaf')) |
437
|
|
|
|
|
|
|
&& |
438
|
|
|
|
|
|
|
($node->getRightEdge->getIndex == $pivot) |
439
|
|
|
|
|
|
|
) |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
{ |
442
|
29
|
|
|
|
|
126
|
return ($node,"RIGHT"); |
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
} |
445
|
|
|
|
|
|
|
|
446
|
0
|
|
|
|
|
0
|
return; |
447
|
|
|
|
|
|
|
} |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
sub addNodes |
452
|
|
|
|
|
|
|
{ |
453
|
63
|
|
|
63
|
1
|
153
|
my ($this,$node_set) = @_; |
454
|
63
|
|
|
|
|
102
|
my $node; |
455
|
63
|
|
|
|
|
105
|
foreach $node (@{$node_set->getNodes}) |
|
63
|
|
|
|
|
154
|
|
456
|
|
|
|
|
|
|
{ |
457
|
67
|
|
|
|
|
161
|
$this->addNode($node); |
458
|
|
|
|
|
|
|
} |
459
|
|
|
|
|
|
|
} |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
sub print |
465
|
|
|
|
|
|
|
{ |
466
|
0
|
|
|
0
|
1
|
0
|
my ($this,$words_a,$fh) = @_; |
467
|
0
|
0
|
|
|
|
0
|
if(scalar @{$this->getNodes} != 0) |
|
0
|
|
|
|
|
0
|
|
468
|
|
|
|
|
|
|
{ |
469
|
0
|
0
|
|
|
|
0
|
if(defined $fh) |
470
|
|
|
|
|
|
|
{ |
471
|
0
|
0
|
|
|
|
0
|
if(defined $this->getRoot) |
472
|
|
|
|
|
|
|
{ |
473
|
0
|
|
|
|
|
0
|
print $fh "ROOT_NODE :" . $this->getRoot->getID . "\n"; |
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
else |
476
|
|
|
|
|
|
|
{ |
477
|
0
|
|
|
|
|
0
|
print $fh "ROOT_NODE :NO ROOT NODE\n"; |
478
|
|
|
|
|
|
|
} |
479
|
0
|
|
|
|
|
0
|
print $fh "NODES : \n"; |
480
|
0
|
|
|
|
|
0
|
$this->getRoot->printRecursively($words_a,$fh); |
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
else |
483
|
|
|
|
|
|
|
{ |
484
|
0
|
0
|
|
|
|
0
|
if(defined $this->getRoot) |
485
|
|
|
|
|
|
|
{ |
486
|
0
|
|
|
|
|
0
|
print "ROOT_NODE :" . $this->getRoot->getID . "\n"; |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
else |
489
|
|
|
|
|
|
|
{ |
490
|
0
|
|
|
|
|
0
|
print "ROOT_NODE :NO ROOT NODE\n"; |
491
|
|
|
|
|
|
|
} |
492
|
0
|
|
|
|
|
0
|
print "NODES : \n"; |
493
|
0
|
|
|
|
|
0
|
$this->getRoot->printRecursively($words_a); |
494
|
|
|
|
|
|
|
} |
495
|
|
|
|
|
|
|
} |
496
|
|
|
|
|
|
|
else |
497
|
|
|
|
|
|
|
{ |
498
|
0
|
0
|
|
|
|
0
|
if(defined $fh) |
499
|
|
|
|
|
|
|
{ |
500
|
0
|
|
|
|
|
0
|
print $fh "NodeSet is empty\n"; |
501
|
|
|
|
|
|
|
} |
502
|
|
|
|
|
|
|
else |
503
|
|
|
|
|
|
|
{ |
504
|
0
|
|
|
|
|
0
|
print "NodeSet is empty\n"; |
505
|
|
|
|
|
|
|
} |
506
|
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
sub printAllNodes |
511
|
|
|
|
|
|
|
{ |
512
|
0
|
|
|
0
|
1
|
0
|
my ($this,$words_a,$fh) = @_; |
513
|
0
|
|
|
|
|
0
|
my $node; |
514
|
0
|
0
|
|
|
|
0
|
if(!defined $fh) |
515
|
|
|
|
|
|
|
{ |
516
|
0
|
|
|
|
|
0
|
$fh = \*STDERR; |
517
|
|
|
|
|
|
|
} |
518
|
0
|
0
|
|
|
|
0
|
if(defined $this->getRoot) |
519
|
|
|
|
|
|
|
{ |
520
|
0
|
|
|
|
|
0
|
print $fh "ROOT_NODE :" . $this->getRoot->getID . "\n"; |
521
|
|
|
|
|
|
|
} |
522
|
|
|
|
|
|
|
else |
523
|
|
|
|
|
|
|
{ |
524
|
0
|
|
|
|
|
0
|
print $fh "ROOT_NODE :NO ROOT NODE\n"; |
525
|
|
|
|
|
|
|
} |
526
|
0
|
|
|
|
|
0
|
print $fh "NODES : \n"; |
527
|
|
|
|
|
|
|
|
528
|
0
|
|
|
|
|
0
|
foreach $node (@{$this->getNodes}) |
|
0
|
|
|
|
|
0
|
|
529
|
|
|
|
|
|
|
{ |
530
|
0
|
|
|
|
|
0
|
$node->printSimple($words_a,$fh); |
531
|
|
|
|
|
|
|
} |
532
|
0
|
|
|
|
|
0
|
print $fh "\n"; |
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
sub printParenthesised |
537
|
|
|
|
|
|
|
{ |
538
|
45
|
|
|
45
|
1
|
82
|
my ($this,$words_a,$fh) = @_; |
539
|
45
|
|
|
|
|
68
|
my $analysis = ""; |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
# print STDERR $this->getRoot; |
542
|
45
|
50
|
|
|
|
103
|
if(defined $fh) |
543
|
|
|
|
|
|
|
{ |
544
|
45
|
|
|
|
|
100
|
$this->getRoot->buildParenthesised(\$analysis,$words_a); |
545
|
45
|
|
|
|
|
263
|
print $fh $analysis . "\n"; |
546
|
|
|
|
|
|
|
} |
547
|
|
|
|
|
|
|
else |
548
|
|
|
|
|
|
|
{ |
549
|
0
|
|
|
|
|
0
|
$this->getRoot->buildParenthesised(\$analysis,$words_a); |
550
|
0
|
|
|
|
|
0
|
print $analysis . "\n"; |
551
|
|
|
|
|
|
|
} |
552
|
|
|
|
|
|
|
} |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
sub searchRootNodeForLeaf |
555
|
|
|
|
|
|
|
{ |
556
|
61
|
|
|
61
|
1
|
136
|
my ($this,$index) = @_; |
557
|
61
|
|
|
|
|
210
|
my ($node,$place) = $this->getNodeWithPivot($index); |
558
|
61
|
50
|
|
|
|
166
|
if (defined $node) { |
559
|
61
|
|
|
|
|
231
|
return $node->searchRoot; |
560
|
|
|
|
|
|
|
} else { |
561
|
0
|
|
|
|
|
|
return ; |
562
|
|
|
|
|
|
|
} |
563
|
|
|
|
|
|
|
} |
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
sub fillIndexSet |
566
|
|
|
|
|
|
|
{ |
567
|
0
|
|
|
0
|
1
|
|
my ($this,$index_set) = @_; |
568
|
0
|
|
|
|
|
|
my $node; |
569
|
|
|
|
|
|
|
|
570
|
0
|
|
|
|
|
|
foreach $node (@{$this->getNodes}) |
|
0
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
{ |
572
|
0
|
0
|
0
|
|
|
|
if ((blessed($node)) && ($node->isa('Lingua::YaTeA::RootNode'))) |
573
|
|
|
|
|
|
|
{ |
574
|
0
|
|
|
|
|
|
$node->fillIndexSet($index_set); |
575
|
|
|
|
|
|
|
} |
576
|
|
|
|
|
|
|
} |
577
|
0
|
|
|
|
|
|
$index_set->removeDoubles; |
578
|
|
|
|
|
|
|
} |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
sub searchHeads |
581
|
|
|
|
|
|
|
{ |
582
|
0
|
|
|
0
|
1
|
|
my ($this,$words_a) = @_; |
583
|
0
|
|
|
|
|
|
my %heads; |
584
|
|
|
|
|
|
|
my $root; |
585
|
0
|
|
|
|
|
|
my $root_head; |
586
|
0
|
|
|
|
|
|
my $free_nodes_a = $this->searchFreeNodes($words_a); |
587
|
|
|
|
|
|
|
|
588
|
0
|
|
|
|
|
|
foreach $root (@$free_nodes_a) |
589
|
|
|
|
|
|
|
{ |
590
|
0
|
|
|
|
|
|
$root_head = $root->searchHead(0); |
591
|
0
|
0
|
0
|
|
|
|
if ((defined $root_head)&&((blessed($root_head)) && ($root_head->isa('Lingua::YaTeA::TermLeaf')))) { |
|
|
|
0
|
|
|
|
|
592
|
0
|
|
|
|
|
|
$heads{$root_head->getIndex}++; |
593
|
|
|
|
|
|
|
} |
594
|
|
|
|
|
|
|
} |
595
|
0
|
|
|
|
|
|
return \%heads; |
596
|
|
|
|
|
|
|
} |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
1; |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
__END__ |