line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::Ogmios::Annotations::Level; |
2
|
|
|
|
|
|
|
|
3
|
16
|
|
|
16
|
|
71
|
use strict; |
|
16
|
|
|
|
|
26
|
|
|
16
|
|
|
|
|
344
|
|
4
|
16
|
|
|
16
|
|
68
|
use warnings; |
|
16
|
|
|
|
|
26
|
|
|
16
|
|
|
|
|
72910
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
0
|
|
|
0
|
0
|
|
my ($class, $fields) = @_; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# if (defined $fields) { |
10
|
|
|
|
|
|
|
# TO UNCOMMENT LATER |
11
|
|
|
|
|
|
|
# if (!defined($fields->{'XML_order'})) { |
12
|
|
|
|
|
|
|
# die 'No XML order defined'; |
13
|
|
|
|
|
|
|
# } |
14
|
|
|
|
|
|
|
# } |
15
|
|
|
|
|
|
|
# if (!defined($fields->{'name'})) { |
16
|
|
|
|
|
|
|
# die 'name order defined'; |
17
|
|
|
|
|
|
|
# } |
18
|
|
|
|
|
|
|
# } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $level = { |
21
|
0
|
|
|
|
|
|
'name' => $fields->{'name'}, |
22
|
|
|
|
|
|
|
'id' => 0, |
23
|
|
|
|
|
|
|
'log_id' => -1, |
24
|
|
|
|
|
|
|
'comments' => undef, |
25
|
|
|
|
|
|
|
'elements' => [], |
26
|
|
|
|
|
|
|
'indexfields' => ['id', 'token'], |
27
|
|
|
|
|
|
|
'indexes' => {'id' => {}, 'token' => {}}, |
28
|
|
|
|
|
|
|
'XML_order' => [], |
29
|
|
|
|
|
|
|
}; |
30
|
0
|
|
|
|
|
|
bless $level, $class; |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
if (defined $fields) { |
33
|
0
|
0
|
|
|
|
|
if (defined $fields->{'indexes'}) { |
34
|
0
|
|
|
|
|
|
$level->addIndex($fields->{'indexes'}); |
35
|
|
|
|
|
|
|
} |
36
|
0
|
0
|
|
|
|
|
if (defined($fields->{'XML_order'})) { |
37
|
0
|
|
|
|
|
|
$level->setXMLorder($fields->{'XML_order'}); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
|
return $level; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub setName { |
46
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$self->{'name'} = $name; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub getName { |
52
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return($self->{'name'}); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub setXMLorder { |
58
|
0
|
|
|
0
|
0
|
|
my ($self, $xml_order) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
push @{$self->getXMLorder}, @$xml_order; |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub getXMLorder { |
65
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return($self->{'XML_order'}); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub resetIndexes { |
72
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
73
|
0
|
|
|
|
|
|
my $field; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
foreach $field (@{$self->getIndexfields}) { |
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$self->getIndexes->{$field} = {}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub getIndexfields { |
81
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return($self->{indexfields}); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub getIndexes { |
87
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return($self->{'indexes'}); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub getElement { |
93
|
0
|
|
|
0
|
0
|
|
my ($self, $id) = @_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return($self->getIndexes->{'id'}->{$id}); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub existsElement { |
99
|
0
|
|
|
0
|
0
|
|
my ($self, $id) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return(exists($self->getIndexes->{'id'}->{$id})); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub getElementFromIndex { |
105
|
0
|
|
|
0
|
0
|
|
my ($self, $indexfield, $id) = @_; |
106
|
0
|
|
|
|
|
|
my $element; |
107
|
|
|
|
|
|
|
my %elements; |
108
|
0
|
|
|
|
|
|
my @elts; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# return($self->getIndexes->{$indexfield}->{$id}); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# warn "$indexfield : $id\n"; |
113
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
if ($self->existsElementFromIndex($indexfield,$id)) { |
115
|
0
|
|
|
|
|
|
foreach $element (@{$self->getIndexes->{$indexfield}->{$id}}) { |
|
0
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# warn $element->getId . "\n"; |
117
|
0
|
|
|
|
|
|
$elements{$element->getId} = $element; |
118
|
|
|
|
|
|
|
} |
119
|
0
|
|
|
|
|
|
@elts = values(%elements); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# warn join(" : ", @elts) . "\n"; |
122
|
|
|
|
|
|
|
} |
123
|
0
|
|
|
|
|
|
return(\@elts); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub getElementFromIndex2 { |
127
|
0
|
|
|
0
|
0
|
|
my ($self, $indexfield, $searchedElement) = @_; |
128
|
0
|
|
|
|
|
|
my $element; |
129
|
|
|
|
|
|
|
my %elements; |
130
|
0
|
|
|
|
|
|
my @elts; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# return($self->getIndexes->{$indexfield}->{$id}); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# warn "$indexfield : $searchedElement " . $searchedElement->getId . "\n"; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
foreach $element (@{$self->getIndexes->{$indexfield}->{$searchedElement->getId}}) { |
|
0
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# warn ref($element) . "\n"; |
138
|
|
|
|
|
|
|
# warn "\t" . ref($element->_getField($indexfield)->{$element->_getField($indexfield)->{"reference"}}->[0]) . "\n"; |
139
|
0
|
0
|
|
|
|
|
if (ref($searchedElement) eq ref($element->_getField($indexfield)->{$element->_getField($indexfield)->{"reference"}}->[0])) { |
140
|
0
|
|
|
|
|
|
$elements{$element->getId} = $element; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
0
|
|
|
|
|
|
@elts = values(%elements); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# warn join(" : ", @elts) . "\n";; |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
return(\@elts); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub existsElementFromIndex { |
151
|
0
|
|
|
0
|
0
|
|
my ($self, $indexfield, $id) = @_; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
return(exists($self->getIndexes->{$indexfield}->{$id})); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub existsElementFromIndex2 { |
158
|
0
|
|
|
0
|
0
|
|
my ($self, $indexfield, $searchedElement) = @_; |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
0
|
|
|
|
return((exists($self->getIndexes->{$indexfield}->{$searchedElement->getId})) && (ref($searchedElement) eq ref($self->getIndexes->{$indexfield}->{$searchedElement->getId}))); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub existsElementFromReference { |
165
|
0
|
|
|
0
|
0
|
|
my ($self, $element) = @_; |
166
|
|
|
|
|
|
|
|
167
|
0
|
0
|
|
|
|
|
if (exists $element->{'reference'}) { |
168
|
0
|
|
|
|
|
|
my @ref = @{$element->getReference}; |
|
0
|
|
|
|
|
|
|
169
|
0
|
0
|
|
|
|
|
if ($self->existsElementFromIndex("list_refid_token", $ref[0]->getId)) { |
170
|
0
|
|
|
|
|
|
my $ne = $self->getElementFromIndex("list_refid_token", $ref[0]->getId)->[0]; |
171
|
0
|
|
|
|
|
|
my @ref_ne = @{$ne->getReference}; |
|
0
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
my $i = 0; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
0
|
|
|
|
while(($i < scalar(@{$ne->getReference})) && ($i < scalar(@ref)) && |
|
0
|
|
0
|
|
|
|
|
175
|
|
|
|
|
|
|
($ref_ne[$i]->equals($ref[$i]))) { |
176
|
0
|
|
|
|
|
|
$i++ |
177
|
|
|
|
|
|
|
}; |
178
|
0
|
0
|
|
|
|
|
if ($i < scalar(@ref)) { |
179
|
0
|
|
|
|
|
|
return(0); |
180
|
|
|
|
|
|
|
} else { |
181
|
0
|
|
|
|
|
|
return(1); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# return(exists($self->getIndexes->{$indexfield}->{$id})); |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub printIndex { |
194
|
0
|
|
|
0
|
0
|
|
my ($self, $indexfield, $fh) = @_; |
195
|
0
|
0
|
|
|
|
|
if (!defined $fh) { |
196
|
0
|
|
|
|
|
|
$fh = \*STDERR |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
my $elt; |
200
|
|
|
|
|
|
|
my $idx; |
201
|
0
|
|
|
|
|
|
my $item; |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
foreach $idx (keys %{$self->getIndex($indexfield)}) { |
|
0
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
print $fh "$idx:\n"; |
205
|
0
|
|
|
|
|
|
print $fh "\t" . $self->getIndex($indexfield)->{$idx} . "\n"; |
206
|
0
|
0
|
|
|
|
|
if (ref($self->getIndex($indexfield)->{$idx}) eq "ARRAY") { |
207
|
0
|
|
|
|
|
|
foreach $item (@{$self->getIndex($indexfield)->{$idx}}) { |
|
0
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
print $fh "\t (" . ref($item) . ") " . $item->getId . "\n"; |
209
|
|
|
|
|
|
|
# print $fh "\t (" . ref($item) . ") " . $item->_getField($indexfield) . " : " . $item->getForm . "\n"; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
} else { |
212
|
0
|
|
|
|
|
|
print $fh "\t (" . ref($item) . ") " . $self->getIndex($indexfield)->{$idx}->getId . "\n"; |
213
|
|
|
|
|
|
|
# print $fh "\t (" . ref($item) . ") " . $self->getIndex($indexfield)->{$idx}->_getField($indexfield) . " : " . $item->getForm . "\n"; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
0
|
|
|
|
|
|
return(0); |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub getIndex { |
220
|
0
|
|
|
0
|
0
|
|
my ($self, $indexfield) = @_; |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
return($self->getIndexes->{$indexfield}); |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub existsIndex{ |
226
|
0
|
|
|
0
|
0
|
|
my ($self, $indexfield) = @_; |
227
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
|
return(exists $self->getIndexes->{$indexfield}); |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
# check if the method as to be generalized |
232
|
|
|
|
|
|
|
sub addComponentToList { |
233
|
0
|
|
|
0
|
0
|
|
my ($self, $element, $component) = @_; |
234
|
|
|
|
|
|
|
|
235
|
0
|
0
|
|
|
|
|
if (exists $self->getIndexes->{'list_refid_components'}) { |
236
|
0
|
|
|
|
|
|
$element->addComponent($component); |
237
|
|
|
|
|
|
|
|
238
|
0
|
0
|
|
|
|
|
if (!exists $self->getIndexes->{'list_refid_components'}->{$component->getId}) { |
239
|
0
|
|
|
|
|
|
$self->getIndexes->{'list_refid_components'}->{$component->getId} = []; |
240
|
|
|
|
|
|
|
} |
241
|
0
|
|
|
|
|
|
push @{$self->getIndexes->{'list_refid_components'}->{$component->getId}}, $element; |
|
0
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
# $self->getIndexes->{'list_refid_components'}->{$component->getId} = $element; |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
sub addElementToIndexes { |
248
|
0
|
|
|
0
|
0
|
|
my ($self, $element) = @_; |
249
|
0
|
|
|
|
|
|
my $field; |
250
|
|
|
|
|
|
|
my $value; |
251
|
0
|
|
|
|
|
|
my $val; |
252
|
0
|
|
|
|
|
|
my $val_element; |
253
|
0
|
|
|
|
|
|
my $component; |
254
|
|
|
|
|
|
|
|
255
|
0
|
|
|
|
|
|
my @indexfields = @{$self->getIndexfields}; |
|
0
|
|
|
|
|
|
|
256
|
0
|
|
|
|
|
|
$field = shift @indexfields; |
257
|
0
|
|
|
|
|
|
$self->getIndexes->{$field}->{$element->getId} = $element; |
258
|
0
|
|
|
|
|
|
$field = shift @indexfields; |
259
|
|
|
|
|
|
|
# warn "== $element\n"; |
260
|
0
|
|
|
|
|
|
$self->addElementToTokenIndex($element); |
261
|
|
|
|
|
|
|
# warn "--\n"; |
262
|
0
|
|
|
|
|
|
foreach $field (@indexfields) { |
263
|
|
|
|
|
|
|
# warn "... ($field)\n"; |
264
|
0
|
|
|
|
|
|
$self->addElementToIndex($element, $field); |
265
|
|
|
|
|
|
|
# warn "+++ ($field)\n"; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
sub addElementToTokenIndex { |
270
|
0
|
|
|
0
|
0
|
|
my ($self, $element) = @_; |
271
|
0
|
|
|
|
|
|
my $ref; |
272
|
|
|
|
|
|
|
my $elt; |
273
|
0
|
|
|
|
|
|
my @refs; |
274
|
0
|
|
|
|
|
|
my $i; |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
# warn "ref: " . ref($element) . "\n"; |
277
|
|
|
|
|
|
|
|
278
|
0
|
0
|
|
|
|
|
if (ref($element) eq "Lingua::Ogmios::Annotations::Token") { |
279
|
0
|
0
|
|
|
|
|
if (! exists $self->getIndex('token')->{$element->getId}) { |
280
|
0
|
|
|
|
|
|
$self->getIndex('token')->{$element->getId} = []; |
281
|
|
|
|
|
|
|
} |
282
|
0
|
|
|
|
|
|
push @{$self->getIndex('token')->{$element->getId}}, $element; |
|
0
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
} else { |
284
|
0
|
|
|
|
|
|
$ref = $element->reference; |
285
|
0
|
0
|
|
|
|
|
if (ref($ref) eq "ARRAY") { |
286
|
0
|
|
|
|
|
|
@refs = @{$ref}; |
|
0
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
} else { |
288
|
0
|
|
|
|
|
|
push @refs, $ref; |
289
|
|
|
|
|
|
|
} |
290
|
0
|
|
|
|
|
|
for($i=0;$i< scalar(@refs);$i++) { |
291
|
0
|
|
|
|
|
|
$elt = $refs[$i]; |
292
|
0
|
0
|
|
|
|
|
if (ref($elt) eq "Lingua::Ogmios::Annotations::Token") { |
293
|
0
|
0
|
|
|
|
|
if (! exists $self->getIndex('token')->{$elt->getId}) { |
294
|
0
|
|
|
|
|
|
$self->getIndex('token')->{$elt->getId} = []; |
295
|
|
|
|
|
|
|
} |
296
|
0
|
|
|
|
|
|
push @{$self->getIndex('token')->{$elt->getId}}, $element; |
|
0
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
} else { |
298
|
0
|
0
|
0
|
|
|
|
if ((ref($elt) eq "Lingua::Ogmios::Annotations::Word") || |
|
|
|
0
|
|
|
|
|
299
|
|
|
|
|
|
|
(ref($elt) eq "Lingua::Ogmios::Annotations::Phrase") || |
300
|
|
|
|
|
|
|
(ref($elt) eq "Lingua::Ogmios::Annotations::SemanticUnit")# || |
301
|
|
|
|
|
|
|
) { |
302
|
0
|
|
|
|
|
|
$ref = $elt->reference; |
303
|
0
|
0
|
|
|
|
|
if (ref($ref) eq "ARRAY") { |
304
|
0
|
|
|
|
|
|
push @refs, @$ref; |
305
|
|
|
|
|
|
|
} else { |
306
|
0
|
|
|
|
|
|
push @refs, $ref; |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
} else { |
309
|
|
|
|
|
|
|
# warn "->$elt\n"; |
310
|
|
|
|
|
|
|
} |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
} |
313
|
|
|
|
|
|
|
# warn join(':', @{$element->reference}) . "\n"; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
sub addElementToIndex { |
318
|
0
|
|
|
0
|
0
|
|
my ($self, $element, $field) = @_; |
319
|
0
|
|
|
|
|
|
my $value; |
320
|
|
|
|
|
|
|
my $val; |
321
|
0
|
|
|
|
|
|
my $val_element; |
322
|
0
|
|
|
|
|
|
my $component; |
323
|
|
|
|
|
|
|
|
324
|
0
|
|
|
|
|
|
$value = $element->_getField($field); |
325
|
|
|
|
|
|
|
# warn "$field\n"; |
326
|
|
|
|
|
|
|
# warn " ($value)\n"; |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
# if (($field eq "type") && (defined $value)) { |
329
|
|
|
|
|
|
|
# warn "$field ($value)\n"; |
330
|
|
|
|
|
|
|
# } |
331
|
0
|
0
|
|
|
|
|
if (defined $value) { |
332
|
0
|
0
|
|
|
|
|
if (ref($value) eq "ARRAY") { |
333
|
0
|
|
|
|
|
|
foreach $val (@$value) { |
334
|
0
|
|
|
|
|
|
$val_element = $val; |
335
|
0
|
0
|
|
|
|
|
if (index(ref($val), "Lingua::Ogmios::Annotations::") == 0) { |
336
|
0
|
|
|
|
|
|
$val_element = $val->getId; |
337
|
|
|
|
|
|
|
} |
338
|
0
|
0
|
|
|
|
|
if (!exists $self->getIndexes->{$field}->{$val_element}) { |
339
|
0
|
|
|
|
|
|
$self->getIndexes->{$field}->{$val_element} = []; |
340
|
|
|
|
|
|
|
} |
341
|
0
|
|
|
|
|
|
push @{$self->getIndexes->{$field}->{$val_element}}, $element; |
|
0
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
} |
343
|
|
|
|
|
|
|
} else { |
344
|
0
|
0
|
|
|
|
|
if (ref($value) eq "HASH") { |
345
|
0
|
|
|
|
|
|
foreach $component (keys %$value) { |
346
|
0
|
0
|
|
|
|
|
if ($component ne "reference") { |
347
|
0
|
|
|
|
|
|
foreach $val (@{$value->{$component}}) { |
|
0
|
|
|
|
|
|
|
348
|
0
|
|
|
|
|
|
$val_element = $val; |
349
|
0
|
0
|
|
|
|
|
if (index(ref($val), "Lingua::Ogmios::Annotations::") == 0) { |
350
|
0
|
|
|
|
|
|
$val_element = $val->getId; |
351
|
|
|
|
|
|
|
} |
352
|
0
|
0
|
|
|
|
|
if (!exists $self->getIndexes->{$field}->{$val_element}) { |
353
|
0
|
|
|
|
|
|
$self->getIndexes->{$field}->{$val_element} = []; |
354
|
|
|
|
|
|
|
} |
355
|
0
|
|
|
|
|
|
push @{$self->getIndexes->{$field}->{$val_element}}, $element; #{$element => $component}; |
|
0
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
} |
357
|
|
|
|
|
|
|
} |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
} else { |
361
|
0
|
|
|
|
|
|
$val_element = $value; |
362
|
0
|
0
|
|
|
|
|
if (index(ref($value), "Lingua::Ogmios::Annotations::") == 0) { |
363
|
0
|
|
|
|
|
|
$val_element = $value->getId; |
364
|
|
|
|
|
|
|
} |
365
|
0
|
0
|
|
|
|
|
if (!exists $self->getIndexes->{$field}->{$val_element}) { |
366
|
0
|
|
|
|
|
|
$self->getIndexes->{$field}->{$val_element} = []; |
367
|
|
|
|
|
|
|
} |
368
|
0
|
|
|
|
|
|
push @{$self->getIndexes->{$field}->{$val_element}}, $element; |
|
0
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
# } else { |
372
|
|
|
|
|
|
|
# warn "undefined field: $field\n"; |
373
|
|
|
|
|
|
|
} |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
sub delElementToIndexes { |
378
|
0
|
|
|
0
|
0
|
|
my ($self, $element) = @_; |
379
|
0
|
|
|
|
|
|
my $field; |
380
|
|
|
|
|
|
|
my $value; |
381
|
0
|
|
|
|
|
|
my $val; |
382
|
0
|
|
|
|
|
|
my $val_element; |
383
|
0
|
|
|
|
|
|
my $component; |
384
|
0
|
|
|
|
|
|
my $i; |
385
|
|
|
|
|
|
|
|
386
|
0
|
|
|
|
|
|
my @indexfields = @{$self->getIndexfields}; |
|
0
|
|
|
|
|
|
|
387
|
0
|
|
|
|
|
|
$field = shift @indexfields; |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
# $value = $element->_getField($field); |
390
|
|
|
|
|
|
|
# print STDERR "$field"; |
391
|
|
|
|
|
|
|
# warn " : $value\n"; |
392
|
|
|
|
|
|
|
|
393
|
0
|
|
|
|
|
|
delete $self->getIndexes->{$field}->{$element->getId}; |
394
|
|
|
|
|
|
|
# $field = shift @indexfields; |
395
|
|
|
|
|
|
|
# $self->delElementToTokenIndex($element); |
396
|
|
|
|
|
|
|
|
397
|
0
|
|
|
|
|
|
foreach $field (@indexfields) { |
398
|
0
|
|
|
|
|
|
$value = $element->_getField($field); |
399
|
|
|
|
|
|
|
# print STDERR "$field"; |
400
|
|
|
|
|
|
|
# warn " : $value\n"; |
401
|
|
|
|
|
|
|
|
402
|
0
|
0
|
|
|
|
|
if (defined $value) { |
403
|
0
|
0
|
|
|
|
|
if (ref($value) eq "ARRAY") { |
404
|
0
|
|
|
|
|
|
foreach $val (@$value) { |
405
|
0
|
|
|
|
|
|
$val_element = $val; |
406
|
0
|
0
|
|
|
|
|
if (index(ref($val), "Lingua::Ogmios::Annotations::") == 0) { |
407
|
0
|
|
|
|
|
|
$val_element = $val->getId; |
408
|
|
|
|
|
|
|
} |
409
|
0
|
|
|
|
|
|
$self->delElementFromIndex($val_element, $field, $element); |
410
|
|
|
|
|
|
|
} |
411
|
|
|
|
|
|
|
} else { |
412
|
0
|
0
|
|
|
|
|
if (ref($value) eq "HASH") { |
413
|
0
|
|
|
|
|
|
$i = 0; |
414
|
0
|
|
|
|
|
|
foreach $component (keys %$value) { |
415
|
0
|
0
|
|
|
|
|
if ($component ne "reference") { |
416
|
0
|
|
|
|
|
|
foreach $val (@{$value->{$component}}) { |
|
0
|
|
|
|
|
|
|
417
|
0
|
|
|
|
|
|
$val_element = $val; |
418
|
0
|
0
|
|
|
|
|
if (index(ref($val), "Lingua::Ogmios::Annotations::") == 0) { |
419
|
0
|
|
|
|
|
|
$val_element = $val->getId; |
420
|
|
|
|
|
|
|
} |
421
|
0
|
|
|
|
|
|
$self->delElementFromIndex($val_element, $component, $element); |
422
|
|
|
|
|
|
|
} |
423
|
|
|
|
|
|
|
} |
424
|
|
|
|
|
|
|
} |
425
|
|
|
|
|
|
|
} else { |
426
|
0
|
|
|
|
|
|
$val_element = $value; |
427
|
0
|
0
|
|
|
|
|
if (index(ref($value), "Lingua::Ogmios::Annotations::") == 0) { |
428
|
0
|
|
|
|
|
|
$val_element = $value->getId; |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
# warn "====> $val_element\n"; |
431
|
|
|
|
|
|
|
|
432
|
0
|
|
|
|
|
|
$self->delElementFromIndex($val_element, $field, $element); |
433
|
|
|
|
|
|
|
} |
434
|
|
|
|
|
|
|
} |
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
} |
437
|
|
|
|
|
|
|
} |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
sub delElementFromIndex { |
440
|
0
|
|
|
0
|
0
|
|
my ($self, $value, $field, $element) = @_; |
441
|
0
|
|
|
|
|
|
my $i; |
442
|
|
|
|
|
|
|
|
443
|
0
|
0
|
|
|
|
|
if (exists $self->getIndexes->{$field}->{$value}) { |
444
|
|
|
|
|
|
|
# warn "--> $field " . join(":", @{$self->getIndexes->{$field}->{$value}}) . "\n"; |
445
|
0
|
|
|
|
|
|
$i = 0; |
446
|
0
|
|
0
|
|
|
|
while(($i < scalar(@{$self->getIndexes->{$field}->{$value}})) && |
|
0
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
(!($self->getIndexes->{$field}->{$value}->[$i]->equals($element)))) { |
448
|
0
|
|
|
|
|
|
$i++; |
449
|
|
|
|
|
|
|
} |
450
|
0
|
0
|
|
|
|
|
if ($i < scalar(@{$self->getIndexes->{$field}->{$value}})) { |
|
0
|
|
|
|
|
|
|
451
|
0
|
|
|
|
|
|
splice(@{$self->getIndexes->{$field}->{$value}}, $i, 1); |
|
0
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
# warn "--del--\n"; |
453
|
|
|
|
|
|
|
} else { |
454
|
|
|
|
|
|
|
# warn "value ($value) not found in $field\n"; |
455
|
|
|
|
|
|
|
} |
456
|
0
|
0
|
|
|
|
|
if (scalar(@{$self->getIndexes->{$field}->{$value}}) == 0) { |
|
0
|
|
|
|
|
|
|
457
|
0
|
|
|
|
|
|
delete $self->getIndexes->{$field}->{$value}; |
458
|
|
|
|
|
|
|
# warn "---del---\n"; |
459
|
|
|
|
|
|
|
} |
460
|
|
|
|
|
|
|
} |
461
|
|
|
|
|
|
|
} |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
sub addIndex { |
465
|
0
|
|
|
0
|
0
|
|
my ($self, $fields) = @_; |
466
|
0
|
|
|
|
|
|
my $field; |
467
|
|
|
|
|
|
|
|
468
|
0
|
|
|
|
|
|
foreach $field (@$fields) { |
469
|
0
|
0
|
|
|
|
|
if (!$self->existsIndex($field)) { |
470
|
0
|
|
|
|
|
|
push @{$self->getIndexfields}, $field; |
|
0
|
|
|
|
|
|
|
471
|
0
|
|
|
|
|
|
$self->getIndexes->{$field} = {}; |
472
|
|
|
|
|
|
|
} |
473
|
|
|
|
|
|
|
} |
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
sub setId { |
477
|
0
|
|
|
0
|
0
|
|
my ($self, $id) = @_; |
478
|
|
|
|
|
|
|
|
479
|
0
|
|
|
|
|
|
$self->{'id'} = $id; |
480
|
|
|
|
|
|
|
} |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
sub setMaxId { |
483
|
0
|
|
|
0
|
0
|
|
my ($self, $id) = @_; |
484
|
|
|
|
|
|
|
|
485
|
0
|
0
|
|
|
|
|
if ($id > $self->getId) { |
486
|
0
|
|
|
|
|
|
$self->setId($id); |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
} |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
sub getId { |
491
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
492
|
|
|
|
|
|
|
|
493
|
0
|
|
|
|
|
|
return($self->{'id'}); |
494
|
|
|
|
|
|
|
} |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
sub incrId { |
497
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
498
|
|
|
|
|
|
|
|
499
|
0
|
|
|
|
|
|
return($self->setId($self->getId + 1)); |
500
|
|
|
|
|
|
|
} |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
sub _decrId { |
503
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
504
|
|
|
|
|
|
|
|
505
|
0
|
|
|
|
|
|
return($self->setId($self->getId - 1)); |
506
|
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
sub getLog_Id { |
509
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
510
|
|
|
|
|
|
|
|
511
|
0
|
|
|
|
|
|
return($self->{'log_id'}); |
512
|
|
|
|
|
|
|
} |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
sub incrLog_Id { |
515
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
516
|
|
|
|
|
|
|
|
517
|
0
|
|
|
|
|
|
return($self->setLog_Id($self->getLog_Id + 1)); |
518
|
|
|
|
|
|
|
} |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
sub _decrLog_Id { |
521
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
522
|
|
|
|
|
|
|
|
523
|
0
|
|
|
|
|
|
return($self->setLog_Id($self->getLog_Id - 1)); |
524
|
|
|
|
|
|
|
} |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
sub resetElements { |
528
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
529
|
0
|
|
|
|
|
|
my $field; |
530
|
|
|
|
|
|
|
|
531
|
0
|
|
|
|
|
|
$self->{'elements'} = []; |
532
|
0
|
|
|
|
|
|
$self->resetIndexes; |
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
sub getElements { |
536
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
537
|
|
|
|
|
|
|
|
538
|
0
|
|
|
|
|
|
return($self->{'elements'}); |
539
|
|
|
|
|
|
|
} |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
sub getSize { |
542
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
543
|
|
|
|
|
|
|
|
544
|
0
|
|
|
|
|
|
return(scalar(@{$self->getElements})); |
|
0
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
} |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
sub getLastElement { |
549
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
550
|
|
|
|
|
|
|
|
551
|
0
|
0
|
|
|
|
|
if ($self->getSize != 0) { |
552
|
0
|
|
|
|
|
|
return($self->getElements->[$#{$self->getElements}]); |
|
0
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
} else { |
554
|
0
|
|
|
|
|
|
return(undef); |
555
|
|
|
|
|
|
|
} |
556
|
|
|
|
|
|
|
# my $elements = $self->getElements; |
557
|
|
|
|
|
|
|
# $element->previous($elements->[$#$elements]); |
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
# $elements->[$#$elements] |
560
|
|
|
|
|
|
|
# return($self->{'elements'}); |
561
|
|
|
|
|
|
|
} |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
sub getFirstElement { |
564
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
565
|
|
|
|
|
|
|
|
566
|
0
|
|
|
|
|
|
my $i = 0; |
567
|
|
|
|
|
|
|
|
568
|
0
|
|
0
|
|
|
|
while(($self->getSize != 0) && (!exists($self->getElements->[$i]))) { $i++; }; |
|
0
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
|
570
|
0
|
0
|
|
|
|
|
if ($self->getSize != 0) { |
571
|
0
|
|
|
|
|
|
return($self->getElements->[$i]); |
572
|
|
|
|
|
|
|
} else { |
573
|
0
|
|
|
|
|
|
return(undef); |
574
|
|
|
|
|
|
|
} |
575
|
|
|
|
|
|
|
# my $elements = $self->getElements; |
576
|
|
|
|
|
|
|
# $element->previous($elements->[$#$elements]); |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
# $elements->[$#$elements] |
579
|
|
|
|
|
|
|
# return($self->{'elements'}); |
580
|
|
|
|
|
|
|
} |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
sub setComments { |
584
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
585
|
|
|
|
|
|
|
|
586
|
0
|
|
|
|
|
|
$self->{'comments'} = {}; |
587
|
|
|
|
|
|
|
} |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
sub getComments { |
590
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
591
|
|
|
|
|
|
|
|
592
|
0
|
|
|
|
|
|
return($self->{'comments'}); |
593
|
|
|
|
|
|
|
} |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
sub replaceElement { |
596
|
0
|
|
|
0
|
0
|
|
my ($self, $oldElement, $newElement) = @_; |
597
|
|
|
|
|
|
|
|
598
|
0
|
|
|
|
|
|
$newElement->setId($oldElement->getId); |
599
|
|
|
|
|
|
|
|
600
|
0
|
|
|
|
|
|
$newElement->previous($oldElement->previous); |
601
|
0
|
0
|
|
|
|
|
if (defined $oldElement->previous) { |
602
|
0
|
|
|
|
|
|
$oldElement->previous->next($newElement); |
603
|
|
|
|
|
|
|
} |
604
|
0
|
|
|
|
|
|
$newElement->next($oldElement->next); |
605
|
0
|
0
|
|
|
|
|
if (defined $oldElement->next) { |
606
|
0
|
|
|
|
|
|
$oldElement->next->previous($newElement); |
607
|
|
|
|
|
|
|
} |
608
|
|
|
|
|
|
|
|
609
|
0
|
|
|
|
|
|
$self->delElementToIndexes($oldElement); |
610
|
0
|
|
|
|
|
|
$self->addElementToIndexes($newElement); |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
# $self->delElement($oldElement); |
613
|
0
|
|
|
|
|
|
$self->addElementToIndexes($newElement); |
614
|
0
|
|
|
|
|
|
$self->delElementToIndexes($oldElement); |
615
|
|
|
|
|
|
|
|
616
|
0
|
|
|
|
|
|
return($newElement->getId); |
617
|
|
|
|
|
|
|
} |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
sub addElement { |
620
|
0
|
|
|
0
|
0
|
|
my ($self, $element) = @_; |
621
|
|
|
|
|
|
|
|
622
|
0
|
|
|
|
|
|
my $id; |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
# warn "++>" . $element->getId . "\n"; |
625
|
0
|
0
|
|
|
|
|
if ($element->getId == -1) { |
626
|
0
|
|
|
|
|
|
$id = $self->incrId; |
627
|
0
|
|
|
|
|
|
$element->setId($id); |
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
} else { |
630
|
0
|
|
|
|
|
|
$id = $element->getId; |
631
|
0
|
|
|
|
|
|
$self->setMaxId($id); |
632
|
|
|
|
|
|
|
# warn "$id already exists (IdElement)\n"; |
633
|
|
|
|
|
|
|
} |
634
|
0
|
0
|
|
|
|
|
if (defined $self->getLastElement) { |
635
|
0
|
|
|
|
|
|
$element->previous($self->getLastElement); |
636
|
0
|
|
|
|
|
|
$self->getLastElement->next($element); |
637
|
|
|
|
|
|
|
} |
638
|
0
|
|
|
|
|
|
push @{$self->getElements}, $element; |
|
0
|
|
|
|
|
|
|
639
|
0
|
|
|
|
|
|
$self->addElementToIndexes($element); |
640
|
0
|
|
|
|
|
|
return($id); |
641
|
|
|
|
|
|
|
} |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
sub delElement { |
644
|
0
|
|
|
0
|
0
|
|
my ($self, $element) = @_; |
645
|
|
|
|
|
|
|
|
646
|
0
|
0
|
|
|
|
|
if (defined $element->previous) { |
647
|
0
|
|
|
|
|
|
$element->previous->next($element->next); |
648
|
|
|
|
|
|
|
} |
649
|
|
|
|
|
|
|
|
650
|
0
|
|
|
|
|
|
my $i = 0; |
651
|
|
|
|
|
|
|
|
652
|
0
|
|
0
|
|
|
|
while(($i < $self->getSize) && ((!defined($self->getElements->[$i])) || (!$self->getElements->[$i]->equals($element)))) { |
|
|
|
0
|
|
|
|
|
653
|
0
|
|
|
|
|
|
$i++; |
654
|
|
|
|
|
|
|
} |
655
|
|
|
|
|
|
|
|
656
|
0
|
0
|
|
|
|
|
if ($i < $self->getSize) { |
657
|
0
|
|
|
|
|
|
splice(@{$self->getElements},$i,1); |
|
0
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
# warn "delElement\n"; |
659
|
0
|
|
|
|
|
|
$self->delElementToIndexes($element); |
660
|
|
|
|
|
|
|
} |
661
|
0
|
|
|
|
|
|
return($element->getId); |
662
|
|
|
|
|
|
|
} |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
sub changeRefFromIndexField { |
665
|
0
|
|
|
0
|
0
|
|
my ($self, $indexfield, $oldvalue, $newvalue) = @_; |
666
|
0
|
|
|
|
|
|
my $section; |
667
|
|
|
|
|
|
|
|
668
|
0
|
|
|
|
|
|
foreach $section (@{$self->getElementFromIndex($indexfield, $oldvalue)}) { |
|
0
|
|
|
|
|
|
|
669
|
0
|
|
|
|
|
|
$section->_setField($indexfield, $newvalue); |
670
|
|
|
|
|
|
|
} |
671
|
|
|
|
|
|
|
} |
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
sub resetIndex { |
674
|
0
|
|
|
0
|
0
|
|
my ($self, $indexfield) = @_; |
675
|
|
|
|
|
|
|
|
676
|
0
|
|
|
|
|
|
$self->getIndexes->{$indexfield} = {}; |
677
|
|
|
|
|
|
|
} |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
sub rebuildIndex { |
680
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
681
|
|
|
|
|
|
|
|
682
|
0
|
|
|
|
|
|
my $element; |
683
|
|
|
|
|
|
|
my $field; |
684
|
0
|
|
|
|
|
|
my $value; |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
# warn "rebuild Index\n"; |
687
|
0
|
|
|
|
|
|
my @indexfields = @{$self->getIndexfields}; |
|
0
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
# shift @indexfields; |
689
|
|
|
|
|
|
|
# $field = shift @indexfields; |
690
|
|
|
|
|
|
|
# $self->getIndexes->{$field}->{$element->getId} = $element; |
691
|
0
|
|
|
|
|
|
foreach $field (@indexfields) { |
692
|
0
|
|
|
|
|
|
$self->resetIndex($field); |
693
|
|
|
|
|
|
|
# warn "field: $field\n"; |
694
|
0
|
|
|
|
|
|
foreach $element (@{$self->getElements}) { |
|
0
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
# warn "element: $element\n"; |
696
|
0
|
|
|
|
|
|
$self->addElementToIndexes($element); |
697
|
|
|
|
|
|
|
# $value = $element->_getField($field); |
698
|
|
|
|
|
|
|
# if (!exists $self->getIndexes->{$field}->{$value}) { |
699
|
|
|
|
|
|
|
# $self->getIndexes->{$field}->{$value} = []; |
700
|
|
|
|
|
|
|
# } |
701
|
|
|
|
|
|
|
# push @{$self->getIndexes->{$field}->{$value}}, $element; |
702
|
|
|
|
|
|
|
} |
703
|
|
|
|
|
|
|
} |
704
|
|
|
|
|
|
|
} |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
sub printXML { |
707
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
708
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
} |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
sub XMLout { |
713
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
714
|
|
|
|
|
|
|
|
715
|
0
|
|
|
|
|
|
my $element; |
716
|
0
|
|
|
|
|
|
my $name = $self->getName; |
717
|
0
|
|
|
|
|
|
my $order = $self->getXMLorder; |
718
|
0
|
|
|
|
|
|
my $str; |
719
|
|
|
|
|
|
|
|
720
|
0
|
|
|
|
|
|
$str = " <$name" . "_level>\n"; |
721
|
0
|
|
|
|
|
|
foreach $element (@{$self->getElements}) { |
|
0
|
|
|
|
|
|
|
722
|
0
|
|
|
|
|
|
$str .= $element->XMLout($order); |
723
|
|
|
|
|
|
|
} |
724
|
0
|
|
|
|
|
|
$str .= " $name" . "_level>\n"; |
725
|
|
|
|
|
|
|
} |
726
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
# sub getElementFromIndex { |
728
|
|
|
|
|
|
|
# my ($self, $indexfield, $id) = @_; |
729
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
sub startsWith { |
731
|
0
|
|
|
0
|
0
|
|
my ($self, $element) = @_; |
732
|
|
|
|
|
|
|
|
733
|
0
|
0
|
|
|
|
|
if (exists $self->getIndex('from')->{$element->getFrom}) { |
734
|
0
|
|
|
|
|
|
return(1); |
735
|
|
|
|
|
|
|
} else { |
736
|
0
|
|
|
|
|
|
return(0); |
737
|
|
|
|
|
|
|
} |
738
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
} |
740
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
sub endsWith { |
742
|
0
|
|
|
0
|
0
|
|
my ($self, $element) = @_; |
743
|
|
|
|
|
|
|
|
744
|
0
|
0
|
|
|
|
|
if (exists $self->getIndex('to')->{$element->getTo}) { |
745
|
0
|
|
|
|
|
|
return(1); |
746
|
|
|
|
|
|
|
} else { |
747
|
0
|
|
|
|
|
|
return(0); |
748
|
|
|
|
|
|
|
} |
749
|
|
|
|
|
|
|
} |
750
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
sub existsElementByToken { |
752
|
0
|
|
|
0
|
0
|
|
my ($self, $token) = @_; |
753
|
|
|
|
|
|
|
|
754
|
0
|
|
|
|
|
|
return(exists($self->getIndex('token')->{$token->getId})); |
755
|
|
|
|
|
|
|
} |
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
sub getElementByToken { |
758
|
0
|
|
|
0
|
0
|
|
my ($self, $token) = @_; |
759
|
|
|
|
|
|
|
|
760
|
0
|
|
|
|
|
|
my @refs; |
761
|
0
|
|
|
|
|
|
my $elt = $self->getIndex('token')->{$token->getId}; |
762
|
0
|
0
|
|
|
|
|
if (defined $elt) { |
763
|
0
|
|
|
|
|
|
return($elt); |
764
|
|
|
|
|
|
|
} else { |
765
|
0
|
|
|
|
|
|
return([]); |
766
|
|
|
|
|
|
|
} |
767
|
|
|
|
|
|
|
# push @refs, $self->getIndex('token')->{$token->getId}; |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
# warn scalar(@refs) . "\n"; |
770
|
|
|
|
|
|
|
|
771
|
|
|
|
|
|
|
# return(\@refs); |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
# return($self->getElementByOffset($token->getFrom)); |
774
|
|
|
|
|
|
|
} |
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
sub getElementByToken1 { |
777
|
0
|
|
|
0
|
0
|
|
my ($self, $token) = @_; |
778
|
|
|
|
|
|
|
|
779
|
|
|
|
|
|
|
# if (exists $self->getElements->[0]->{'reference'}) { |
780
|
|
|
|
|
|
|
# # TODO |
781
|
|
|
|
|
|
|
# } else { |
782
|
|
|
|
|
|
|
# $selt->getElements |
783
|
|
|
|
|
|
|
# warn "Search $token in ($self)\n"; |
784
|
0
|
|
|
|
|
|
return($self->getElementByOffset($token->getFrom)); |
785
|
|
|
|
|
|
|
# } |
786
|
|
|
|
|
|
|
} |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
# this method has to be rewriten correctly |
789
|
|
|
|
|
|
|
sub getElementByOffset { |
790
|
0
|
|
|
0
|
0
|
|
my ($self, $offset) = @_; |
791
|
|
|
|
|
|
|
|
792
|
0
|
|
|
|
|
|
my $element; |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
my $fromOffset; |
795
|
0
|
|
|
|
|
|
my $from; |
796
|
0
|
|
|
|
|
|
my $toOffset; |
797
|
0
|
|
|
|
|
|
my $to; |
798
|
|
|
|
|
|
|
|
799
|
0
|
|
|
|
|
|
my @elements; |
800
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
# warn "Search $offset in ($self)\n"; |
802
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
|
804
|
0
|
|
|
|
|
|
foreach $element (@{$self->getElements}) { |
|
0
|
|
|
|
|
|
|
805
|
|
|
|
|
|
|
# warn "==> $element\n"; |
806
|
0
|
0
|
|
|
|
|
if (defined $element) { |
807
|
0
|
0
|
0
|
|
|
|
if ((defined $element->{'reference'}) || (defined $element->{'list_refid_components'})){ |
808
|
0
|
|
|
|
|
|
$from = $element->start_token; |
809
|
0
|
|
|
|
|
|
$to = $element->end_token; |
810
|
|
|
|
|
|
|
# warn "go1\n"; |
811
|
|
|
|
|
|
|
} else { |
812
|
0
|
0
|
|
|
|
|
if (defined $element->{'refid_start_token'}) { |
813
|
|
|
|
|
|
|
# warn "go2\n"; |
814
|
0
|
|
|
|
|
|
$from = $element->refid_start_token; |
815
|
0
|
|
|
|
|
|
$to = $element->refid_end_token; |
816
|
|
|
|
|
|
|
|
817
|
|
|
|
|
|
|
} else { |
818
|
0
|
|
|
|
|
|
$from = $element->getFrom; |
819
|
0
|
|
|
|
|
|
$to = $element->getTo; |
820
|
|
|
|
|
|
|
} |
821
|
|
|
|
|
|
|
} |
822
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
# warn "ref($from) : " . ref($from) . ";\n"; |
824
|
0
|
0
|
|
|
|
|
if (ref($from) eq "") { |
825
|
0
|
|
|
|
|
|
$fromOffset = $from; |
826
|
|
|
|
|
|
|
} else { |
827
|
0
|
|
|
|
|
|
$fromOffset = $from->getFrom; |
828
|
|
|
|
|
|
|
} |
829
|
|
|
|
|
|
|
# warn "ref($to) : " . ref($to) . "\n"; |
830
|
0
|
0
|
|
|
|
|
if (ref($to) eq "") { |
831
|
0
|
|
|
|
|
|
$toOffset = $to; |
832
|
|
|
|
|
|
|
} else { |
833
|
0
|
|
|
|
|
|
$toOffset = $to->getTo; |
834
|
|
|
|
|
|
|
} |
835
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
# warn "\tfrom $fromOffset to $toOffset\n"; |
837
|
0
|
0
|
0
|
|
|
|
if (($fromOffset <= $offset) && ($offset <= $toOffset)) { |
838
|
|
|
|
|
|
|
# warn "$offset is in the element " . $element->getId . " / " . $element->getForm . "\n"; |
839
|
|
|
|
|
|
|
# warn "$offset is in the element " . $element->getId . "\n"; |
840
|
0
|
|
|
|
|
|
push @elements, $element; |
841
|
|
|
|
|
|
|
} |
842
|
|
|
|
|
|
|
} |
843
|
|
|
|
|
|
|
} |
844
|
|
|
|
|
|
|
# warn "===================\n"; |
845
|
0
|
|
|
|
|
|
return(\@elements); |
846
|
|
|
|
|
|
|
} |
847
|
|
|
|
|
|
|
|
848
|
|
|
|
|
|
|
sub getElementById { |
849
|
0
|
|
|
0
|
0
|
|
my ($self, $id) = @_; |
850
|
|
|
|
|
|
|
|
851
|
0
|
|
|
|
|
|
return($self->getElement($id)); |
852
|
|
|
|
|
|
|
} |
853
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
sub contains { |
855
|
0
|
|
|
0
|
0
|
|
my ($self, $element) = @_; |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
# warn "------------------------------------------------------------------------\n"; |
858
|
|
|
|
|
|
|
# warn $element->getForm . "\n"; |
859
|
0
|
|
|
|
|
|
my $levelElement; |
860
|
0
|
|
|
|
|
|
my $token = $element->start_token; |
861
|
0
|
|
|
|
|
|
my $offset = $token->getFrom; |
862
|
|
|
|
|
|
|
# warn "\t$offset\n\n"; |
863
|
|
|
|
|
|
|
|
864
|
0
|
|
|
|
|
|
foreach $levelElement (@{$self->getElements}) { |
|
0
|
|
|
|
|
|
|
865
|
|
|
|
|
|
|
# warn "$levelElement\n"; |
866
|
|
|
|
|
|
|
# warn "\t" . $levelElement->start_token->getFrom . "\n"; |
867
|
|
|
|
|
|
|
# warn "\t" . $levelElement->end_token->getTo . "\n"; |
868
|
0
|
0
|
0
|
|
|
|
if (($levelElement->start_token->getFrom <= $offset) && |
869
|
|
|
|
|
|
|
($offset <= $levelElement->end_token->getTo)) { |
870
|
|
|
|
|
|
|
# warn "OK\n"; |
871
|
0
|
|
|
|
|
|
return($levelElement); |
872
|
|
|
|
|
|
|
} |
873
|
|
|
|
|
|
|
} |
874
|
0
|
|
|
|
|
|
return(undef); |
875
|
|
|
|
|
|
|
} |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
sub getElementsBetweenStartEndTokens { |
878
|
0
|
|
|
0
|
0
|
|
my ($self, $start_token, $end_token) = @_; |
879
|
|
|
|
|
|
|
|
880
|
0
|
|
|
|
|
|
my $token = $start_token; |
881
|
0
|
|
|
|
|
|
my %semFs; |
882
|
|
|
|
|
|
|
my $elt; |
883
|
|
|
|
|
|
|
|
884
|
0
|
|
|
|
|
|
foreach $elt (@{$self->getElementByToken($token)}) { |
|
0
|
|
|
|
|
|
|
885
|
0
|
|
|
|
|
|
$semFs{$elt->getId} = $elt; |
886
|
|
|
|
|
|
|
# warn $elt->getId . "\n"; |
887
|
|
|
|
|
|
|
} |
888
|
|
|
|
|
|
|
|
889
|
0
|
|
0
|
|
|
|
while ((defined $token) && (!($token->equals($end_token)))) { |
890
|
0
|
|
|
|
|
|
$token = $token->next; |
891
|
0
|
0
|
|
|
|
|
if (defined $token) { |
892
|
0
|
|
|
|
|
|
foreach $elt (@{$self->getElementByToken($token)}) { |
|
0
|
|
|
|
|
|
|
893
|
0
|
|
|
|
|
|
$semFs{$elt->getId} = $elt; |
894
|
|
|
|
|
|
|
# warn $elt->getId . "\n"; |
895
|
|
|
|
|
|
|
} |
896
|
|
|
|
|
|
|
} |
897
|
|
|
|
|
|
|
} |
898
|
|
|
|
|
|
|
|
899
|
0
|
|
|
|
|
|
return(values(%semFs)); |
900
|
|
|
|
|
|
|
} |
901
|
|
|
|
|
|
|
|
902
|
|
|
|
|
|
|
sub getElementByStartEndTokens { |
903
|
0
|
|
|
0
|
0
|
|
my ($self, $start_token, $end_token) = @_; |
904
|
|
|
|
|
|
|
|
905
|
0
|
|
|
|
|
|
my $term; |
906
|
|
|
|
|
|
|
my @terms; |
907
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
# warn "$start_token: " . $start_token->getId . "\n"; |
909
|
0
|
|
|
|
|
|
foreach $term (@{$self->getElementByToken($start_token)}) { |
|
0
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
# warn "$term\n"; |
911
|
0
|
0
|
0
|
|
|
|
if (($term->start_token->equals($start_token)) && ($term->end_token->equals($end_token))) { |
912
|
0
|
|
|
|
|
|
push @terms, $term; |
913
|
|
|
|
|
|
|
} |
914
|
|
|
|
|
|
|
} |
915
|
0
|
0
|
|
|
|
|
if (scalar(@terms) > 0) { |
916
|
0
|
|
|
|
|
|
return($terms[0]); |
917
|
|
|
|
|
|
|
} else { |
918
|
0
|
|
|
|
|
|
return(undef); |
919
|
|
|
|
|
|
|
} |
920
|
|
|
|
|
|
|
} |
921
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
|
923
|
|
|
|
|
|
|
sub existsElementByStartEndTokens { |
924
|
0
|
|
|
0
|
0
|
|
my ($self, $start_token, $end_token) = @_; |
925
|
|
|
|
|
|
|
|
926
|
0
|
|
|
|
|
|
my $term; |
927
|
|
|
|
|
|
|
my @terms; |
928
|
|
|
|
|
|
|
|
929
|
|
|
|
|
|
|
# warn "$start_token: " . $start_token->getId . "\n"; |
930
|
0
|
|
|
|
|
|
foreach $term (@{$self->getElementByToken($start_token)}) { |
|
0
|
|
|
|
|
|
|
931
|
|
|
|
|
|
|
# warn "$term\n"; |
932
|
0
|
0
|
0
|
|
|
|
if (($term->start_token->equals($start_token)) && ($term->end_token->equals($end_token))) { |
933
|
0
|
|
|
|
|
|
push @terms, $term; |
934
|
|
|
|
|
|
|
} |
935
|
|
|
|
|
|
|
} |
936
|
0
|
|
|
|
|
|
return(scalar(@terms) > 0); |
937
|
|
|
|
|
|
|
} |
938
|
|
|
|
|
|
|
|
939
|
|
|
|
|
|
|
sub getElementsByStartToken { |
940
|
0
|
|
|
0
|
0
|
|
my ($self, $start_token) = @_; |
941
|
|
|
|
|
|
|
|
942
|
0
|
|
|
|
|
|
my $term; |
943
|
|
|
|
|
|
|
my @terms; |
944
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
# warn "$start_token: " . $start_token->getId . "\n"; |
946
|
0
|
|
|
|
|
|
foreach $term (@{$self->getElementByToken($start_token)}) { |
|
0
|
|
|
|
|
|
|
947
|
|
|
|
|
|
|
# warn "$term\n"; |
948
|
0
|
0
|
|
|
|
|
if ($term->start_token->equals($start_token)) { |
949
|
0
|
|
|
|
|
|
push @terms, $term; |
950
|
|
|
|
|
|
|
} |
951
|
|
|
|
|
|
|
} |
952
|
0
|
|
|
|
|
|
return(\@terms); |
953
|
|
|
|
|
|
|
} |
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
1; |
956
|
|
|
|
|
|
|
|
957
|
|
|
|
|
|
|
__END__ |