blib/lib/Lingua/Ogmios/DocumentRecord.pm

filter: Statementstmt 58.1% 150 / 258 Branchbran 33.7% 27 / 80 Conditioncond 54.1% 13 / 24 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 88.8% 16 / 18 Podpod 0.0% 0 / 11 totaltotal 52.2% 210 / 402 CC 52 SCAR 47.2
CC
52
Cov
52%
tokenisation2
380.0
computeSectionFromToken
29.8
tokenisation
12.6
CRAP 112.7
« blib/lib/Lingua/Ogmios/NLPWrappers/UKWordSegmentizer.pm ↑ Summary blib/lib/Lingua/Ogmios/NLPWrappers/SectionIdentification.pm »
1 package Lingua::Ogmios::DocumentRecord;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # use XML::Simple;
7 16 ▶use Lingua::Ogmios::Annotations;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use Lingua::Ogmios::Annotations::LogProcessing;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 16 my $debug_devel_level = 0;
11  
12 14 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
13 14 my ($class, $document_record, $platformConfig) = @_;
14  
15 14 my $doc = {
16 'annotations' => Lingua::Ogmios::Annotations->new($platformConfig),
17 'id' => undef,
18 'attributes' => [],
19 };
20  
21 14 bless $doc, $class;
22  
23 # Parsing the file and loading into the structures
24 14 $doc->setId($document_record);
25 14 $doc->_parse($document_record, $platformConfig);
26 # Making the indexes
27  
28 14 return($doc);
29 }
30  
31 14 ▶sub setId {
Subroutine setId: called CC=3 SCAR=12.0
Pod undocumented
32 14 my ($self, $document_record) = @_;
33  
34 14 my $id;
35  
36 14 ▶ if (UNIVERSAL::isa($document_record, 'XML::LibXML::Element')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($document_record, 'XML::LibXML::Element')) { } 14 0 14
37 14 $id = $document_record->getAttribute("id");
38 } else {
39 0 $id = $document_record;
40 }
41  
42 14 ▶ if (defined($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) { } 14 0 14
43 14 $self->getAnnotations->{'id'} = $id;
44 }
45 else {
46 0 warn "No id for record for doc " . ($self->getCount + 1) . "\n";
47 }
48 }
49  
50 145 ▶sub getId {
Subroutine getId: called CC=1 SCAR=0.0
Pod undocumented
51 145 my ($self) = @_;
52  
53 145 return($self->getAnnotations->{'id'});
54 }
55  
56 14 ▶sub setAttributes {
Subroutine setAttributes: called CC=2 SCAR=6.9
Pod undocumented
57 14 my ($self, $attributes) = @_;
58 14 my $attr;
59  
60 14 foreach $attr (@$attributes) {
61 16 push @{$self->{'attributes'}}, {'nodeName' => $attr->nodeName,
62 'value' => $attr->value,
63 };
64 }
65 }
66  
67 1 ▶sub getAttributes {
Subroutine getAttributes: called CC=1 SCAR=0.0
Pod undocumented
68 1 my ($self) = @_;
69  
70 1 return($self->{'attributes'});
71 }
72  
73 14 ▶sub _parse {
Subroutine _parse: called CC=7 SCAR=21.6
74 14 my ($self, $document_record, $platformConfig) = @_;
75  
76 14 my $lingAnalysisLoad = $platformConfig->linguisticAnnotationLoading;
77  
78 14 warn "Processing document " . $self->getId . "\n";
79  
80 14 my @attr = $document_record->attributes;
81 14 $self->setAttributes(\@attr);
82  
83 14 my $acquisition_section_node = $document_record->getChildrenByTagName('acquisition')->get_node(1);
84 # my $acquisition_section_node;
85 14 ▶ if (defined $acquisition_section_node) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $acquisition_section_node) { } 14 0 14
86 # $acquisition_section_node = $acquisition_section_node_orig->cloneNode(1);
87 14 $self->getAnnotations->setAcquisitionSection($acquisition_section_node);
88 14 $self->getAnnotations->setLanguageFromXMLAndProperties($acquisition_section_node);
89 14 ▶ if (!defined($self->getAnnotations->getLanguage)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->getAnnotations->getLanguage) 0 14 14
90 0 $self->getAnnotations->setLanguage(uc($platformConfig->getOgmiosDefaultLanguage));
91 0 print STDERR $self->getAnnotations->getLanguage . "\n";
92 }
93 14 $self->getAnnotations->setURLs($acquisition_section_node);
94 14 $self->getAnnotations->loadCanonicalDocument($acquisition_section_node);
95 } else {
96 0 die "no acquisition node\n";
97 }
98 # for $document_record ($document_record->getChildrenByTagName('linguisticAnalysis')) {
99 # TODO
100 14 ▶ if ((defined $lingAnalysisLoad) && ($lingAnalysisLoad == 1) && (defined $document_record->getChildrenByTagName('linguisticAnalysis')->get_node(1))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lingAnalysisLoad and $lingAnalysisLoad == 1 and defined $document_record->getChildrenByTagName("linguisticAnalysis")->get_node(1)) 0 14 14
Condition66%4/6
defined $lingAnalysisLoad and $lingAnalysisLoad == 1 and defined $document_record->getChildrenByTagName("linguisticAnalysis")->get_node(1)
!ll&&!rl&&r
1220
defined $lingAnalysisLoad and $lingAnalysisLoad == 1
!ll&&!rl&&r
0122
MC/DC0%0/3
defined $lingAnalysisLoad and $lingAnalysisLoad == 1 and defined $document_record->getChildrenByTagName("linguisticAnalysis")->get_node(1)
defined $lingAnalysisLoad $lingAnalysisLoad == 1 defined $document_record->getChildrenByTagName("linguisticAnalysis")->get_node(1)
Truth table50%2/4
A and B and C
A= defined $lingAnalysisLoadB= $lingAnalysisLoad == 1C= defined $document_record->getChildrenByTagName("linguisticAnalysis")->get_node(1)
ABCresult
0XX0
10X0
1100
1111
101 0 $self->getAnnotations->loadLinguisticAnalysis($document_record->getChildrenByTagName('linguisticAnalysis')->get_node(1));
102 }
103  
104 14 my $relevance_section_node = $document_record->getChildrenByTagName('relevance')->get_node(1);
105 14 ▶ if (defined $relevance_section_node) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $relevance_section_node) 0 14 14
106 0 $self->getAnnotations->setRelevanceSection($relevance_section_node);
107 }
108 }
109  
110  
111 0 ▶sub setAnnotations {
Subroutine setAnnotations: not called CC=1 SCAR=6.9
Pod undocumented
112 0 my ($self) = @_;
113 0 $self->{'annotations'} = undef;
114 }
115  
116 95597 ▶sub getAnnotations {
Subroutine getAnnotations: called CC=1 SCAR=0.0
Pod undocumented
117 95597 my ($self) = @_;
118  
119 95597 return($self->{'annotations'});
120 }
121  
122 20041 ▶sub _char_type_identification {
Subroutine _char_type_identification: called CC=4 SCAR=13.9
123 20041 my ($self, $character) = @_;
124  
125  
126 # Definition of the character types
127 20041 my $alpha="[A-Za-z\x{C0}-\x{D6}\x{D8}-\x{F6}\x{F8}-\x{FF}\x{0400}-\x{0482}\x{048A}-\x{04FF}]";
128 20041 my $num="[0-9]";
129 20041 my $sep="[ \\s\\t\\n\\r]";
130  
131 20041 my $current_char_type;
132 my $current_char_type_string;
133  
134 # default is symbol
135 20041 $current_char_type = 4;$current_char_type_string = "symb";
136  
137 # print STDERR "$character\n";
138  
139 20041 ▶ if($character=~/$alpha/o){$current_char_type = 1;$current_char_type_string = "alpha";};
Branch: 1 branch
BranchTrueFalseTotal
if ($character =~ /$alpha/o) 15847 4194 20041
140 20041 ▶ if($character=~/$num/o){$current_char_type = 2;$current_char_type_string = "num";};
Branch: 1 branch
BranchTrueFalseTotal
if ($character =~ /$num/o) 159 19882 20041
141 20041 ▶ if($character=~/$sep/o){$current_char_type = 3;$current_char_type_string = "sep";};
Branch: 1 branch
BranchTrueFalseTotal
if ($character =~ /$sep/o) 3548 16493 20041
142  
143 20041 return($current_char_type, $current_char_type_string);
144 }
145  
146 6463 ▶sub _tokenCreation {
Subroutine _tokenCreation: called CC=1 SCAR=0.0
147 6463 my ($self,$current_token_string, $current_token_string_length, $previous_char_type_string, $offset) = @_;
148  
149 # code for the character types
150 # 1: alphabetic
151 # 2: numeric
152 # 3: separator
153 # 4: symbol
154 # 0 : not defined
155 # warn "add token: $current_token_string\n";
156  
157  
158 # warn "Creation of new token\n";
159 6463 my $token = Lingua::Ogmios::Annotations::Token->new(
160 {'content' => $current_token_string,
161 'type' => $previous_char_type_string,
162 'from' => $offset,
163 'to' => $offset + $current_token_string_length - 1,
164 });
165 # $token->print;
166 6463 return($token);
167 }
168  
169 11 ▶sub tokenisation {
Subroutine tokenisation: called CC=12 SCAR=25.4
Pod undocumented
170 11 my ($self) = @_;
171  
172 11 ▶ if ($self->getAnnotations->getTokenLevel->getSize != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getTokenLevel->getSize != 0) 0 11 11
173 0 warn "tokens exist - no tokenisation required\n";
174 0 return(0);
175 }
176  
177 11 warn "[LOG] Tokenisation (" . $self->getId . ")\n";
178  
179 11 my $canonicalDocument = $self->getAnnotations->getCanonicalDocument;
180  
181 # warn $self->getId . "\n";
182 # warn $canonicalDocument . "\n";
183  
184 11 my @characters = split //, $canonicalDocument;
185  
186 11 ▶ if (scalar @characters) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @characters) { } 11 0 11
187  
188 11 my $character;
189  
190 11 my $current_token_string = "";
191 11 my $current_token_string_length = 0;
192 11 my $current_token_type = 0;
193 11 my $current_char_type = 0;
194 11 my $current_char_type_string = "";
195 11 my $previous_char_type = 0;
196 11 my $previous_char_type_string = "";
197 11 my $offset = 0;
198  
199 11 my $current_id;
200 my $current_token;
201  
202 11 $character = $characters[0];
203 11 ($current_char_type, $current_char_type_string) = $self->_char_type_identification($character);
204 11 $current_token_string_length = 1;
205 11 $current_token_string = $character;
206 11 $previous_char_type = $current_char_type;
207 11 $previous_char_type_string = $current_char_type_string;
208  
209 11 ▶ if ($current_char_type == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_char_type == 4) 0 11 11
210 0 $current_token = $self->_tokenCreation($character, 1, $current_char_type_string, $offset);
211 0 $current_id = $self->getAnnotations->addToken($current_token);
212 0 $current_token_string = "$character";
213 0 $current_token_string_length = 1;
214 0 $previous_char_type = $current_char_type;
215 0 $previous_char_type_string = $current_char_type_string;
216 0 $offset += $current_token_string_length;
217 }
218 11 my $i;
219 11 ▶ for($i=1;$i<scalar(@characters);$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @characters) 20030 11 20041
220 20030 $character = $characters[$i];
221 # identification of the type of the current character
222  
223 20030 ($current_char_type, $current_char_type_string) = $self->_char_type_identification($character);
224  
225 20030 ▶ if (($current_char_type == $previous_char_type) && ($current_char_type != 4) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($current_char_type == $previous_char_type and $current_char_type != 4 and not $self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset + $current_token_string_length) and not $self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset + $current_token_string_length - 1)) { } 13578 6452 20030
Condition100%9/9
$current_char_type == $previous_char_type and $current_char_type != 4 and not $self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset + $current_token_string_length) and not $self->getAnnotations->getSectionLevel->existsElementFromIndex("to", $offset + $current_token_string_length - 1)
!ll&&!rl&&r
64193313578
$current_char_type == $previous_char_type and $current_char_type != 4 and not $self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset + $current_token_string_length)
!ll&&!rl&&r
64081113611
$current_char_type == $previous_char_type and $current_char_type != 4
!ll&&!rl&&r
63654313622
MC/DC100%4/4
$current_char_type == $previous_char_type and $current_char_type != 4 and not $self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset + $current_token_string_length) and not $self->getAnnotations->getSectionLevel->existsElementFromIndex("to", $offset + $current_token_string_length - 1)
$current_char_type == $previous_char_type $current_char_type != 4 not $self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset + $current_token_string_length) not $self->getAnnotations->getSectionLevel->existsElementFromIndex("to", $offset + $current_token_string_length - 1)
Truth table100%5/5
A and B and not(C) and not(D)
A= $current_char_type == $previous_char_typeB= $current_char_type != 4C= not $self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset + $current_token_string_length)D= not $self->getAnnotations->getSectionLevel->existsElementFromIndex("to", $offset + $current_token_string_length - 1)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
226 (!($self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset + $current_token_string_length ))) &&
227 (!($self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset + $current_token_string_length - 1)))) {
228 13578 $current_token_string .= $character;
229 13578 $current_token_string_length++;
230 } else {
231 6452 ▶ if ($previous_char_type != 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($previous_char_type != 4) 5965 487 6452
232 5965 $current_token = $self->_tokenCreation($current_token_string, $current_token_string_length, $previous_char_type_string, $offset);
233 5965 $current_id = $self->getAnnotations->addToken($current_token);
234 5965 $offset += $current_token_string_length;
235 }
236 6452 ▶ if ($current_char_type == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_char_type == 4) 487 5965 6452
237 487 $current_token_string = $character;
238 487 $current_token_string_length = 1;
239 487 $current_token = $self->_tokenCreation($current_token_string, $current_token_string_length, $current_char_type_string, $offset);
240 487 $current_id = $self->getAnnotations->addToken($current_token);
241 487 $offset += $current_token_string_length;
242 }
243 # and create a new token string
244 6452 $previous_char_type = $current_char_type;
245 6452 $previous_char_type_string = $current_char_type_string;
246 6452 $current_token_string = $character;
247 6452 $current_token_string_length = 1;
248 }
249 }
250 11 ▶ if ($current_char_type != 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_char_type != 4) 11 0 11
251 11 $current_token = $self->_tokenCreation($current_token_string, $current_token_string_length, $previous_char_type_string, $offset);
252 11 $current_id = $self->getAnnotations->addToken($current_token);
253 }
254 } else {
255 0 $self->getAnnotations
256 }
257
258 11 $self->getAnnotations->getSectionLevel->rebuildIndex();
259
260 11 $self->getAnnotations->addLogProcessing(
261 Lingua::Ogmios::Annotations::LogProcessing->new(
262 { 'comments' => 'Found ' . $self->getAnnotations->getTokenLevel->getSize . ' tokens\n',
263 'list_modified_level' => ["token_level"],
264 }
265 )
266 );
267 # $self->getAnnotations->addLogProcessing(
268 # Lingua::Ogmios::Annotations::LogProcessing->new(
269 # { 'comments' => 'Found ' . $self->getAnnotations->getSectionLevel->getSize . ' sections\n',
270 # }
271 # )
272 # );
273 11 $self->getAnnotations->addLogProcessing(Lingua::Ogmios::Annotations::LogProcessing->new(
274 { 'software_name' => 'internal processing',
275 'comments' => 'Tokenisation. Can not be change\n',
276 'list_modified_level' => ["token_level"],
277 }));
278 11 warn "[LOG] Check merging identification of the end and start position (1)\n";
279 }
280  
281 0 ▶sub tokenisation2 {
Subroutine tokenisation2: not called CC=19 SCAR=59.4
Pod undocumented
282 0 my ($self) = @_;
283  
284 0 warn "[LOG] Tokenisation2 (" . $self->getId . ")\n";
285  
286 0 my $canonicalDocument = $self->getAnnotations->getCanonicalDocument;
287  
288 0 my @characters = split //, $canonicalDocument;
289  
290 0 my $character;
291  
292 0 my $current_token_string = "";
293 0 my $current_token_string_length = 0;
294 0 my $current_token_type = 0;
295 0 my $current_char_type = 0;
296 0 my $current_char_type_string = "";
297 0 my $previous_char_type = 0;
298 0 my $previous_char_type_string = "";
299 0 my $offset = 0;
300  
301 0 my $current_id;
302 my $current_token;
303  
304 0 $self->getAnnotations->addLogProcessing(Lingua::Ogmios::Annotations::LogProcessing->new(
305 { 'software_name' => 'internal processing',
306 'comments' => 'Tokenisation. Can not be change\n',
307 }));
308 0 $character = $characters[0];
309 0 ($current_char_type, $current_char_type_string) = $self->_char_type_identification($character);
310 0 $current_token_string_length = 1;
311 0 $current_token_string = $character;
312 0 $previous_char_type = $current_char_type;
313 0 $previous_char_type_string = $current_char_type_string;
314  
315 0 ▶ if ($current_char_type == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_char_type == 4) 0 0 0
316 0 $current_token = $self->_tokenCreation($character, 1, $current_char_type_string, $offset);
317 0 $current_id = $self->getAnnotations->addToken($current_token);
318 0 $current_token_string = "$character";
319 0 $current_token_string_length = 1;
320 0 $previous_char_type = $current_char_type;
321 0 $previous_char_type_string = $current_char_type_string;
322 0 ▶ if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset)) 0 0 0
323 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('from', $offset, $current_token);
324 }
325 0 $offset += $current_token_string_length;
326 0 ▶ if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getSectionLevel->existsElementFromIndex("to", $offset)) 0 0 0
327 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $offset, $current_token);
328 }
329 }
330 0 my $i;
331 0 ▶ for($i=1;$i<scalar(@characters);$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @characters) 0 0 0
332 0 $character = $characters[$i];
333 # identification of the type of the current character
334  
335 0 ($current_char_type, $current_char_type_string) = $self->_char_type_identification($character);
336  
337 0 ▶ if (($current_char_type == $previous_char_type) && ($current_char_type != 4) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($current_char_type == $previous_char_type and $current_char_type != 4 and not $self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset + $current_token_string_length) and not $self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset + $current_token_string_length)) { } 0 0 0
Condition0%0/9
$current_char_type == $previous_char_type and $current_char_type != 4 and not $self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset + $current_token_string_length) and not $self->getAnnotations->getSectionLevel->existsElementFromIndex("to", $offset + $current_token_string_length)
!ll&&!rl&&r
000
$current_char_type == $previous_char_type and $current_char_type != 4 and not $self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset + $current_token_string_length)
!ll&&!rl&&r
000
$current_char_type == $previous_char_type and $current_char_type != 4
!ll&&!rl&&r
000
MC/DC0%0/4
$current_char_type == $previous_char_type and $current_char_type != 4 and not $self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset + $current_token_string_length) and not $self->getAnnotations->getSectionLevel->existsElementFromIndex("to", $offset + $current_token_string_length)
$current_char_type == $previous_char_type $current_char_type != 4 not $self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset + $current_token_string_length) not $self->getAnnotations->getSectionLevel->existsElementFromIndex("to", $offset + $current_token_string_length)
Truth table0%0/5
A and B and not(C) and not(D)
A= $current_char_type == $previous_char_typeB= $current_char_type != 4C= not $self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset + $current_token_string_length)D= not $self->getAnnotations->getSectionLevel->existsElementFromIndex("to", $offset + $current_token_string_length)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
338 (!($self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset + $current_token_string_length ))) &&
339 (!($self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset + $current_token_string_length )))) {
340 0 $current_token_string .= $character;
341 0 $current_token_string_length++;
342 } else {
343 0 ▶ if ($previous_char_type != 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($previous_char_type != 4) 0 0 0
344 0 $current_token = $self->_tokenCreation($current_token_string, $current_token_string_length, $previous_char_type_string, $offset);
345 0 $current_id = $self->getAnnotations->addToken($current_token);
346 0 ▶ if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset)) 0 0 0
347 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('from', $offset, $current_token);
348 }
349 0 ▶ if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset + $current_token_string_length)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getSectionLevel->existsElementFromIndex("to", $offset + $current_token_string_length)) 0 0 0
350 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $offset + $current_token_string_length, $current_token);
351 }
352 0 $offset += $current_token_string_length;
353 }
354 0 ▶ if ($current_char_type == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_char_type == 4) 0 0 0
355 0 $current_token_string = $character;
356 0 $current_token_string_length = 1;
357 0 $current_token = $self->_tokenCreation($current_token_string, $current_token_string_length, $current_char_type_string, $offset);
358 0 $current_id = $self->getAnnotations->addToken($current_token);
359 0 ▶ if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset)) 0 0 0
360 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('from', $offset, $current_token);
361 }
362 0 ▶ if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset + $current_token_string_length)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getSectionLevel->existsElementFromIndex("to", $offset + $current_token_string_length)) 0 0 0
363 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $offset + $current_token_string_length, $current_token);
364 }
365 0 $offset += $current_token_string_length;
366 }
367 # and create a new token string
368 0 $previous_char_type = $current_char_type;
369 0 $previous_char_type_string = $current_char_type_string;
370 0 $current_token_string = $character;
371 0 $current_token_string_length = 1;
372 }
373 }
374 0 ▶ if ($current_char_type != 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_char_type != 4) 0 0 0
375 0 $current_token = $self->_tokenCreation($current_token_string, $current_token_string_length, $previous_char_type_string, $offset);
376 0 $current_id = $self->getAnnotations->addToken($current_token);
377 }
378 0 ▶ if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset + $current_token_string_length)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getSectionLevel->existsElementFromIndex("from", $offset + $current_token_string_length)) 0 0 0
379 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('from', $offset + $current_token_string_length, $current_token);
380 }
381 0 ▶ if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset + $current_token_string_length)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getSectionLevel->existsElementFromIndex("to", $offset + $current_token_string_length)) 0 0 0
382 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $offset + $current_token_string_length, $current_token);
383 }
384  
385 0 $self->getAnnotations->getSectionLevel->rebuildIndex();
386  
387 0 ▶ if ($self->getAnnotations->getTokenLevel->getSize == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getTokenLevel->getSize == 0) 0 0 0
388  
389 0 $self->getAnnotations->addLogProcessing(
390 Lingua::Ogmios::Annotations::LogProcessing->new(
391 { 'comments' => 'Found ' . $self->getAnnotations->getTokenLevel->getSize . ' tokens\n',
392 }
393 )
394 );
395 0 $self->getAnnotations->addLogProcessing(
396 Lingua::Ogmios::Annotations::LogProcessing->new(
397 { 'comments' => 'Found ' . $self->getAnnotations->getSectionLevel->getSize . ' sections\n',
398 }
399 )
400 );
401 }
402 0 warn "[LOG] Check merging identification of the end and start position (2)\n";
403 }
404  
405 11 ▶sub computeSectionFromToken {
Subroutine computeSectionFromToken: called CC=10 SCAR=34.0
Pod undocumented
406 11 my ($self, $record_log) = @_;
407  
408 11 warn "[LOG] Compute Section Ref From Tokens (" . $self->getId . ")\n";
409  
410 11 my $token;
411 11 my $lasttoken = $self->getAnnotations->getTokenLevel->getLastElement;
412 11 my $section;
413 11 foreach $section (@{$self->getAnnotations->getSectionLevel->getElements}) {
414 # warn "check for section " . $section->getId . " (" . $section->getFrom . " - " . $section->getTo . ")\n";
415 44 ▶ if ($self->getAnnotations->getTokenLevel->existsElementFromIndex('from', $section->getFrom)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getTokenLevel->existsElementFromIndex("from", $section->getFrom)) 44 0 44
416 44 $token = $self->getAnnotations->getTokenLevel->getElementFromIndex('from', $section->getFrom)->[0];
417 44 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('from', $token->getFrom, $token);
418 # } else {
419 # die "==> " . $section->getFrom . "\n";
420 }
421 44 ▶ if ($self->getAnnotations->getTokenLevel->existsElementFromIndex('to', $section->getTo)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getTokenLevel->existsElementFromIndex('to', $section->getTo)) { } 44 0 44
422 44 $token = $self->getAnnotations->getTokenLevel->getElementFromIndex('to', $section->getTo)->[0];
423 #warn "in to\n";
424 44 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $token->getTo, $token);
425 } else {
426 0 ▶ if ($self->getAnnotations->getTokenLevel->existsElementFromIndex('from', $section->getTo)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getAnnotations->getTokenLevel->existsElementFromIndex('from', $section->getTo)) { } 0 0 0
427 0 $token = $self->getAnnotations->getTokenLevel->getElementFromIndex('from', $section->getTo)->[0];
428 0 ▶ if (defined $token->previous) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $token->previous) { } 0 0 0
429 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $token->getFrom, $token->previous);
430 } else {
431 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $token->getFrom, $token);
432 }
433 0 warn "ok\n";
434 } else {
435 0 ▶ if (ref($section->getTo) eq "Lingua::Ogmios::Annotations::Token") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $section->getTo eq 'Lingua::Ogmios::Annotations::Token') { } 0 0 0
436 # $self->getAnnotations->getSectionLevel->addElementToIndex($section->getTo,'to');
437 } else {
438 0 ▶ if ($self->getAnnotations->getTokenLevel->existsElementFromIndex('to', $section->getTo - 1)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->getAnnotations->getTokenLevel->existsElementFromIndex('to', $section->getTo - 1)) { } 0 0 0
elsif ($self->getAnnotations->getTokenLevel->existsElementFromIndex('to', $section->getTo + 1)) { } 0 0 0
439 0 $token = $self->getAnnotations->getTokenLevel->getElementFromIndex('to', $section->getTo - 1)->[0];
440 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $section->getTo, $token);
441 # } elsif ($self->getAnnotations->getTokenLevel->existsElementFromIndex('to', $section->getTo + 1)) {
442 # $token = $self->getAnnotations->getTokenLevel->getElementFromIndex('to', $section->getTo + 1)->[0];
443 # $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $section->getTo, $token);
444 0 warn "ok2\n";
445 } elsif ($self->getAnnotations->getTokenLevel->existsElementFromIndex('to', $section->getTo + 1)) {
446 0 $token = $self->getAnnotations->getTokenLevel->getElementFromIndex('to', $section->getTo + 1)->[0];
447 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $section->getTo, $token);
448 } else {
449 0 warn "set to last token\n";
450 0 $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $section->getTo, $lasttoken);
451 # die "==> " . $section->getTo->getContent . "\n";
452 }
453 }
454 }
455 # } else {
456 # warn "not defined\n";
457 # }
458 }
459 # warn "Check for corrected section " . $section->getId . " (" . $section->getFrom . " - " . $section->getTo . ")\n";
460  
461 # warn "Last token " . $lasttoken->getId . " (" . $lasttoken->getFrom . " - " . $lasttoken->getTo . ")\n";
462 # warn "Check for corrected section " . $section->getId . " (" . $section->getFrom . " - " . $section->getTo . ")\n";
463 # warn ".\n";
464 }
465 # exit;
466 # warn "===\n";
467 11 $self->getAnnotations->getSectionLevel->rebuildIndex();
468 # warn "+++\n";
469 11 ▶ if ($record_log) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record_log) 11 0 11
470 11 $self->getAnnotations->addLogProcessing(
471 Lingua::Ogmios::Annotations::LogProcessing->new(
472 { 'comments' => 'Found ' . $self->getAnnotations->getSectionLevel->getSize . ' sections\n',
473 'list_modified_level' => ["section_level"],
474 }
475 )
476 );
477 }
478 11 warn "[LOG] Check merging identification of the end and start position (3)\n";
479 }
480  
481  
482 1 ▶sub XMLout {
Subroutine XMLout: called CC=2 SCAR=6.9
Pod undocumented
483 1 my ($self) = @_;
484  
485 1 my $str;
486 my $attr;
487  
488 1 $str = ' <documentRecord';
489 1 foreach $attr (@{$self->getAttributes}) {
490 1 $str .= " " . $attr->{'nodeName'} . '="' . $attr->{'value'} . '"';
491 }
492 1 $str .= ">\n";
493  
494 1 $str .= $self->getAnnotations->XMLout;
495 1 $str .= " </documentRecord>\n";
496  
497 1 return($str);
498 }
499  
500  
501 16 1;
502  
503 __END__
« blib/lib/Lingua/Ogmios/NLPWrappers/UKWordSegmentizer.pm ↑ Summary blib/lib/Lingua/Ogmios/NLPWrappers/SectionIdentification.pm »