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

filter: Statementstmt 42.8% 120 / 280 Branchbran 21.8% 14 / 64 Conditioncond 8.7% 6 / 69 MC/DCmcdc 0.0% 0 / 41 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 32.1% 150 / 466 CC 62 SCAR 69.1
CC
62
Cov
34%
_outputParsing
1361.4
run
11.6
_inputAwkWS
3.0
CRAP 998.7
« blib/lib/Lingua/Ogmios/NLPWrappers/YaTeA.pm ↑ Summary blib/lib/Lingua/Ogmios/NLPWrappers/PerlWordSegmentizer.pm »
1 package Lingua::Ogmios::NLPWrappers::AwkWordSegmentizer;
2  
3  
4 5 our $VERSION='0.1';
5  
6  
7 5 ▶use Lingua::Ogmios::NLPWrappers::Wrapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶use Lingua::Ogmios::Annotations::Word;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 ▶use Encode qw(:fallbacks);;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 our @ISA = qw(Lingua::Ogmios::NLPWrappers::Wrapper);
17  
18 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
19 5 my ($class, $config, $tmpfile_prefix, $logfile, $position, $no_standard_output) = @_;
20  
21 5 warn "[LOG] Creating a wrapper of the Awk Word segmentizer\n";
22  
23 5 my $AwkWordseg = $class->SUPER::new($config, $tmpfile_prefix, $logfile, $position, $no_standard_output);
24  
25 5 $AwkWordseg->_input_filename($tmpfile_prefix . ".awkWSeg.in");
26 5 $AwkWordseg->_output_filename($tmpfile_prefix . ".awkWSeg.out");
27  
28 5 unlink($AwkWordseg->_input_filename);
29 5 unlink($AwkWordseg->_output_filename);
30  
31 5 return($AwkWordseg);
32  
33 }
34  
35 5 ▶sub _inputAwkWS {
Subroutine _inputAwkWS: called CC=3 SCAR=11.0
36 5 my ($self) = @_;
37  
38 5 my $token;
39 5 my $corpus_in = "";
40 5 my $document;
41  
42 5 warn "[LOG] making Awk Word segmentizer input\n";
43  
44 5 foreach $document (@{$self->_documentSet}) {
45 7 foreach $token (@{$document->getAnnotations->getTokenLevel->getElements}) {
46 # warn "$token: " . $token->getContent . ";\n";
47 4090 $corpus_in .= $token->getContent;
48 }
49 }
50 5 $corpus_in =~ s/[\x{A0}\x{2000}-\x{200B}]/ /go;
51 5 $corpus_in =~ s/\x{0153}/oe/go;
52 5 $corpus_in =~ s/\x{0152}/OE/go;
53
54  
55 5 open FILE_IN, ">" . $self->_input_filename;
56
57  
58 5 print FILE_IN Encode::encode("iso-8859-1", $corpus_in, Encode::FB_DEFAULT); #$corpus_in;
59  
60 5 close FILE_IN;
61  
62 5 warn "[LOG] done\n";
63 }
64  
65  
66 5 ▶sub _processAwkSW {
Subroutine _processAwkSW: called CC=2 SCAR=8.1
67 5 my ($self, $lang) = @_;
68  
69 5 warn "[LOG] wordsegmentation with a awk\n";
70  
71 # warn "\tLanguage for the documentSet: " . $self->_documentSet->[0]->getAnnotations->getLanguage . "\n";
72 5 $lang = $self->_documentSet->[0]->getAnnotations->getLanguage;
73  
74 5 ▶ if (defined $self->_config->commands($lang)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_config->commands($lang)) { } 5 0 5
75 # warn $self->_config->commands($lang)->{WSSegmentizer_CMD} . "\n";;
76  
77 5 return($self->_exec_command($self->_defineCommandLine($self->_config->commands($lang)->{WordSegmentizer_CMD} . " < " . $self->_input_filename . ">" . $self->_output_filename)));
78 } else {
79 0 warn "No segmentizer defined for $lang\n";
80 0 return(undef);
81 }
82 0 warn "[LOG]\n";
83 }
84  
85 5 ▶sub _outputParsing {
Subroutine _outputParsing: called CC=52 SCAR=72.2
86 5 my ($self) = @_;
87  
88 5 my $line;
89 my @words;
90 5 my $token;
91  
92 5 my $doc_idx;
93 5 my $word_shift;
94 5 my $word_idx;
95 5 my $full_idx;
96 5 my $full;
97  
98 5 my $isInNE;
99 5 my $IsNE;
100  
101 5 my $word_start = 0;
102 5 my $word_end = 0;
103  
104 5 my $word;
105  
106 my $token_content1;
107  
108 5 my @Word2tokens;
109 5 my $word_type;
110  
111 5 my $document;
112  
113 5 my $word_form;
114  
115 5 warn "[LOG] . Parsing " . $self->_output_filename . "\n";
116  
117 5 ▶ open FILE_OUT, $self->_output_filename or warn "Can't open the file " . $self->_output_filename;;
Branch: 1 branch
BranchTrueFalseTotal
open FILE_OUT, $self->_output_filename or warn q[Can't open the file ] . $self->_output_filename 0 5 5
118 # binmode(FILE_OUT, ":utf8");
119  
120 5 ▶ while($line = <FILE_OUT>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline FILE_OUT)) 0 5 5
121 0 chomp $line;
122 0 ▶ if ($line ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($line ne "") 0 0 0
123 0 push @words, $line;
124 }
125  
126 }
127 5 close FILE_OUT;
128  
129 5 $word_type = 0;
130 5 $word_idx = 0;
131 5 $word_shift = 0;
132 5 $isInNE = 0;
133 5 $IsNE = 0;
134  
135 5 my $token_content;
136  
137 5 foreach $document (@{$self->_documentSet}) {
138 7 $doc_idx = 0;
139  
140 # warn "Processing document " . $document ->getId . "\n";
141  
142 7 @Word2tokens = ();
143 7 $word_shift = 0;
144 7 $word_form = "";
145 7 $word_type = 0;
146 7 ▶ 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;}) 4090 7 4097
147 # warn "\n";
148 4090 $token = $document->getAnnotations->getTokenLevel->getElements->[$doc_idx];
149 4090 $token_content1 = $token->getContent;
150 4090 $token_content1 =~ s/\x{0153}/oe/go;
151 4090 $token_content1 =~ s/\x{0152}/OE/go;
152 4090 $token_content = Encode::encode("iso-8859-1", $token_content1, Encode::FB_DEFAULT);
153 # warn "(-1) -- " . ($isInNE*1) . " " . $token->getContent . " / $token_content (word $word_idx / token $doc_idx)\n";
154 # warn " == " . scalar(@Word2tokens) . "\n";
155 4090 $isInNE = $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId);
156 # warn "(0) -- " . ($isInNE*1) . " " . $token->getContent . " / $token_content (word $word_idx / token $doc_idx)\n";
157  
158 4090 ▶ if ((!$isInNE) && (scalar(@Word2tokens) != 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $isInNE and scalar @Word2tokens != 0) 0 4090 4090
Condition33%1/3
not $isInNE and scalar @Word2tokens != 0
!ll&&!rl&&r
040900
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
159 # warn "(b1) Add word \"$word_form\" ($word_type)\n";
160  
161 0 my $stok = $Word2tokens[0];
162 0 my $etok = $Word2tokens[$#Word2tokens];
163 0 @Word2tokens = ();
164 0 push @Word2tokens, $stok;
165 0 $word_form = $stok->getContent;
166 0 ▶ while(!$stok->equals($etok)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stok->equals($etok)) 0 0 0
167 0 $stok = $stok->next;
168 0 $word_form .= $stok->getContent;
169 0 push @Word2tokens, $stok;
170 }
171  
172 0 $word = Lingua::Ogmios::Annotations::Word->new(
173 {'form' => $word_form,
174 'list_refid_token' => \@Word2tokens,
175 'isNE' => $IsNE,
176 });
177 0 $document->getAnnotations->addWord($word);
178 0 @Word2tokens = ();
179 0 $IsNE = 0;
180 0 $word_shift = 0;
181 0 $word_form = "";
182 0 $word_type = 0;
183 0 $isInNE = 0;
184 }
185 # if ($word_idx < scalar(@words)) {
186 # warn "(0b) " . $words[$word_idx] . ", " . $token->getContent . " / $token_content\n";
187 # }
188
189 4090 ▶ 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 4090 4090
Condition33%1/3
$word_idx < scalar @words and index($words[$word_idx], $token_content) == 0
!ll&&!rl&&r
409000
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
190 # warn "in if\n";
191 0 push @Word2tokens, $token;
192 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
193  
194 0 $word_start = $token->getId;
195 0 $word_form .= $token->getContent;
196 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
197 0 $word_shift = length($token_content);
198 0 $doc_idx++;
199 0 ▶ if ($doc_idx >= scalar(@{$document->getAnnotations->getTokenLevel->getElements})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doc_idx >= scalar @{$document->getAnnotations->getTokenLevel->getElements;}) { } 0 0 0
200 # warn "out\n";
201 0 $word_end = $token->previous->getId;
202 # next;
203 } else {
204  
205 0 $token = $document->getAnnotations->getTokenLevel->getElements->[$doc_idx];
206 0 $token_content = Encode::encode("iso-8859-1", $token->getContent, Encode::FB_DEFAULT);
207 0 $isInNE = $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId);
208 0 $word_end = $token->getId;
209 # warn " (1) -- $isInNE " . $token->getContent . "(word $word_idx / token $doc_idx)\n";
210 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
211 # warn $token->getContent . "\n";
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 # warn "out\n";
220 0 $word_end = $token->previous->getId;
221 0 next;
222 }
223 0 $token = $document->getAnnotations->getTokenLevel->getElements->[$doc_idx];
224 0 $token_content = Encode::encode("iso-8859-1", $token->getContent, Encode::FB_DEFAULT);
225 0 $isInNE = $document->getAnnotations->getSemanticUnitLevel->existsElementFromIndex("list_refid_token", $token->getId);
226 0 $word_end = $token->getId;
227
228 # warn "\t(2a) -- $isInNE " . $token->getContent . "(word $word_idx / token $doc_idx)\n";
229 }
230 }
231 0 $doc_idx--;
232 # warn "(3) -- $isInNE " . $words[$word_idx] . " / " . $token->getContent . "(word $word_idx / token $doc_idx)\n";
233  
234 0 ▶ if (!$isInNE) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($isInNE) 0 0 0
235 0 ▶ if ($word_type != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word_type != 0) { } 0 0 0
236 # warn "Add word \"$word_form\" ($word_type)" . "(word $word_idx / token $doc_idx)\n";
237 0 my $stok = $Word2tokens[0];
238 0 my $etok = $Word2tokens[$#Word2tokens];
239 0 @Word2tokens = ();
240 0 push @Word2tokens, $stok;
241 0 $word_form = $stok->getContent;
242 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
243 (!$stok->equals($etok))) {
244 0 $stok = $stok->next;
245 0 $word_form .= $stok->getContent;
246 0 push @Word2tokens, $stok;
247 }
248 0 ▶ if ($document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $stok->getId)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($document->getAnnotations->getSectionLevel->existsElementFromIndex("to", $stok->getId)) 0 0 0
249 0 ▶ while(!$stok->equals($etok)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stok->equals($etok)) 0 0 0
250 0 $doc_idx--;
251 0 $etok = $etok->previous;
252 }
253 }
254 0 $word = Lingua::Ogmios::Annotations::Word->new(
255 {'form' => $word_form,
256 'list_refid_token' => \@Word2tokens,
257 'isNE' => $IsNE,
258 });
259 0 $document->getAnnotations->addWord($word);
260 } else {
261 # warn "Go here\n";
262 # TODO XXXX
263 }
264 0 @Word2tokens = ();
265 0 $IsNE = 0;
266 0 $word_shift = 0;
267 0 $word_form = "";
268 0 $word_type = 0;
269  
270 0 $isInNE = 0;
271 }
272 # warn "(4a) -- $isInNE " . $words[$word_idx] . " / " . $token->getContent . "(word $word_idx / token $doc_idx)\n";
273 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
274 ($document->getAnnotations->getTokenLevel->getElements->[$doc_idx+1]->isSep)) {
275 0 $doc_idx++;
276 }
277 # do {
278 0 $word_idx++;
279 # warn "(W) " . $words[$word_idx] . "\n";
280 # } while(($word_idx < scalar(@words)) && (Encode::decode("iso-8859-1", $words[$word_idx], Encode::FB_DEFAULT) =~ /^\s+$/o));
281  
282 # warn "(4b) -- $isInNE " . $words[$word_idx] . " / " . $token->getContent . "(word $word_idx / token $doc_idx)\n";
283 } else {
284 # warn "Check special cases\n";
285 4090 ▶ 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 4090 4090
Condition33%2/6
$word_idx < scalar @words and index($token_content, $words[$word_idx]) == 0 and $token->next->getContent eq "'"
!ll&&!rl&&r
409000
$word_idx < scalar @words and index($token_content, $words[$word_idx]) == 0
!ll&&!rl&&r
409000
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
286 && ($token->next->getContent eq "'")) {
287 # probably a elision
288 # warn "probably a elision\n";
289 0 push @Word2tokens, $token;
290 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
291  
292 0 $word_start = $token->getId;
293 0 $word_form = $words[$word_idx];
294 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
295 0 $word_shift = length($token_content);
296  
297 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
298 (lc($word_form) eq "ca")){
299 0 $word_form .= "n";
300 # warn "correction ca + n't as can + n't\n";
301 }
302  
303 0 my $stok = $Word2tokens[0];
304 0 my $etok = $Word2tokens[$#Word2tokens];
305 0 @Word2tokens = ();
306 0 push @Word2tokens, $stok;
307 0 $word_form = $stok->getContent;
308 0 ▶ while(!$stok->equals($etok)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stok->equals($etok)) 0 0 0
309 0 $stok = $stok->next;
310 0 $word_form .= $stok->getContent;
311 0 push @Word2tokens, $stok;
312 }
313  
314 0 $word = Lingua::Ogmios::Annotations::Word->new(
315 {'form' => $word_form,
316 'list_refid_token' => \@Word2tokens,
317 'isNE' => $IsNE,
318 });
319 0 $document->getAnnotations->addWord($word);
320 # warn "(b2) Add word \"$word_form\" ($word_type)\n";
321 0 @Word2tokens = ();
322 0 $IsNE = 0;
323 0 $word_form = "";
324 0 $word_type = 0;
325  
326 0 push @Word2tokens, $token;
327 0 ▶ if ($token_content ne $words[$word_idx]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_content ne $words[$word_idx]) 0 0 0
328 0 $word_form = substr($token->getContent, length($words[$word_idx]));
329 }
330 0 $word_idx++;
331 # warn "word_form: $word_form\n";
332 0 $doc_idx++;
333 0 ▶ while($word_form ne $words[$word_idx]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word_form ne $words[$word_idx]) 0 0 0
334 0 $token = $document->getAnnotations->getTokenLevel->getElements->[$doc_idx];
335 0 $token_content = Encode::encode("iso-8859-1", $token->getContent, Encode::FB_DEFAULT);
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 4090 ▶ if ($isInNE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isInNE) { } 0 4090 4090
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 4090 ▶ if ($word_type != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word_type != 0) { } 0 4090 4090
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 4090 my $simple_word_form = "";
398 4090 ▶ 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 4090 4090
Condition33%1/3
$word_idx < scalar @words and index($token_content, $words[$word_idx]) == 0
!ll&&!rl&&r
409000
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 4090 @Word2tokens = ();
438 4090 $IsNE = 0;
439 4090 $word_shift = 0;
440 4090 $word_form = "";
441 4090 $word_type = 0;
442  
443 4090 $isInNE = 0;
444  
445 }
446 }
447 }
448 }
449 }
450  
451  
452 }
453  
454 5 ▶sub run {
Subroutine run: called CC=8 SCAR=24.5
Pod undocumented
455 5 my ($self, $documentSet) = @_;
456  
457 5 my $word;
458 my $document;
459 # Set variables according the the configuration
460  
461 5 warn "[LOG] Awk Word segmentizer... \n";
462 5 $self->_documentSet($documentSet);
463  
464 5 ▶ if ($documentSet->[0]->getAnnotations->existsWordLevel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($documentSet->[0]->getAnnotations->existsWordLevel) { } 0 5 5
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 5 $self->_inputAwkWS;
471 # Running the awk segmentizer
472 5 my $command_line = $self->_processAwkSW;
473 5 ▶ if (defined $command_line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $command_line) 5 0 5
474 # Parsing the output
475 5 $self->_outputParsing;
476 }
477 # Put log information
478 5 my $information = { 'software_name' => 'awk word segmentizer',
479 'comments' => 'Word Segmentation\n',
480 'command_line' => "$command_line",
481 'list_modified_level' => ['word_level'],
482 };
483
484 5 $self->_log($information);
485
486 5 my $document;
487 5 foreach $document (@{$documentSet}) {
488 7 $document->getAnnotations->addLogProcessing(
489 Lingua::Ogmios::Annotations::LogProcessing->new(
490 { 'comments' => 'Found ' . $document->getAnnotations->getWordLevel->getSize . ' words \n',
491 }
492 )
493 );
494 }
495 }
496 5 ▶ if (($self->_position eq "last") && ($self->_no_standard_output)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_position eq "last" and $self->_no_standard_output) 0 5 5
Condition33%1/3
$self->_position eq "last" and $self->_no_standard_output
!ll&&!rl&&r
500
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 5 warn "[LOG] done\n";
505 }
506  
507  
508 5 1;
509  
510  
511 __END__
« blib/lib/Lingua/Ogmios/NLPWrappers/YaTeA.pm ↑ Summary blib/lib/Lingua/Ogmios/NLPWrappers/PerlWordSegmentizer.pm »