« blib/lib/Lingua/Ogmios/NLPWrappers/Distribution.pm
↑ Summary
blib/lib/Lingua/Ogmios/NLPWrappers/BasicSentenceSegmentizer.pm »
| 1 | package Lingua::Ogmios::DocumentRecord; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | # use XML::Simple; | ||
| 7 | use Lingua::Ogmios::Annotations; | ||
| 8 | use Lingua::Ogmios::Annotations::LogProcessing; | ||
| 9 | |||
| 10 | my $debug_devel_level = 0; | ||
| 11 | |||
| 12 | sub new { | ||
| 13 | my ($class, $document_record, $platformConfig) = @_; | ||
| 14 | |||
| 15 | my $doc = { | ||
| 16 | 'annotations' => Lingua::Ogmios::Annotations->new($platformConfig), | ||
| 17 | 'id' => undef, | ||
| 18 | 'attributes' => [], | ||
| 19 | }; | ||
| 20 | |||
| 21 | bless $doc, $class; | ||
| 22 | |||
| 23 | # Parsing the file and loading into the structures | ||
| 24 | $doc->setId($document_record); | ||
| 25 | $doc->_parse($document_record, $platformConfig); | ||
| 26 | # Making the indexes | ||
| 27 | |||
| 28 | return($doc); | ||
| 29 | } | ||
| 30 | |||
| 31 | sub setId { | ||
| 32 | my ($self, $document_record) = @_; | ||
| 33 | |||
| 34 | my $id; | ||
| 35 | |||
| 36 | if (UNIVERSAL::isa($document_record, 'XML::LibXML::Element')) { | ||
| 37 | $id = $document_record->getAttribute("id"); | ||
| 38 | } else { | ||
| 39 | $id = $document_record; | ||
| 40 | } | ||
| 41 | |||
| 42 | if (defined($id)) { | ||
| 43 | $self->getAnnotations->{'id'} = $id; | ||
| 44 | } | ||
| 45 | else { | ||
| 46 | warn "No id for record for doc " . ($self->getCount + 1) . "\n"; | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | sub getId { | ||
| 51 | my ($self) = @_; | ||
| 52 | |||
| 53 | return($self->getAnnotations->{'id'}); | ||
| 54 | } | ||
| 55 | |||
| 56 | sub setAttributes { | ||
| 57 | my ($self, $attributes) = @_; | ||
| 58 | my $attr; | ||
| 59 | |||
| 60 | foreach $attr (@$attributes) { | ||
| 61 | push @{$self->{'attributes'}}, {'nodeName' => $attr->nodeName, | ||
| 62 | 'value' => $attr->value, | ||
| 63 | }; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | sub getAttributes { | ||
| 68 | my ($self) = @_; | ||
| 69 | |||
| 70 | return($self->{'attributes'}); | ||
| 71 | } | ||
| 72 | |||
| 73 | sub _parse { | ||
| 74 | my ($self, $document_record, $platformConfig) = @_; | ||
| 75 | |||
| 76 | my $lingAnalysisLoad = $platformConfig->linguisticAnnotationLoading; | ||
| 77 | |||
| 78 | warn "Processing document " . $self->getId . "\n"; | ||
| 79 | |||
| 80 | my @attr = $document_record->attributes; | ||
| 81 | $self->setAttributes(\@attr); | ||
| 82 | |||
| 83 | my $acquisition_section_node = $document_record->getChildrenByTagName('acquisition')->get_node(1); | ||
| 84 | # my $acquisition_section_node; | ||
| 85 | if (defined $acquisition_section_node) { | ||
| 86 | # $acquisition_section_node = $acquisition_section_node_orig->cloneNode(1); | ||
| 87 | $self->getAnnotations->setAcquisitionSection($acquisition_section_node); | ||
| 88 | $self->getAnnotations->setLanguageFromXMLAndProperties($acquisition_section_node); | ||
| 89 | if (!defined($self->getAnnotations->getLanguage)) { | ||
| 90 | $self->getAnnotations->setLanguage(uc($platformConfig->getOgmiosDefaultLanguage)); | ||
| 91 | print STDERR $self->getAnnotations->getLanguage . "\n"; | ||
| 92 | } | ||
| 93 | $self->getAnnotations->setURLs($acquisition_section_node); | ||
| 94 | $self->getAnnotations->loadCanonicalDocument($acquisition_section_node); | ||
| 95 | } else { | ||
| 96 | die "no acquisition node\n"; | ||
| 97 | } | ||
| 98 | # for $document_record ($document_record->getChildrenByTagName('linguisticAnalysis')) { | ||
| 99 | # TODO | ||
| 100 | if ((defined $lingAnalysisLoad) && ($lingAnalysisLoad == 1) && (defined $document_record->getChildrenByTagName('linguisticAnalysis')->get_node(1))) { | ||
| 101 | $self->getAnnotations->loadLinguisticAnalysis($document_record->getChildrenByTagName('linguisticAnalysis')->get_node(1)); | ||
| 102 | } | ||
| 103 | |||
| 104 | my $relevance_section_node = $document_record->getChildrenByTagName('relevance')->get_node(1); | ||
| 105 | if (defined $relevance_section_node) { | ||
| 106 | $self->getAnnotations->setRelevanceSection($relevance_section_node); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | |||
| 111 | sub setAnnotations { | ||
| 112 | my ($self) = @_; | ||
| 113 | $self->{'annotations'} = undef; | ||
| 114 | } | ||
| 115 | |||
| 116 | sub getAnnotations { | ||
| 117 | my ($self) = @_; | ||
| 118 | |||
| 119 | return($self->{'annotations'}); | ||
| 120 | } | ||
| 121 | |||
| 122 | sub _char_type_identification { | ||
| 123 | my ($self, $character) = @_; | ||
| 124 | |||
| 125 | |||
| 126 | # Definition of the character types | ||
| 127 | 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 | my $num="[0-9]"; | ||
| 129 | my $sep="[ \\s\\t\\n\\r]"; | ||
| 130 | |||
| 131 | my $current_char_type; | ||
| 132 | my $current_char_type_string; | ||
| 133 | |||
| 134 | # default is symbol | ||
| 135 | $current_char_type = 4;$current_char_type_string = "symb"; | ||
| 136 | |||
| 137 | # print STDERR "$character\n"; | ||
| 138 | |||
| 139 | if($character=~/$alpha/o){$current_char_type = 1;$current_char_type_string = "alpha";}; | ||
| 140 | if($character=~/$num/o){$current_char_type = 2;$current_char_type_string = "num";}; | ||
| 141 | if($character=~/$sep/o){$current_char_type = 3;$current_char_type_string = "sep";}; | ||
| 142 | |||
| 143 | return($current_char_type, $current_char_type_string); | ||
| 144 | } | ||
| 145 | |||
| 146 | sub _tokenCreation { | ||
| 147 | 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 | 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 | return($token); | ||
| 167 | } | ||
| 168 | |||
| 169 | sub tokenisation { | ||
| 170 | my ($self) = @_; | ||
| 171 | |||
| 172 | if ($self->getAnnotations->getTokenLevel->getSize != 0) { | ||
| 173 | warn "tokens exist - no tokenisation required\n"; | ||
| 174 | return(0); | ||
| 175 | } | ||
| 176 | |||
| 177 | warn "[LOG] Tokenisation (" . $self->getId . ")\n"; | ||
| 178 | |||
| 179 | my $canonicalDocument = $self->getAnnotations->getCanonicalDocument; | ||
| 180 | |||
| 181 | # warn $self->getId . "\n"; | ||
| 182 | # warn $canonicalDocument . "\n"; | ||
| 183 | |||
| 184 | my @characters = split //, $canonicalDocument; | ||
| 185 | |||
| 186 | if (scalar @characters) { | ||
| 187 | |||
| 188 | my $character; | ||
| 189 | |||
| 190 | my $current_token_string = ""; | ||
| 191 | my $current_token_string_length = 0; | ||
| 192 | my $current_token_type = 0; | ||
| 193 | my $current_char_type = 0; | ||
| 194 | my $current_char_type_string = ""; | ||
| 195 | my $previous_char_type = 0; | ||
| 196 | my $previous_char_type_string = ""; | ||
| 197 | my $offset = 0; | ||
| 198 | |||
| 199 | my $current_id; | ||
| 200 | my $current_token; | ||
| 201 | |||
| 202 | $character = $characters[0]; | ||
| 203 | ($current_char_type, $current_char_type_string) = $self->_char_type_identification($character); | ||
| 204 | $current_token_string_length = 1; | ||
| 205 | $current_token_string = $character; | ||
| 206 | $previous_char_type = $current_char_type; | ||
| 207 | $previous_char_type_string = $current_char_type_string; | ||
| 208 | |||
| 209 | if ($current_char_type == 4) { | ||
| 210 | $current_token = $self->_tokenCreation($character, 1, $current_char_type_string, $offset); | ||
| 211 | $current_id = $self->getAnnotations->addToken($current_token); | ||
| 212 | $current_token_string = "$character"; | ||
| 213 | $current_token_string_length = 1; | ||
| 214 | $previous_char_type = $current_char_type; | ||
| 215 | $previous_char_type_string = $current_char_type_string; | ||
| 216 | $offset += $current_token_string_length; | ||
| 217 | } | ||
| 218 | my $i; | ||
| 219 | for($i=1;$i<scalar(@characters);$i++) { | ||
| 220 | $character = $characters[$i]; | ||
| 221 | # identification of the type of the current character | ||
| 222 | |||
| 223 | ($current_char_type, $current_char_type_string) = $self->_char_type_identification($character); | ||
| 224 | |||
| 225 | if (($current_char_type == $previous_char_type) && ($current_char_type != 4) && | ||
| 226 | (!($self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset + $current_token_string_length ))) && | ||
| 227 | (!($self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset + $current_token_string_length - 1)))) { | ||
| 228 | $current_token_string .= $character; | ||
| 229 | $current_token_string_length++; | ||
| 230 | } else { | ||
| 231 | if ($previous_char_type != 4) { | ||
| 232 | $current_token = $self->_tokenCreation($current_token_string, $current_token_string_length, $previous_char_type_string, $offset); | ||
| 233 | $current_id = $self->getAnnotations->addToken($current_token); | ||
| 234 | $offset += $current_token_string_length; | ||
| 235 | } | ||
| 236 | if ($current_char_type == 4) { | ||
| 237 | $current_token_string = $character; | ||
| 238 | $current_token_string_length = 1; | ||
| 239 | $current_token = $self->_tokenCreation($current_token_string, $current_token_string_length, $current_char_type_string, $offset); | ||
| 240 | $current_id = $self->getAnnotations->addToken($current_token); | ||
| 241 | $offset += $current_token_string_length; | ||
| 242 | } | ||
| 243 | # and create a new token string | ||
| 244 | $previous_char_type = $current_char_type; | ||
| 245 | $previous_char_type_string = $current_char_type_string; | ||
| 246 | $current_token_string = $character; | ||
| 247 | $current_token_string_length = 1; | ||
| 248 | } | ||
| 249 | } | ||
| 250 | if ($current_char_type != 4) { | ||
| 251 | $current_token = $self->_tokenCreation($current_token_string, $current_token_string_length, $previous_char_type_string, $offset); | ||
| 252 | $current_id = $self->getAnnotations->addToken($current_token); | ||
| 253 | } | ||
| 254 | } else { | ||
| 255 | $self->getAnnotations | ||
| 256 | } | ||
| 257 | |||
| 258 | $self->getAnnotations->getSectionLevel->rebuildIndex(); | ||
| 259 | |||
| 260 | $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 | $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 | warn "[LOG] Check merging identification of the end and start position (1)\n"; | ||
| 279 | } | ||
| 280 | |||
| 281 | sub tokenisation2 { | ||
| 282 | my ($self) = @_; | ||
| 283 | |||
| 284 | warn "[LOG] Tokenisation2 (" . $self->getId . ")\n"; | ||
| 285 | |||
| 286 | my $canonicalDocument = $self->getAnnotations->getCanonicalDocument; | ||
| 287 | |||
| 288 | my @characters = split //, $canonicalDocument; | ||
| 289 | |||
| 290 | my $character; | ||
| 291 | |||
| 292 | my $current_token_string = ""; | ||
| 293 | my $current_token_string_length = 0; | ||
| 294 | my $current_token_type = 0; | ||
| 295 | my $current_char_type = 0; | ||
| 296 | my $current_char_type_string = ""; | ||
| 297 | my $previous_char_type = 0; | ||
| 298 | my $previous_char_type_string = ""; | ||
| 299 | my $offset = 0; | ||
| 300 | |||
| 301 | my $current_id; | ||
| 302 | my $current_token; | ||
| 303 | |||
| 304 | $self->getAnnotations->addLogProcessing(Lingua::Ogmios::Annotations::LogProcessing->new( | ||
| 305 | { 'software_name' => 'internal processing', | ||
| 306 | 'comments' => 'Tokenisation. Can not be change\n', | ||
| 307 | })); | ||
| 308 | $character = $characters[0]; | ||
| 309 | ($current_char_type, $current_char_type_string) = $self->_char_type_identification($character); | ||
| 310 | $current_token_string_length = 1; | ||
| 311 | $current_token_string = $character; | ||
| 312 | $previous_char_type = $current_char_type; | ||
| 313 | $previous_char_type_string = $current_char_type_string; | ||
| 314 | |||
| 315 | if ($current_char_type == 4) { | ||
| 316 | $current_token = $self->_tokenCreation($character, 1, $current_char_type_string, $offset); | ||
| 317 | $current_id = $self->getAnnotations->addToken($current_token); | ||
| 318 | $current_token_string = "$character"; | ||
| 319 | $current_token_string_length = 1; | ||
| 320 | $previous_char_type = $current_char_type; | ||
| 321 | $previous_char_type_string = $current_char_type_string; | ||
| 322 | if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset)) { | ||
| 323 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('from', $offset, $current_token); | ||
| 324 | } | ||
| 325 | $offset += $current_token_string_length; | ||
| 326 | if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset)) { | ||
| 327 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $offset, $current_token); | ||
| 328 | } | ||
| 329 | } | ||
| 330 | my $i; | ||
| 331 | for($i=1;$i<scalar(@characters);$i++) { | ||
| 332 | $character = $characters[$i]; | ||
| 333 | # identification of the type of the current character | ||
| 334 | |||
| 335 | ($current_char_type, $current_char_type_string) = $self->_char_type_identification($character); | ||
| 336 | |||
| 337 | if (($current_char_type == $previous_char_type) && ($current_char_type != 4) && | ||
| 338 | (!($self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset + $current_token_string_length ))) && | ||
| 339 | (!($self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset + $current_token_string_length )))) { | ||
| 340 | $current_token_string .= $character; | ||
| 341 | $current_token_string_length++; | ||
| 342 | } else { | ||
| 343 | if ($previous_char_type != 4) { | ||
| 344 | $current_token = $self->_tokenCreation($current_token_string, $current_token_string_length, $previous_char_type_string, $offset); | ||
| 345 | $current_id = $self->getAnnotations->addToken($current_token); | ||
| 346 | if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset)) { | ||
| 347 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('from', $offset, $current_token); | ||
| 348 | } | ||
| 349 | if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset + $current_token_string_length)) { | ||
| 350 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $offset + $current_token_string_length, $current_token); | ||
| 351 | } | ||
| 352 | $offset += $current_token_string_length; | ||
| 353 | } | ||
| 354 | if ($current_char_type == 4) { | ||
| 355 | $current_token_string = $character; | ||
| 356 | $current_token_string_length = 1; | ||
| 357 | $current_token = $self->_tokenCreation($current_token_string, $current_token_string_length, $current_char_type_string, $offset); | ||
| 358 | $current_id = $self->getAnnotations->addToken($current_token); | ||
| 359 | if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset)) { | ||
| 360 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('from', $offset, $current_token); | ||
| 361 | } | ||
| 362 | if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset + $current_token_string_length)) { | ||
| 363 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $offset + $current_token_string_length, $current_token); | ||
| 364 | } | ||
| 365 | $offset += $current_token_string_length; | ||
| 366 | } | ||
| 367 | # and create a new token string | ||
| 368 | $previous_char_type = $current_char_type; | ||
| 369 | $previous_char_type_string = $current_char_type_string; | ||
| 370 | $current_token_string = $character; | ||
| 371 | $current_token_string_length = 1; | ||
| 372 | } | ||
| 373 | } | ||
| 374 | if ($current_char_type != 4) { | ||
| 375 | $current_token = $self->_tokenCreation($current_token_string, $current_token_string_length, $previous_char_type_string, $offset); | ||
| 376 | $current_id = $self->getAnnotations->addToken($current_token); | ||
| 377 | } | ||
| 378 | if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('from', $offset + $current_token_string_length)) { | ||
| 379 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('from', $offset + $current_token_string_length, $current_token); | ||
| 380 | } | ||
| 381 | if ($self->getAnnotations->getSectionLevel->existsElementFromIndex('to', $offset + $current_token_string_length)) { | ||
| 382 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $offset + $current_token_string_length, $current_token); | ||
| 383 | } | ||
| 384 | |||
| 385 | $self->getAnnotations->getSectionLevel->rebuildIndex(); | ||
| 386 | |||
| 387 | if ($self->getAnnotations->getTokenLevel->getSize == 0) { | ||
| 388 | |||
| 389 | $self->getAnnotations->addLogProcessing( | ||
| 390 | Lingua::Ogmios::Annotations::LogProcessing->new( | ||
| 391 | { 'comments' => 'Found ' . $self->getAnnotations->getTokenLevel->getSize . ' tokens\n', | ||
| 392 | } | ||
| 393 | ) | ||
| 394 | ); | ||
| 395 | $self->getAnnotations->addLogProcessing( | ||
| 396 | Lingua::Ogmios::Annotations::LogProcessing->new( | ||
| 397 | { 'comments' => 'Found ' . $self->getAnnotations->getSectionLevel->getSize . ' sections\n', | ||
| 398 | } | ||
| 399 | ) | ||
| 400 | ); | ||
| 401 | } | ||
| 402 | warn "[LOG] Check merging identification of the end and start position (2)\n"; | ||
| 403 | } | ||
| 404 | |||
| 405 | sub computeSectionFromToken { | ||
| 406 | my ($self, $record_log) = @_; | ||
| 407 | |||
| 408 | warn "[LOG] Compute Section Ref From Tokens (" . $self->getId . ")\n"; | ||
| 409 | |||
| 410 | my $token; | ||
| 411 | my $lasttoken = $self->getAnnotations->getTokenLevel->getLastElement; | ||
| 412 | my $section; | ||
| 413 | foreach $section (@{$self->getAnnotations->getSectionLevel->getElements}) { | ||
| 414 | # warn "check for section " . $section->getId . " (" . $section->getFrom . " - " . $section->getTo . ")\n"; | ||
| 415 | if ($self->getAnnotations->getTokenLevel->existsElementFromIndex('from', $section->getFrom)) { | ||
| 416 | $token = $self->getAnnotations->getTokenLevel->getElementFromIndex('from', $section->getFrom)->[0]; | ||
| 417 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('from', $token->getFrom, $token); | ||
| 418 | # } else { | ||
| 419 | # die "==> " . $section->getFrom . "\n"; | ||
| 420 | } | ||
| 421 | if ($self->getAnnotations->getTokenLevel->existsElementFromIndex('to', $section->getTo)) { | ||
| 422 | $token = $self->getAnnotations->getTokenLevel->getElementFromIndex('to', $section->getTo)->[0]; | ||
| 423 | #warn "in to\n"; | ||
| 424 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $token->getTo, $token); | ||
| 425 | } else { | ||
| 426 | if ($self->getAnnotations->getTokenLevel->existsElementFromIndex('from', $section->getTo)) { | ||
| 427 | $token = $self->getAnnotations->getTokenLevel->getElementFromIndex('from', $section->getTo)->[0]; | ||
| 428 | if (defined $token->previous) { | ||
| 429 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $token->getFrom, $token->previous); | ||
| 430 | } else { | ||
| 431 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $token->getFrom, $token); | ||
| 432 | } | ||
| 433 | warn "ok\n"; | ||
| 434 | } else { | ||
| 435 | if (ref($section->getTo) eq "Lingua::Ogmios::Annotations::Token") { | ||
| 436 | # $self->getAnnotations->getSectionLevel->addElementToIndex($section->getTo,'to'); | ||
| 437 | } else { | ||
| 438 | if ($self->getAnnotations->getTokenLevel->existsElementFromIndex('to', $section->getTo - 1)) { | ||
| 439 | $token = $self->getAnnotations->getTokenLevel->getElementFromIndex('to', $section->getTo - 1)->[0]; | ||
| 440 | $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 | warn "ok2\n"; | ||
| 445 | } elsif ($self->getAnnotations->getTokenLevel->existsElementFromIndex('to', $section->getTo + 1)) { | ||
| 446 | $token = $self->getAnnotations->getTokenLevel->getElementFromIndex('to', $section->getTo + 1)->[0]; | ||
| 447 | $self->getAnnotations->getSectionLevel->changeRefFromIndexField('to', $section->getTo, $token); | ||
| 448 | } else { | ||
| 449 | warn "set to last token\n"; | ||
| 450 | $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 | $self->getAnnotations->getSectionLevel->rebuildIndex(); | ||
| 468 | # warn "+++\n"; | ||
| 469 | if ($record_log) { | ||
| 470 | $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 | warn "[LOG] Check merging identification of the end and start position (3)\n"; | ||
| 479 | } | ||
| 480 | |||
| 481 | |||
| 482 | sub XMLout { | ||
| 483 | my ($self) = @_; | ||
| 484 | |||
| 485 | my $str; | ||
| 486 | my $attr; | ||
| 487 | |||
| 488 | $str = ' <documentRecord'; | ||
| 489 | foreach $attr (@{$self->getAttributes}) { | ||
| 490 | $str .= " " . $attr->{'nodeName'} . '="' . $attr->{'value'} . '"'; | ||
| 491 | } | ||
| 492 | $str .= ">\n"; | ||
| 493 | |||
| 494 | $str .= $self->getAnnotations->XMLout; | ||
| 495 | $str .= " </documentRecord>\n"; | ||
| 496 | |||
| 497 | return($str); | ||
| 498 | } | ||
| 499 | |||
| 500 | |||
| 501 | 1; | ||
| 502 | |||
| 503 | __END__ |