| 1 | package Alvis::NLPPlatform::Canonical; | ||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 4 | our $VERSION=$Alvis::NLPPlatform::VERSION; | |||||||||
| 7 | |||||||||||
| 8 | sub CleanUp | ||||||||||
| 9 | 0 | ▶ | { | ||||||||
|
Subroutine
CleanUp: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 10 | |||||||||||
| 11 | 0 | my ($canonical, $preserveWhiteSpace) = @_; | |||||||||
| 12 | |||||||||||
| 13 | # my $tmp_str; | ||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | if (!$preserveWhiteSpace) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 0 | warn "\nRemoving White Spaces\n"; | |||||||||
| 17 | |||||||||||
| 18 | 0 | $canonical =~ s/^[\s\t]*(<[^>]+>)[\s\t\n]*(\n)/$1$2/go; | |||||||||
| 19 | 0 | $canonical =~ s/(\n)[\s\t\n]*(<[^>]+>)[\s\t]*(\n)/$1$2$3/go; | |||||||||
| 20 | 0 | $canonical =~ s/(\n)[\s\t\n]*(<[^>]+>)[\s\t]*/$1$2/go; | |||||||||
| 21 | } | ||||||||||
| 22 | 0 | $canonical =~ s/<section[^>]*>//go; | |||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | 0 | $canonical =~ s/<\/?list>/\n/go; | |||||||||
| 27 | 0 | $canonical =~ s/<\/?item>/\n/go; | |||||||||
| 28 | 0 | $canonical =~ s/<\/?canonicalDocument>/\n/go; | |||||||||
| 29 | 0 | $canonical =~ s/<\/?ulink[^>]*>//go; | |||||||||
| 30 | 0 | ▶ | if (!$preserveWhiteSpace) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | $canonical =~ s/\n+/\n/go; | |||||||||
| 32 | 0 | $canonical =~ s/^\n//go; | |||||||||
| 33 | 0 | $canonical =~ s/^\n$//go; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | my $pos = 0; | |||||||||
| 37 | 0 | my $str = $canonical; | |||||||||
| 38 | 0 | my $pos_section = -1; | |||||||||
| 39 | 0 | my $pos_prec_section = 0; | |||||||||
| 40 | |||||||||||
| 41 | 0 | Alvis::NLPPlatform::XMLEntities::decode($str); | |||||||||
| 42 | 0 | $canonical = ""; | |||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | while(($pos_section = index($str, "</section>", $pos_prec_section)) > -1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | $canonical .= substr($str, $pos_prec_section, $pos_section - $pos_prec_section); | |||||||||
| 46 | 0 | chomp $canonical; | |||||||||
| 47 | 0 | ▶ | if ($pos_section != $pos_prec_section) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | $canonical .= "\n"; | |||||||||
| 49 | } | ||||||||||
| 50 | 0 | ▶ | if (!$preserveWhiteSpace) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | $canonical =~ s/\n+/\n/go; | |||||||||
| 52 | 0 | $canonical =~ s/^\n//go; | |||||||||
| 53 | 0 | $canonical =~ s/^\n$//go; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | push @Alvis::NLPPlatform::tab_end_sections_byaddr, (length($canonical) - 1); | |||||||||
| 57 | 0 | $pos_prec_section = $pos_section + 10; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | |||||||||||
| 61 | 0 | return($canonical); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 4 | 1; | |||||||||
| 65 | |||||||||||
| 66 | |||||||||||
| 67 | __END__ | ||||||||||