blib/lib/Lingua/Ogmios/NLPWrappers/PerlWordSegmentizer.pm

filter: Statementstmt 43.4% 125 / 288 Branchbran 24.2% 16 / 66 Conditioncond 8.7% 6 / 69 MC/DCmcdc 0.0% 0 / 41 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 2 totaltotal 33.1% 158 / 477 CC 63 SCAR 68.9
CC
63
Cov
35%
_outputParsing
1371.2
run
11.3
_inputPerlWS
4.0
CRAP 978.4
« blib/lib/Lingua/Ogmios/NLPWrappers/AwkWordSegmentizer.pm ↑ Summary blib/lib/Lingua/Ogmios/NLPWrappers/Wrapper.pm »
1 package Lingua::Ogmios::NLPWrappers::PerlWordSegmentizer;
2  
3  
4 1 our $VERSION='0.1';
5  
6 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Lingua::Ogmios::NLPWrappers::Wrapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Lingua::Ogmios::Annotations::Word;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Encode qw(:fallbacks);;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our @ISA = qw(Lingua::Ogmios::NLPWrappers::Wrapper);
18  
19 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
20 1 my ($class, $config, $tmpfile_prefix, $logfile, $position, $no_standard_output) = @_;
21  
22 1 warn "[LOG] Creating a wrapper of the Perl Word segmentizer\n";
23  
24 1 my $PerlWordseg = $class->SUPER::new($config, $tmpfile_prefix, $logfile, $position, $no_standard_output);
25  
26 1 $PerlWordseg->_input_filename($tmpfile_prefix . ".PerlWSeg.in");
27 1 $PerlWordseg->_output_filename($tmpfile_prefix . ".PerlWSeg.out");
28  
29 1 unlink($PerlWordseg->_input_filename);
30 1 unlink($PerlWordseg->_output_filename);
31  
32 1 return($PerlWordseg);
33  
34 }
35  
36 1 ▶sub _inputPerlWS {
Subroutine _inputPerlWS: called CC=4 SCAR=13.9
37 1 my ($self) = @_;
38  
39 1 my $token;
40 1 my $corpus_in = "";
41 1 my $document;
42  
43 1 warn "[LOG] making Perl Word segmentizer input\n";
44  
45 1 foreach $document (@{$self->_documentSet}) {
46 2 foreach $token (@{$document->getAnnotations->getTokenLevel->getElements}) {
47 # warn "$token: " . $token->getContent . ";\n";
48 1061 $corpus_in .= $token->getContent;
49 1061 ▶ if ($document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $token->getId)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $token->getId)) 8 1053 1061
50 8 $corpus_in .= "\n";
51 }
52 }
53 }
54 1 $corpus_in =~ s/[\x{A0}\x{2000}-\x{200B}]/ /go;
55 # $corpus_in =~ s/\x{0153}/oe/go;
56 # $corpus_in =~ s/\x{0152}/OE/go;
57 1 $corpus_in =~ s/[\x{2019}\x{2032}]/\'/go;
58
59  
60 ##XXX TH
61 1 open FILE_IN, ">:utf8", $self->_input_filename;
62  
63  
64 # print FILE_IN Encode::encode("iso-8859-1", $corpus_in, Encode::FB_DEFAULT); #$corpus_in;
65  
66 1 print FILE_IN $corpus_in;
67  
68 1 close FILE_IN;
69  
70 1 warn "[LOG] done\n";
71 }
72  
73  
74 1 ▶sub _processPerlSW {
Subroutine _processPerlSW: called CC=2 SCAR=8.1
75 1 my ($self, $lang) = @_;
76  
77 1 warn "[LOG] wordsegmentation with a Perl script\n";
78  
79 # warn "\tLanguage for the documentSet: " . $self->_documentSet->[0]->getAnnotations->getLanguage . "\n";
80 1 $lang = $self->_documentSet->[0]->getAnnotations->getLanguage;
81  
82 1 ▶ if (defined $self->_config->commands($lang)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_config->commands($lang)) { } 1 0 1
83 # warn $self->_config->commands($lang)->{WSSegmentizer_CMD} . "\n";;
84  
85 1 return($self->_exec_command($self->_defineCommandLine($self->_config->commands($lang)->{WordSegmentizer_CMD} . " < " . $self->_input_filename . " > " . $self->_output_filename)));
86 } else {
87 0 warn "No segmentizer defined for $lang\n";
88 0 return(undef);
89 }
90 0 warn "[LOG]\n";
91 }
92  
93 1 ▶sub _outputParsing {
Subroutine _outputParsing: called CC=52 SCAR=72.2
94 1 my ($self) = @_;
95  
96 1 my $line;
97 my @words;
98 1 my $token;
99  
100 1 my $doc_idx;
101 1 my $word_shift;
102 1 my $word_idx;
103 1 my $full_idx;
104 1 my $full;
105  
106 1 my $isInNE;
107 1 my $IsNE;
108  
109 1 my $word_start = 0;
110 1 my $word_end = 0;
111  
112 1 my $word;
113  
114 my $token_content1;
115  
116 1 my @Word2tokens;
117 1 my $word_type;
118  
119 1 my $document;
120  
121 1 my $word_form;
122  
123 1 warn "[LOG] . Parsing " . $self->_output_filename . "\n";
124  
125 ##XXX TH
126 1 ▶ open FILE_OUT, "<:utf8", $self->_output_filename or warn "Can't open the file " . $self->_output_filename;;
Branch: 1 branch
BranchTrueFalseTotal
open FILE_OUT, "<:utf8", $self->_output_filename or warn q[Can't open the file ] . $self->_output_filename 0 1 1
127 1 binmode(FILE_OUT, ":utf8");
128  
129 1 ▶ while($line = <FILE_OUT>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline FILE_OUT)) 0 1 1
130 0 chomp $line;
131 0 ▶ if ($line ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($line ne "") 0 0 0
132 0 push @words, $line;
133 }
134  
135 }
136 1 close FILE_OUT;
137  
138 1 $word_type = 0;
139 1 $word_idx = 0;
140 1 $word_shift = 0;
141 1 $isInNE = 0;
142 1 $IsNE = 0;
143  
144 1 my $token_content;
145  
146 1 foreach $document (@{$self->_documentSet}) {
147 2 $doc_idx = 0;
148  
149 # warn "Processing document " . $document ->getId . "\n";
150  
151 2 @Word2tokens = ();
152 2 $word_shift = 0;
153 2 $word_form = "";
154 2 $word_type = 0;
155 2 ▶ for($doc_idx = 0; $doc_idx < scalar(@{$document->getAnnotations->getTokenLevel->getElements});$doc_idx++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doc_idx < scalar @{$document->getAnnotations->getTokenLevel->getElements;}) 1061 2 1063
156 1061 $token = $document->getAnnotations->getTokenLevel->getElements->[$doc_idx];
157 1061 $token_content1 = $token->getContent;
158 # $token_content1 =~ s/\x{0153}/oe/go;
159 # $token_content1 =~ s/\x{0152}/OE/go;
160 # $token_content1 =~ s/[\x{2019}\x{2032}]/\'/go;
161 # $token_content = Encode::encode("iso-8859-1", $token_content1, Encode::FB_DEFAULT);
162 1061 $token_content = $token_content1;
163 1061 $token_content =~ s/[\x{2019}\x{2032}]/\'/go;
164 # warn "(1a) -- $isInNE - " . $words[$word_idx] . " / $word_idx / " . $token_content . " / " . $token->getType . " (word $word_idx / token $doc_idx)\n";
165 1061 $isInNE = $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId);
166 1061 ▶ if ((!$isInNE) && (scalar(@Word2tokens) != 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $isInNE and scalar @Word2tokens != 0) 0 1061 1061
Condition33%1/3
not $isInNE and scalar @Word2tokens != 0
!ll&&!rl&&r
010610
MC/DC0%0/2
not $isInNE and scalar @Word2tokens != 0
not $isInNE scalar @Word2tokens != 0
Truth table33%1/3
not(A) and B
A= not $isInNEB= scalar @Word2tokens != 0
ABresult
0X0
100
111
167 0 my $stok = $Word2tokens[0];
168 0 my $etok = $Word2tokens[$#Word2tokens];
169 0 @Word2tokens = ();
170 0 push @Word2tokens, $stok;
171 0 $word_form = $stok->getContent;
172 0 ▶ while(!$stok->equals($etok)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stok->equals($etok)) 0 0 0
173 0 $stok = $stok->next;
174 0 $word_form .= $stok->getContent;
175 0 push @Word2tokens, $stok;
176 }
177  
178 0 $word = Lingua::Ogmios::Annotations::Word->new(
179 {'form' => $word_form,
180 'list_refid_token' => \@Word2tokens,
181 'isNE' => $IsNE,
182 });
183 0 $document->getAnnotations->addWord($word);
184 0 @Word2tokens = ();
185 0 $IsNE = 0;
186 0 $word_shift = 0;
187 0 $word_form = "";
188 0 $word_type = 0;
189 0 $isInNE = 0;
190 }
191 1061 ▶ if (($word_idx < scalar(@words)) && (index($words[$word_idx], $token_content) == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word_idx < scalar @words and index($words[$word_idx], $token_content) == 0) { } 0 1061 1061
Condition33%1/3
$word_idx < scalar @words and index($words[$word_idx], $token_content) == 0
!ll&&!rl&&r
106100
MC/DC0%0/2
$word_idx < scalar @words and index($words[$word_idx], $token_content) == 0
$word_idx < scalar @words index($words[$word_idx], $token_content) == 0
Truth table33%1/3
A and B
A= $word_idx < scalar @wordsB= index($words[$word_idx], $token_content) == 0
ABresult
0X0
100
111
192 # warn "$token_content\n";
193 0 push @Word2tokens, $token;
194 0 ▶ $IsNE ||= $isInNE;
Condition0%0/3
$IsNE ||= $isInNE
l!l&&r!l&&!r
000
MC/DC0%0/2
$IsNE ||= $isInNE
$IsNE $isInNE
Truth table0%0/3
A ||= B
A= $IsNEB= $isInNE
ABresult
1X1
011
000
195 0 $word_start = $token->getId;
196 0 $word_form .= $token->getContent;
197 0 ▶ $word_type ||= (($token->getType ne "sep") && ($token->getType ne "symb"));
Condition0%0/6
$word_type ||= $token->getType ne "sep" && $token->getType ne "symb"
l!l&&r!l&&!r
000
$token->getType ne 'sep' && $token->getType ne 'symb'
!ll&&!rl&&r
000
MC/DC0%0/3
$word_type ||= $token->getType ne "sep" && $token->getType ne "symb"
$word_type $token->getType ne 'sep' $token->getType ne 'symb'
Truth table0%0/4
A ||= B && C
A= $word_typeB= $token->getType ne 'sep'C= $token->getType ne 'symb'
ABCresult
1XX1
0111
00X0
0100
198 0 $word_shift = length($token_content);
199 0 $doc_idx++;
200 0 ▶ if ($doc_idx >= scalar(@{$document->getAnnotations->getTokenLevel->getElements})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doc_idx >= scalar @{$document->getAnnotations->getTokenLevel->getElements;}) { } 0 0 0
201 0 $word_end = $token->previous->getId;
202 } else {
203  
204 0 $token = $document->getAnnotations->getTokenLevel->getElements->[$doc_idx];
205 # $token_content = Encode::encode("iso-8859-1", $token->getContent, Encode::FB_DEFAULT);
206 0 $token_content = $token->getContent;
207 0 $token_content =~ s/[\x{2019}\x{2032}]/\'/go;
208 0 $isInNE = $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId);
209 0 $word_end = $token->getId;
210 # warn "(2a) -- $isInNE - " . $words[$word_idx] . " / $word_idx / " . $token_content . " / " . $token->getType . " (word $word_idx / token $doc_idx)\n";
211 0 ▶ while(index($words[$word_idx], $token_content, $word_shift) == $word_shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($words[$word_idx], $token_content, $word_shift) == $word_shift) 0 0 0
212 0 push @Word2tokens, $token;
213 0 ▶ $IsNE ||= $isInNE;
Condition0%0/3
$IsNE ||= $isInNE
l!l&&r!l&&!r
000
MC/DC0%0/2
$IsNE ||= $isInNE
$IsNE $isInNE
Truth table0%0/3
A ||= B
A= $IsNEB= $isInNE
ABresult
1X1
011
000
214 0 $word_form .= $token->getContent;
215 0 ▶ $word_type ||= (($token->getType ne "sep") && ($token->getType ne "symb"));
Condition0%0/6
$word_type ||= $token->getType ne "sep" && $token->getType ne "symb"
l!l&&r!l&&!r
000
$token->getType ne 'sep' && $token->getType ne 'symb'
!ll&&!rl&&r
000
MC/DC0%0/3
$word_type ||= $token->getType ne "sep" && $token->getType ne "symb"
$word_type $token->getType ne 'sep' $token->getType ne 'symb'
Truth table0%0/4
A ||= B && C
A= $word_typeB= $token->getType ne 'sep'C= $token->getType ne 'symb'
ABCresult
1XX1
0111
00X0
0100
216 0 $word_shift += length($token_content);
217 0 $doc_idx++;
218 0 ▶ if ($doc_idx >= scalar(@{$document->getAnnotations->getTokenLevel->getElements})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doc_idx >= scalar @{$document->getAnnotations->getTokenLevel->getElements;}) 0 0 0
219 0 $word_end = $token->previous->getId;
220 0 next;
221 }
222 0 $token = $document->getAnnotations->getTokenLevel->getElements->[$doc_idx];
223 # $token_content = Encode::encode("iso-8859-1", $token->getContent, Encode::FB_DEFAULT);
224 0 $token_content = $token->getContent;
225 0 $token_content =~ s/[\x{2019}\x{2032}]/\'/go;
226 0 $isInNE = $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId);
227 0 $word_end = $token->getId;
228 # warn "(2b) -- $isInNE - " . $words[$word_idx] . " / $word_idx / " . $token_content . " / " . $token->getType . " (word $word_idx / token $doc_idx / $word_shift : $word_form)\n";
229 }
230 }
231 0 $doc_idx--;
232 # if (index($words[$word_idx], $token_content, $word_shift) == $word_shift) {
233
234 # }
235 # warn "(2c) -- $isInNE - " . $words[$word_idx] . " / $word_idx / " . $token_content . " / " . $token->getType . " (word $word_idx / token $doc_idx / $word_shift : $word_form)\n";
236  
237 0 ▶ if (!$isInNE) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($isInNE) 0 0 0
238 0 ▶ if ($word_type != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word_type != 0) { } 0 0 0
239 0 my $stok = $Word2tokens[0];
240 0 my $etok = $Word2tokens[$#Word2tokens];
241 0 @Word2tokens = ();
242 0 push @Word2tokens, $stok;
243 0 $word_form = $stok->getContent;
244 0 ▶ while((!$document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $stok->getId)) &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $stok->getId) or $stok->equals($etok)) 0 0 0
Condition0%0/3
$document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $stok->getId) or $stok->equals($etok)
l!l&&r!l&&!r
000
MC/DC0%0/2
$document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $stok->getId) or $stok->equals($etok)
$document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $stok->getId) $stok->equals($etok)
Truth table0%0/3
A or B
A= $document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $stok->getId)B= $stok->equals($etok)
ABresult
1X1
011
000
245 (!$stok->equals($etok))) {
246 0 $stok = $stok->next;
247 0 $word_form .= $stok->getContent;
248 0 push @Word2tokens, $stok;
249 }
250 0 ▶ if ($document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $stok->getId)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $stok->getId)) 0 0 0
251 0 ▶ while(!$stok->equals($etok)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stok->equals($etok)) 0 0 0
252 0 $doc_idx--;
253 0 $etok = $etok->previous;
254 }
255 }
256 # warn "=> $word_form (3a)\n";
257 0 $word = Lingua::Ogmios::Annotations::Word->new(
258 {'form' => $word_form,
259 'list_refid_token' => \@Word2tokens,
260 'isNE' => $IsNE,
261 });
262 0 $document->getAnnotations->addWord($word);
263 } else {
264 # warn "Go here\n";
265 # TODO XXXX
266 }
267 0 @Word2tokens = ();
268 0 $IsNE = 0;
269 0 $word_shift = 0;
270 0 $word_form = "";
271 0 $word_type = 0;
272  
273 0 $isInNE = 0;
274 }
275 0 ▶ while(($doc_idx + 1< scalar(@{$document->getAnnotations->getTokenLevel->getElements})) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($doc_idx + 1 < scalar @{$document->getAnnotations->getTokenLevel->getElements;} and $document->getAnnotations->getTokenLevel->getElements->[$doc_idx + 1]->isSep) 0 0 0
Condition0%0/3
$doc_idx + 1 < scalar @{$document->getAnnotations->getTokenLevel->getElements;} and $document->getAnnotations->getTokenLevel->getElements->[$doc_idx + 1]->isSep
!ll&&!rl&&r
000
MC/DC0%0/2
$doc_idx + 1 < scalar @{$document->getAnnotations->getTokenLevel->getElements;} and $document->getAnnotations->getTokenLevel->getElements->[$doc_idx + 1]->isSep
$doc_idx + 1 < scalar @{$document->getAnnotations->getTokenLevel->getElements;} $document->getAnnotations->getTokenLevel->getElements->[$doc_idx + 1]->isSep
Truth table0%0/3
A and B
A= $doc_idx + 1 < scalar @{$document->getAnnotations->getTokenLevel->getElements;}B= $document->getAnnotations->getTokenLevel->getElements->[$doc_idx + 1]->isSep
ABresult
0X0
100
111
276 ($document->getAnnotations->getTokenLevel->getElements->[$doc_idx+1]->isSep)) {
277 0 $doc_idx++;
278 }
279 0 $word_idx++;
280 } else {
281 # warn "Check special cases ($token_content)\n";
282 # warn "(4a) -- $isInNE - " . $words[$word_idx] . " / $word_idx / " . $token->getContent . " / " . $token->getType . " (word $word_idx / token $doc_idx)\n";
283 1061 ▶ if (($word_idx < scalar(@words)) && (index($token_content, $words[$word_idx]) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($word_idx < scalar @words and index($token_content, $words[$word_idx]) == 0 and $token->next->getContent eq q[']) { } 0 1061 1061
Condition33%2/6
$word_idx < scalar @words and index($token_content, $words[$word_idx]) == 0 and $token->next->getContent eq "'"
!ll&&!rl&&r
106100
$word_idx < scalar @words and index($token_content, $words[$word_idx]) == 0
!ll&&!rl&&r
106100
MC/DC0%0/3
$word_idx < scalar @words and index($token_content, $words[$word_idx]) == 0 and $token->next->getContent eq "'"
$word_idx < scalar @words index($token_content, $words[$word_idx]) == 0 $token->next->getContent eq "'"
Truth table25%1/4
A and B and C
A= $word_idx < scalar @wordsB= index($token_content, $words[$word_idx]) == 0C= $token->next->getContent eq "'"
ABCresult
0XX0
10X0
1100
1111
284 && ($token->next->getContent eq "'")) {
285 # probably a elision
286 # warn "probably a elision\n";
287 0 push @Word2tokens, $token;
288 0 ▶ $IsNE ||= $isInNE;
Condition0%0/3
$IsNE ||= $isInNE
l!l&&r!l&&!r
000
MC/DC0%0/2
$IsNE ||= $isInNE
$IsNE $isInNE
Truth table0%0/3
A ||= B
A= $IsNEB= $isInNE
ABresult
1X1
011
000
289  
290 0 $word_start = $token->getId;
291 0 $word_form = $words[$word_idx];
292 0 ▶ $word_type ||= (($token->getType ne "sep") && ($token->getType ne "symb"));
Condition0%0/6
$word_type ||= $token->getType ne "sep" && $token->getType ne "symb"
l!l&&r!l&&!r
000
$token->getType ne 'sep' && $token->getType ne 'symb'
!ll&&!rl&&r
000
MC/DC0%0/3
$word_type ||= $token->getType ne "sep" && $token->getType ne "symb"
$word_type $token->getType ne 'sep' $token->getType ne 'symb'
Truth table0%0/4
A ||= B && C
A= $word_typeB= $token->getType ne 'sep'C= $token->getType ne 'symb'
ABCresult
1XX1
0111
00X0
0100
293 0 $word_shift = length($token_content);
294  
295 0 ▶ if (($self->_documentSet->[0]->getAnnotations->getLanguage eq "EN") &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_documentSet->[0]->getAnnotations->getLanguage eq "EN" and lc $word_form eq "ca") 0 0 0
Condition0%0/3
$self->_documentSet->[0]->getAnnotations->getLanguage eq "EN" and lc $word_form eq "ca"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_documentSet->[0]->getAnnotations->getLanguage eq "EN" and lc $word_form eq "ca"
$self->_documentSet->[0]->getAnnotations->getLanguage eq "EN" lc $word_form eq "ca"
Truth table0%0/3
A and B
A= $self->_documentSet->[0]->getAnnotations->getLanguage eq "EN"B= lc $word_form eq "ca"
ABresult
0X0
100
111
296 (lc($word_form) eq "ca")){
297 0 $word_form .= "n";
298 # warn "correction ca + n't as can + n't\n";
299 }
300  
301 0 my $stok = $Word2tokens[0];
302 0 my $etok = $Word2tokens[$#Word2tokens];
303 0 @Word2tokens = ();
304 0 push @Word2tokens, $stok;
305 0 $word_form = $stok->getContent;
306 0 ▶ while(!$stok->equals($etok)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stok->equals($etok)) 0 0 0
307 0 $stok = $stok->next;
308 0 $word_form .= $stok->getContent;
309 0 push @Word2tokens, $stok;
310 }
311  
312 0 $word = Lingua::Ogmios::Annotations::Word->new(
313 {'form' => $word_form,
314 'list_refid_token' => \@Word2tokens,
315 'isNE' => $IsNE,
316 });
317 0 $document->getAnnotations->addWord($word);
318 # warn "(b2) Add word \"$word_form\" ($word_type)\n";
319 0 @Word2tokens = ();
320 0 $IsNE = 0;
321 0 $word_form = "";
322 0 $word_type = 0;
323  
324 0 push @Word2tokens, $token;
325 0 ▶ if ($token_content ne $words[$word_idx]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_content ne $words[$word_idx]) 0 0 0
326 0 $word_form = substr($token->getContent, length($words[$word_idx]));
327 }
328 0 $word_idx++;
329 # warn "word_form: $word_form\n";
330 0 $doc_idx++;
331 0 ▶ while($word_form ne $words[$word_idx]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word_form ne $words[$word_idx]) 0 0 0
332 0 $token = $document->getAnnotations->getTokenLevel->getElements->[$doc_idx];
333 # $token_content = Encode::encode("iso-8859-1", $token->getContent, Encode::FB_DEFAULT);
334 0 $token_content = $token->getContent;
335 0 $token_content =~ s/[\x{2019}\x{2032}]/\'/go;
336 0 ▶ $isInNE ||= $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId);
Condition0%0/3
$isInNE ||= $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId)
l!l&&r!l&&!r
000
MC/DC0%0/2
$isInNE ||= $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId)
$isInNE $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId)
Truth table0%0/3
A ||= B
A= $isInNEB= $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId)
ABresult
1X1
011
000
337 0 push @Word2tokens, $token;
338 0 $word_form .= $token->getContent;
339 # warn "word_form: $word_form\n";
340 0 $doc_idx++;
341 }
342 0 $stok = $Word2tokens[0];
343 0 $etok = $Word2tokens[$#Word2tokens];
344 0 @Word2tokens = ();
345 0 push @Word2tokens, $stok;
346 0 $word_form = $stok->getContent;
347 0 ▶ while (!$stok->equals($etok)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stok->equals($etok)) 0 0 0
348 0 $stok = $stok->next;
349 0 $word_form .= $stok->getContent;
350 0 push @Word2tokens, $stok;
351 }
352 0 $word = Lingua::Ogmios::Annotations::Word->new(
353 {'form' => $word_form,
354 'list_refid_token' => \@Word2tokens,
355 'isNE' => $IsNE,
356 });
357 0 $document->getAnnotations->addWord($word);
358 # warn "(b3) Add word \"$word_form\" ($word_type)\n";
359 0 @Word2tokens = ();
360 0 $IsNE = 0;
361 0 $word_form = "";
362 0 $word_type = 0;
363 0 $word_idx++;
364 0 ▶ if (!$document->getAnnotations->getTokenLevel->getElements->[$doc_idx]->isSep) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($document->getAnnotations->getTokenLevel->getElements->[$doc_idx]->isSep) 0 0 0
365 0 $doc_idx--;
366 }
367 # warn "End of probably elision\n";
368 } else {
369 1061 ▶ if ($isInNE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isInNE) { } 0 1061 1061
370 # warn "Named Entity\n";
371 0 push @Word2tokens, $token;
372 0 ▶ $IsNE ||= $isInNE;
Condition0%0/3
$IsNE ||= $isInNE
l!l&&r!l&&!r
000
MC/DC0%0/2
$IsNE ||= $isInNE
$IsNE $isInNE
Truth table0%0/3
A ||= B
A= $IsNEB= $isInNE
ABresult
1X1
011
000
373 0 $word_form .= $token->getContent;
374 0 ▶ $word_type ||= (($token->getType ne "sep") && ($token->getType ne "symb"));
Condition0%0/6
$word_type ||= $token->getType ne "sep" && $token->getType ne "symb"
l!l&&r!l&&!r
000
$token->getType ne 'sep' && $token->getType ne 'symb'
!ll&&!rl&&r
000
MC/DC0%0/3
$word_type ||= $token->getType ne "sep" && $token->getType ne "symb"
$word_type $token->getType ne 'sep' $token->getType ne 'symb'
Truth table0%0/4
A ||= B && C
A= $word_typeB= $token->getType ne 'sep'C= $token->getType ne 'symb'
ABCresult
1XX1
0111
00X0
0100
375 0 $word_shift += length($token_content);
376 } else {
377 # warn "word_type: $word_type\n";
378 1061 ▶ if ($word_type != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word_type != 0) { } 0 1061 1061
379 # warn "(b4) Add word \"$word_form\" ($word_type)\n";
380 0 my $stok = $Word2tokens[0];
381 0 my $etok = $Word2tokens[$#Word2tokens];
382 0 @Word2tokens = ();
383 0 push @Word2tokens, $stok;
384 0 $word_form = $stok->getContent;
385 0 ▶ while(!$stok->equals($etok)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stok->equals($etok)) 0 0 0
386 0 $stok = $stok->next;
387 0 $word_form .= $stok->getContent;
388 0 push @Word2tokens, $stok;
389 }
390 0 $word = Lingua::Ogmios::Annotations::Word->new(
391 {'form' => $word_form,
392 'list_refid_token' => \@Word2tokens,
393 'isNE' => $IsNE,
394 });
395 0 $document->getAnnotations->addWord($word);
396 } else {
397 1061 my $simple_word_form = "";
398 1061 ▶ if (($word_idx < scalar(@words)) && (index($token_content, $words[$word_idx]) == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word_idx < scalar @words and index($token_content, $words[$word_idx]) == 0) 0 1061 1061
Condition33%1/3
$word_idx < scalar @words and index($token_content, $words[$word_idx]) == 0
!ll&&!rl&&r
106100
MC/DC0%0/2
$word_idx < scalar @words and index($token_content, $words[$word_idx]) == 0
$word_idx < scalar @words index($token_content, $words[$word_idx]) == 0
Truth table33%1/3
A and B
A= $word_idx < scalar @wordsB= index($token_content, $words[$word_idx]) == 0
ABresult
0X0
100
111
399 # warn "Seg word is inside current token\n";
400 # warn "Usually it's foreign words\n";
401 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$word_idx < scalar @words and $token_content ne $simple_word_form and do { do { $simple_word_form .= $words[$word_idx]; ++$word_idx } } 0 0 0
Condition0%0/3
$word_idx < scalar @words and $token_content ne $simple_word_form
!ll&&!rl&&r
000
MC/DC0%0/2
$word_idx < scalar @words and $token_content ne $simple_word_form
$word_idx < scalar @words $token_content ne $simple_word_form
Truth table0%0/3
A and B
A= $word_idx < scalar @wordsB= $token_content ne $simple_word_form
ABresult
0X0
100
111
402 0 $simple_word_form .= $words[$word_idx];
403 0 $word_idx++;
404 } while(($word_idx < scalar(@words)) && ($token_content ne $simple_word_form));
405 # } else {
406 # warn "(5aa) -- $isInNE - " . $words[$word_idx] . " / " . $token->getContent . " / " . $token->getType . " (word $word_idx / token $doc_idx)\n";
407 # if (($word_idx < scalar(@words)) && (index($words[$word_idx], $token_content))) {
408 # warn "current token is inside Seg word\n";
409 # warn scalar(@Word2tokens) . "\n";
410 # # if ($document->getAnnotations->getTokenLevel->getElements->[$doc_idx]->isSep) {
411 # # $word_form = $token->getContent;
412 # # $word_type ||= (($token->getType ne "sep") && ($token->getType ne "symb"));
413 # # $word_start = $token->getId;
414 # # push @Word2tokens, $token;
415 # # $word_idx++;
416 # # }
417 # # warn "Usually it's foreign words\n";
418 # }
419  
420 # warn "(5a) -- $isInNE " . $words[$word_idx] . " / " . $token->getContent . " / " . $token->getType . " (word $word_idx / token $doc_idx)\n";
421 # while(($doc_idx < scalar(@{$document->getAnnotations->getTokenLevel->getElements})) &&
422 # ($document->getAnnotations->getTokenLevel->getElements->[$doc_idx]->isSep)) {
423 # $doc_idx++;
424 # }
425 # if (Encode::decode("iso-8859-1", $words[$word_idx], Encode::FB_DEFAULT) =~ /^\s+$/o) {
426 # while(($doc_idx < scalar(@{$document->getAnnotations->getTokenLevel->getElements})) &&
427 # (!$document->getAnnotations->getTokenLevel->getElements->[$doc_idx]->isSep)) {
428 # $doc_idx++;
429 # warn "(5b) -- $isInNE " . $words[$word_idx] . " / " . $token->getContent . " / " . $token->getType . " (word $word_idx / token $doc_idx)\n";
430 # }
431 # $word_idx++;
432 # }
433 # warn "(5c) -- $isInNE " . $words[$word_idx] . " / " . $token->getContent . " / " . $token->getType . " (word $word_idx / token $doc_idx)\n";
434 }
435 }
436 # warn "out\n";
437 1061 @Word2tokens = ();
438 1061 $IsNE = 0;
439 1061 $word_shift = 0;
440 1061 $word_form = "";
441 1061 $word_type = 0;
442  
443 1061 $isInNE = 0;
444  
445 }
446 }
447 }
448 }
449 }
450  
451  
452 }
453  
454 1 ▶sub run {
Subroutine run: called CC=8 SCAR=24.2
Pod undocumented
455 1 my ($self, $documentSet) = @_;
456  
457 1 my $word;
458 my $document;
459 # Set variables according the the configuration
460  
461 1 warn "[LOG] Perl Word segmentizer... \n";
462 1 $self->_documentSet($documentSet);
463  
464 1 ▶ if ($documentSet->[0]->getAnnotations->existsWordLevel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($documentSet->[0]->getAnnotations->existsWordLevel) { } 0 1 1
465 0 warn "words exist in the first document\n";
466 0 warn " Assuming that no word segmentation is required for the current document set\n";
467 # return(0);
468 } else {
469 # Generating the input for one document
470 1 $self->_inputPerlWS;
471 # Running the Perl segmentizer
472 1 my $command_line = $self->_processPerlSW;
473 1 ▶ if (defined $command_line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $command_line) 1 0 1
474 # Parsing the output
475 1 $self->_outputParsing;
476 }
477 # Put log information
478 1 my $information = { 'software_name' => 'Perl word segmentizer',
479 'comments' => 'Word Segmentation\n',
480 'command_line' => "$command_line",
481 'list_modified_level' => ['word_level'],
482 };
483
484 1 $self->_log($information);
485
486 1 my $document;
487 1 foreach $document (@{$documentSet}) {
488 2 $document->getAnnotations->addLogProcessing(
489 Lingua::Ogmios::Annotations::LogProcessing->new(
490 { 'comments' => 'Found ' . $document->getAnnotations->getWordLevel->getSize . ' words \n',
491 }
492 )
493 );
494 }
495 }
496 1 ▶ if (($self->_position eq "last") && ($self->_no_standard_output)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_position eq "last" and $self->_no_standard_output) 0 1 1
Condition33%1/3
$self->_position eq "last" and $self->_no_standard_output
!ll&&!rl&&r
100
MC/DC0%0/2
$self->_position eq "last" and $self->_no_standard_output
$self->_position eq "last" $self->_no_standard_output
Truth table33%1/3
A and B
A= $self->_position eq "last"B= $self->_no_standard_output
ABresult
0X0
100
111
497 0 warn "print no standard output\n";
498 0 foreach $document (@{$documentSet}) {
499 0 foreach $word (@{$document->getAnnotations->getWordLevel->getElements}) {
500 0 print $word->getForm . "\n";
501 }
502 }
503 }
504  
505 1 $self->getTimer->_printTimesInLine($self->_config->name);
506 1 warn "[LOG] done\n";
507 }
508  
509  
510 1 1;
511  
512 __END__
« blib/lib/Lingua/Ogmios/NLPWrappers/AwkWordSegmentizer.pm ↑ Summary blib/lib/Lingua/Ogmios/NLPWrappers/Wrapper.pm »