PLN.pm

filter: Statementstmt 26.3% 76 / 288 Branchbran 15.2% 14 / 92 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 31.8% 7 / 22 Podpod 100% 12 / 12 totaltotal 24.8% 109 / 438 CC 62 SCAR 41.6
CC
62
Cov
23%
toPhon
132.0
syllable
110.0
oco
79.9
CRAP 64.2
« PLN/Words2Sampa.pm ↑ Summary
1 package Lingua::PT::PLN;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4  
5 4 ▶use Lingua::PT::PLNbase;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 #use Lingua::PT::PLN::Words2Sampa;
7  
8 4 require Exporter;
9 4 our @ISA = qw(Exporter AutoLoader);
10  
11 4 our @EXPORT =
12 (@Lingua::PT::PLNbase::EXPORT,
13 qw(syllable accent wordaccent oco initPhon toPhon));
14  
15 4 our $VERSION = '0.22';
16  
17 4 ▶use POSIX qw(locale_h);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 setlocale(&POSIX::LC_ALL, "pt_PT");
19 4 ▶use locale;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # para transcrição fonética
22 4 $INC{'Lingua/PT/PLN.pm'} =~ m!/PLN\.pm$!;
23 4 our $ptpho = "$`/PLN/ptpho";
24 4 our $naoacentuadas = "$`/PLN/nao_acentuadas";
25 4 our $dic;
26 4 our $no_accented;
27  
28 4 our ($consoante, $vogal, $acento, %names);
29  
30 4 my ($lmax,$maxlog,$magicF);
31  
32 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
33 4 $consoante=qr{[bcçdfghjklmñnpqrstvwyxz]}i;
34 4 $vogal=qr{[áéíóúâêôãõàèaeiouüöäëï]}i;
35 4 $acento=qr{[áéíóúâêôãõüöäëï]}i;
36 4 setlocale(&POSIX::LC_ALL, "pt_PT");
37  
38 4 ▶ use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 4 POSIX::setlocale(LC_CTYPE,"pt_PT");
40  
41 4 $lmax = 1000000;
42 4 $maxlog = 13.815;
43 4 $magicF = $maxlog/log($lmax);
44 }
45  
46  
47  
48 2 ▶sub oco {
Subroutine oco: called CC=25 SCAR=43.8
Pod documented
49 ### { from => (file|string),
50 ### num => 1,
51 ### log => 1, # logaritmic output
52 ### alpha => 1,
53 ### output => file,
54 ### encoding => utf8,
55 ### ignorexml => 1,
56 ### ignorecase => 1}
57  
58 2 my %opt = (from => 'file', ignorecase => 0, ignorexml => 0, encoding => "latin1");
59 2 ▶ %opt = (%opt , %{shift(@_)}) if ref($_[0]) eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" 2 0 2
60  
61 2 local $\ = "\n"; # set output record separator
62  
63 2 my $P="(?:[,;:?!]|[.]+|[-]+)"; # pontuacao a contar
64 2 my $A="[A-ZñÑa-záàãâäçéèêëíïóòõôöúùûüÁÀÃÂÄÇÉÈÊËÍÏÓÒÕÔÖÚÙÛÜ_]";
65 2 my $I="[ \"(){}+*=<>\250\256\257\277\253\273]"; # car. a ignorar
66 2 my %oco=();
67 2 my $tot=0;
68  
69 2 ▶ if ($opt{from} eq 'string') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{'from'} eq 'string') { } 1 1 2
70 1 my (@str) = (@_);
71 1 for (@str) {
72 1 ▶ $_ = lc if $opt{ignorecase};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"ignorecase"} 0 1 1
73 1 ▶ s/<[^>]+>//g if $opt{ignorexml};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"ignorexml"} 0 1 1
74 1 for (/($A+(?:['-]$A+)*|$P)/g) { $oco{$_}++; $tot++ }
75 }
76 } else {
77 1 my (@file) = (@_);
78 1 for(@file) {
79 1 ▶ open F,"< $_" or die "cant open $_: $!";
Branch: 1 branch
BranchTrueFalseTotal
open F, "< $_" or die "cant open ${_}: $!" 1 0 1
80 1 ▶ binmode(F, ":utf8") if $opt{encoding} =~ /utf8/i ;
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"encoding"} =~ /utf8/il 0 1 1
81 1 ▶ while (<F>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline F)) 500 1 501
82 500 ▶ $_ = lc if $opt{ignorecase};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"ignorecase"} 0 500 500
83 500 ▶ s/<[^>]+>//g if $opt{ignorexml};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"ignorexml"} 0 500 500
84 500 for (/($A+(?:['-]$A+)*|$P)/g) { $oco{$_}++; $tot++}
85 }
86 1 close F;
87 }
88 }
89  
90 2 ▶ if ($opt{log}){
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"log"}) 0 2 2
91 0 print "total = $tot\n";
92 0 _setmax($tot);
93 0 ▶ _setmax($opt{log}) if($opt{log} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"log"} > 1 0 0 0
94 0 for (keys %oco){
95 0 $oco{$_}=_logit($oco{$_});
96 }
97 }
98  
99 2 ▶ if ($opt{num}) { # imprime por ordem de quantidade de ocorrencias
Branch: 2 branches
BranchTrueFalseTotal
if ($opt{'num'}) { } 0 2 2
elsif ($opt{'alpha'}) { } 0 2 2
100  
101 # TODO: não é portável
102 0 ▶ if (defined $opt{output}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{'output'}) { } 0 0 0
103 0 open SORT,"| sort -nr > $opt{output}"
104 } else {
105 0 open SORT,"| sort -nr"
106 }
107  
108 0 for my $i (keys %oco) {
109 0 print SORT "$oco{$i} $i"
110 }
111 0 close SORT;
112  
113 } elsif ($opt{alpha}) { # imprime ordenado alfabeticamente
114  
115 0 ▶ if (defined $opt{output}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{'output'}) { } 0 0 0
116 0 open SORT ,"> $opt{output}";
117 0 for my $i (sort keys %oco ) {
118 0 print SORT "$i $oco{$i}";
119 }
120 } else {
121 0 ▶ binmode STDOUT, ":utf8" if $opt{encoding};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"encoding"} 0 0 0
122 0 for my $i (sort keys %oco ) {
123 0 print "$i $oco{$i}";
124 }
125 }
126 } else {
127 2 return (%oco)
128 }
129 }
130  
131 ### syllabs, and accents
132  
133 0 ▶sub accent {
Subroutine accent: not called CC=1 SCAR=6.9
Pod documented
134 0 local $/ = ""; # input record separator=1 or more empty lines
135 0 my $p=shift;
136 0 $p =~ s/(\w+)/ wordaccent($1) /ge;
137 0 $p
138 }
139  
140 0 ▶sub wordaccent {
Subroutine wordaccent: not called CC=7 SCAR=40.3
Pod documented
141 0 my $p = syllable($_[0]);
142 0 ▶ my $flag = $_[1] or 0; # 0 (default) => use : after vowel; 1 => use " before syllable
Branch: 1 branch
BranchTrueFalseTotal
my $flag = $_[1] or '???' 0 0 0
143 0 for ($p) {
144 0 ▶ s{(\w*$acento)}{"$1}i or # word with an accent character
Branch: 1 branch
BranchTrueFalseTotal
s/(\w*$Lingua::PT::PLN::acento)/"$1/il or s/(\w*([zlr]|[iu]s?|um))$/"$1/il or s/(\w+\|\w+)$/"$1/l or s/(\w)/"$1/l 0 0 0
Condition0%0/6
s/(\w*$Lingua::PT::PLN::acento)/"$1/il or s/(\w*([zlr]|[iu]s?|um))$/"$1/il or s/(\w+\|\w+)$/"$1/l
l!l&&r!l&&!r
000
s/(\w*$Lingua::PT::PLN::acento)/"$1/il or s/(\w*([zlr]|[iu]s?|um))$/"$1/il
l!l&&r!l&&!r
000
MC/DC0%0/3
s/(\w*$Lingua::PT::PLN::acento)/"$1/il or s/(\w*([zlr]|[iu]s?|um))$/"$1/il or s/(\w+\|\w+)$/"$1/l
s/(\w*$Lingua::PT::PLN::acento)/"$1/il s/(\w*([zlr]|[iu]s?|um))$/"$1/il s/(\w+\|\w+)$/"$1/l
Truth table0%0/4
A or B or C
A= s/(\w*$Lingua::PT::PLN::acento)/"$1/ilB= s/(\w*([zlr]|[iu]s?|um))$/"$1/ilC= s/(\w+\|\w+)$/"$1/l
ABCresult
1XX1
01X1
0011
0000
145 # s{(\w*)([ua])(ir)$}{$1$2|"$3}i or # word ending with air uir
146 s{(\w*([zlr]|[iu]s?|um))$}{"$1}i or # word ending with z l r i u is us
147 s{(\w+\|\w+)$}{"$1} or # accent in 2 syllable frm the end
148 s{(\w)}{"$1}; # accent in the only syllable
149  
150 0 ▶ if(!$flag){
Branch: 1 branch
BranchTrueFalseTotal
unless ($flag) 0 0 0
151 # s{"(([qg]u|$consoante)*($vogal|[yw]))}{$1:}i; # accent in the 1.st vowel
152 # bugfix: quo|ti|"dia|no => quo|ti|dia:|no; op|"ção => op|çã:o
153 0 s{"(([qg]u|$consoante)*([i]$vogal|$vogal|[yw]))}{$1:}i; # accent in the 1.st vowel
154 0 s{:($acento)}{$1:}i; # mv accent after accents
155 0 s{"}{}g;
156 }
157  
158 }
159 $p
160 0 }
161  
162 4 my %syl = (
163 20 => " -.!?:;",
164 10 => "bçdfgjkpqtv",
165 8 => "sc",
166 7 => "m",
167 6 => "lzx",
168 5 => "nr",
169 4 => "h",
170 3 => "wy",
171 2 => "eaoáéíóúôâêûàãõäëïöü",
172 1 => "iu",
173 breakpair =>
174 #"ie|ia|io|ee|oo|oa|sl|sm|sn|sc|sr|rn|bc|lr|lz|bd|bj|bg|bq|bt|bv|pt|pc|dj|pç|ln|nr|mn|tp|bf|bp",
175 "sl|sm|sn|sc|sr|rn|bc|lr|lz|bd|bj|bg|bq|bt|bv|pt|pc|dj|pç|ln|nr|mn|tp|bf|bp|xc|sç|ss|rr",
176 # dígrafos que se separam sempre: xc, sç, ss, rr, sc.
177 );
178  
179 4 my %spri = ();
180  
181 4 for my $pri (grep(/\d/, keys %syl)){
182 40 for(split(//,$syl{$pri})) { $spri{$_} = $pri}}
183  
184 4 (my $sylseppair= $syl{breakpair}) =~ s/(\w)(\w)/(\?<=($1))(\?=($2))/g;
185  
186 0 ▶sub syllable{
Subroutine syllable: not called CC=10 SCAR=47.0
Pod documented
187 0 my $p=shift;
188  
189 0 for($p){
190 0 s/$sylseppair/|/g;
191 0 s{(\w)(?=(\w)(\w))}
192 0 ▶ {if($spri{lc($1)}<$spri{lc($2)} && $spri{lc($2)}>=$spri{lc($3)}){"$1|"}
Branch: 1 branch
BranchTrueFalseTotal
if ($spri{lc $1} < $spri{lc $2} and $spri{lc $2} >= $spri{lc $3}) { } 0 0 0
Condition0%0/3
$spri{lc $1} < $spri{lc $2} and $spri{lc $2} >= $spri{lc $3}
!ll&&!rl&&r
000
MC/DC0%0/2
$spri{lc $1} < $spri{lc $2} and $spri{lc $2} >= $spri{lc $3}
$spri{lc $1} < $spri{lc $2} $spri{lc $2} >= $spri{lc $3}
Truth table0%0/3
A and B
A= $spri{lc $1} < $spri{lc $2}B= $spri{lc $2} >= $spri{lc $3}
ABresult
0X0
100
111
193 0 else{$1}
194 }ge;
195  
196 0 s{([a])(i[ru])$}{$1|$2}i; #ditongos and friends
197  
198 #s{([ioeê])([aoe])}{$1|$2}ig; # not this simple
199 0 s{(?<!^h)([ioeê])([e])}{$1|$2}ig; #
200 0 s{([ioeêé])([ao])}{$1|$2}ig; # la|go|a; di|a; ru|bé|o|la; né|on; au|ré|o|la
201  
202 0 s{([^qg]u)(ai|ou|a)}{$1|$2}i; # BUGFIX: [^q]: qu|a|se => qua|se
203 0 s{([^qgc]u)(i|ei|iu|ir|$acento|e)}{$1|$2}i; # continu|e
204 0 s{([lpt]u)\|(i)(?=\|[ao])}{$1$2}ig; # a|le|lui|a ta|pui|a con|lui|o
205 0 s{([^q]u)(o)}{$1|$2}i; # quo|ta; vácu|o
206 0 s{([aeio])($acento)}{$1|$2}i;
207 0 s{([íúô])($vogal)}{$1|$2}i;
208 0 s{^a(o|e)}{a|$1}i; # a|onde; a|orta; a|eródromo
209  
210 # Exemplo: his|tó|ria
211 0 ▶ if( m/([\w\|]*$acento[\w\|]*)\-/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/([\w\|]*$Lingua::PT::PLN::acento[\w\|]*)\-/l) 0 0 0
212 0 ▶ if ( m/([eiou])\|([aeio])\-/ ) { # palavras com hifen
Branch: 1 branch
BranchTrueFalseTotal
if (/([eiou])\|([aeio])\-/l) 0 0 0
213 0 ▶ s{([eiou])\|([aeio])(?=\-)}{$1$2}ig if $1 ne $2 ;
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne $2 0 0 0
214 }
215 }
216 0 ▶ if ( m/([\w\|]*$acento[\w\|]*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/([\w\|]*$Lingua::PT::PLN::acento[\w\|]*)$/l) 0 0 0
217 0 ▶ if ( m/([eiou])\|([aeio])$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/([eiou])\|([aeio])$/l) 0 0 0
218 0 ▶ s{([eiou])\|([aeio])$}{$1$2}ig if $1 ne $2 ;
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne $2 0 0 0
219 }
220 }
221  
222 #s{([qg]u)\|([eií])}{$1$2}i;
223  
224 0 s{rein}{re|in}ig; # re|in|ves|tir
225 0 s{ae}{a|e}ig; # ma|ca|en|se ; es|ma|e|cer
226 0 s{ain}{a|in}ig; # a|in|da con|tra|in|for|mar pa|in|ço
227 0 s{ao(?!s)}{a|o}ig; # ca|o|ti|ca|men|te ; ma|o|me|tis|mo != caos
228 0 s{cue}{cu|e}ig; # ar|cu|en|se
229 0 s{cui(?=\|?[mnr])}{cu|i}ig; #
230 0 s{cui(?=\|da\|de$)}{cu|i}ig; # pro|mis|cu|i|da|de; i|no|cu|i|da|de
231 0 s{coi(?=[mn])}{co|i}ig; # co|in|ci|den|te;
232 0 s{cai(?=\|?[mnd])}{ca|i}ig; # des|ca|i|de|la; des|ca|i|men|to
233 0 s{ca\|i(?=\|?[m]$acento)}{cai}ig; # cai|mão
234 0 s{cu([áó])}{cu|$1}ig; # pe|cu|á|ria va|cu|ó|me|tro
235 0 s{ai(?=\|?[z])}{a|i}ig; # ra|iz ; en|ra|i|zar
236 0 s{i(u\|?)n}{i|$1n}ig; # tri|un|fo
237 0 s{i(u\|?)r}{i|$1r}ig; # di|ur|no
238 0 s{i(u\|?)v}{i|$1v}ig; # viuvar
239 0 s{i(u\|?)l}{i|$1l}ig; # friulano
240 0 s{ium}{i|um}ig; # médium
241 0 s{([ta])iu}{$1i|u}ig; # multiuso , baiuca, maiusculizar
242 0 s{miu\|d}{mi|u|d}ig; # miudinho
243 0 s{au\|to(?=i)}{au|to|}ig; # au|to|i|ma|gem
244 0 s{(?<=$vogal)i\|nh(?=[ao])}{|i|nh}ig; # # ven|to|i|nha
245 0 s{oi([mn])}{o|i$1}ig; # a|men|do|im monoinsaturado microinjecção
246 0 s{oi\|b}{o|i|b}ig; # proibido
247 0 s{ois(?!$)}{o|is}ig; # ma|o|is|mo ; e|go|is|ti|ca|men|te
248 0 s{o(i\|?)s(?=$acento)}{o|$1s}ig; # ra|di|o|i|só|to|po
249 0 s{([dtm])aoi}{$1a|o|i}ig; # da|o|is|ta ; ta|o|is|ta ; ma|o|is|ta
250 0 s{(?<=[trm])u\|i(?=\|?[tvb][oa])}{ui}ig;
251 # ?: gra|tui|ti|da|de vs in|tu|i|ti|vo
252  
253 0 s{^gas\|tro(?!-)}{gas|tro|}ig; # gas|tro|in|tes|ti|nal ; gas|tro-in|tes|ti|nal
254 0 s{^fais}{fa|is}ig; # faiscar | faiscação
255 0 s{^hie}{hi|e}ig; # hi|e|na ; hi|e|rar|ca
256 0 s{^ciu}{ci|u}ig; # ci|u|men|to
257 0 s{(?<=^al\|ca)\|i}{i}ig; # al|cai|de
258 0 s{(?<=^an\|ti)(p)\|?}{|$1}ig; # anti
259 0 s{(?<=^an\|ti)(\-p)\|?}{$1}ig; # anti
260 0 s{(?<=^neu\|ro)p\|}{|p}ig; # neu|ro|psi|có|lo|go
261 0 s{(?<=^pa\|ra)p\|}{|p}ig; # pa|ra|psi|có|lo|go
262 0 s{(?<=^ne\|)op\|}{o|p}ig; # neopsicadélico
263 0 s{^re(?=[i]\|?[md])}{re|}ig; # re|i|dra|ta|ção
264 0 s{^re(?=i\|n[ií]\|c)}{re|}ig; # re|i|ni|ci|ar
265 0 s{^re(?=i\|nau\|g)}{re|}ig; # re|i|nau|gu|rar
266 0 s{^re(?=[u]\|?[ntsr])}{re|}ig; # re|u|so
267 0 s{(?<=^vi\|de\|)o($vogal)}{o|$1}ig; # vi|de|o|a|ma|dor
268  
269 0 s{^su\|b(?!$vogal)}{sub|}ig;
270 0 s{(?<=[\|\-])su\|b(?!$vogal)}{sub|}ig;
271 0 s{^sub\|l(?=i\|?m)}{su|bl}ig; # su|bli|mar (excepção, compostas: sub|li|mi|nar sub|li|mi|te)
272 0 s{(?<=\|)sub\|l(?=i\|?m)}{su|bl}ig;
273 0 s{^sub\|l(?=i\|?nh)}{su|bl}ig; # (excepção: sublinha)
274 0 s{(?<=\|)sub\|l(?=i\|?nh)}{su|bl}ig;
275 0 s{^sub\|s(?=\|?$vogal)}{sub|s}ig;
276 0 s{(?<=\|)sub\|s(?=\|?$vogal)}{sub|s}ig;
277 0 s{^sub\|s(?=\|?$consoante)}{subs|}ig;
278 0 s{(?<=\|)sub\|s(?=\|?$consoante)}{subs|}ig;
279  
280 0 s{so\|bs}{sobs}ig; # de|sobs|tru|ir
281  
282 0 s{(?<=\|)trai(?=\|d)}{tra|i}ig; # re|tra|i|da|men|te ; des|con|tra|i|da|men|te
283  
284 0 s{^e\|cze}{ec|ze}ig; # ec|ze|ma
285  
286 0 s{^ex\|tra(?=$vogal)}{ex|tra|}ig; # ex|tra|or|di|na|ri|a|men|te
287  
288 0 s{u\|i$}{ui}ig; # institui ; chui ;
289 0 s{\|?ói([ao])$}{ói|$1}ig; # jóia clarabóia
290 0 s{ei([oa])(?=$|\-)}{ei|$1}ig; # ma|ré-chei|a mei|a-ir|mã meio
291  
292 0 s{^a\|([bd])([svqnmgfz])($vogal)}{a$1|$2$3}ig; # ab|sin|to
293 0 s{(?<=\|)a\|([bd])([svqnmgfz])($vogal)}{a$1|$2$3}ig; # re|ab|sor|ção
294 0 s{^a\|(b)(r)(o)(?=\|g)}{a$1|$2$3}ig; # ab|ro|ga|ção
295 0 s{^a\|([bd])([s])\|?($consoante)}{a$1$2|$3}ig; # abs|trac|to
296 0 s{^o\|([bd])([svqnmgfz])($vogal)}{o$1|$2$3}ig; # ob|ser|var
297 0 s{^o\|([bd])([s])\|?($consoante)}{o$1$2|$3}ig; # obs|tru|ir
298 0 s{([qg]u)\|([aeií])}{$1$2}i;
299 0 s{([qg]u)\|([o])$}{$1$2}i; # ambíguo; contíguo
300  
301 0 s{^($consoante)\|}{$1}i;
302 #s{êm$}{ê|_nhem}i; # removido após reunião do P-Pal a 2010-06-01
303  
304 0 s{tun\|gs}{tungs}ig; # tungsténio
305  
306 0 s{p\|s$}{ps}i; # excepção de "ps" como breakpair
307 0 s{(^p|\-p)\|s([ií])}{$1s$2}i; # excepção de "ps" como breakpair => mé|di|co-psi|co|ló|gi|co
308  
309 0 s{s\|s$}{ss}i; # excepção de "ss" como breakpair => fitness
310  
311 0 s{\|\|}{\|}g;
312 }
313 $p
314 0 }
315  
316 # carregar ficheiros necessários para transcrição fonética
317 sub initPhon
318 0 ▶{
Subroutine initPhon: not called CC=1 SCAR=6.9
Pod documented
319 0 our $dic = carregaDicionario($ptpho);
320 0 our $no_accented = chargeNoAccented($naoacentuadas);
321 }
322  
323 # transcrição fonética
324 0 ▶sub toPhon {
Subroutine toPhon: not called CC=11 SCAR=48.8
Pod documented
325 0 my $word = shift;
326 0 my $prefix = undef;
327 0 my $res = undef;
328 0 $word = lc($word);
329  
330 0 ▶ unless ($word =~ /,/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($word =~ /,/l) 0 0 0
331 0 $res = gfdict($word,$dic); #$dic->{$word};
332 # $res = "$dic->{$1}S" if(!$res && $word =~ /(.*)s$/ );
333
334 0 ▶ unless ($res || length($word)<3) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res or length $word < 3) 0 0 0
Condition0%0/3
$res or length $word < 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$res or length $word < 3
$res length $word < 3
Truth table0%0/3
A or B
A= $resB= length $word < 3
ABresult
1X1
011
000
335  
336 0 $prefix = $word;
337 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
($res or $prefix =~ /^\w\*/l) or do { do { $prefix =~ s/\*$//gl; $prefix =~ s/.$/*/l; $res = $Lingua::PT::PLN::dic->{$prefix} } } 0 0 0
Condition0%0/3
$res or $prefix =~ /^\w\*/l
l!l&&r!l&&!r
000
MC/DC0%0/2
$res or $prefix =~ /^\w\*/l
$res $prefix =~ /^\w\*/l
Truth table0%0/3
A or B
A= $resB= $prefix =~ /^\w\*/l
ABresult
1X1
011
000
338 0 $prefix =~ s{\*$}{}g;
339 0 $prefix =~ s{.$}{*};
340 0 $res = $dic->{$prefix};
341 } until ($res || $prefix =~ m!^\w\*! );
342 }
343  
344 0 ▶ if (defined($prefix)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prefix) 0 0 0
345 0 ▶ if ($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 0 0
346 0 $prefix =~ s{\*$}{}g;
347 0 $res =~ s{\*$}{}g;
348 0 $word =~ s/^$prefix/$res/;
349 0 undef($res);
350 }
351 }
352 }
353 0 ▶ if ($res) {
Branch: 2 branches
BranchTrueFalseTotal
if ($res) { } 0 0 0
elsif ($Lingua::PT::PLN::no_accented->{$word}) { } 0 0 0
354 0 ▶ if ($res =~ /^!/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res =~ /^!/l) 0 0 0
355 0 $res = toPhon2($');
356 }
357 } elsif ($no_accented->{$word}) {
358 0 $res = Lingua::PT::PLN::Words2Sampa::run($word, 0); # debug = 0
359 } else {
360 0 $res = toPhon2($word);
361 }
362 0 return $res;
363 }
364  
365 sub toPhon2
366 0 ▶{
Subroutine toPhon2: not called CC=1 SCAR=6.9
Pod documented
367 0 my $word = shift;
368 0 my $t = wordaccent($word, 1);
369 0 $t =~ s/\|//g;
370 0 return Lingua::PT::PLN::Words2Sampa::run($t, 0); # debug = 0
371 }
372  
373 0 ▶sub chargeNoAccented {
Subroutine chargeNoAccented: not called CC=3 SCAR=24.8
Pod documented
374 0 my $file = shift;
375 0 my $dic;
376 0 ▶ open F, $file or die ("cannot open dictionary file: $!");
Branch: 1 branch
BranchTrueFalseTotal
open F, $file or die "cannot open dictionary file: $!" 0 0 0
377 0 ▶ while(<F>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline F)) 0 0 0
378 0 chomp;
379 0 $dic->{$_}++;
380 }
381 0 close F;
382 0 return $dic;
383 }
384  
385 0 ▶sub carregaDicionario {
Subroutine carregaDicionario: not called CC=3 SCAR=24.8
Pod documented
386 0 my $file = shift;
387 0 my $dic;
388 0 ▶ open F, $file or die ("cannot open dicionary file: $!");
Branch: 1 branch
BranchTrueFalseTotal
open F, $file or die "cannot open dicionary file: $!" 0 0 0
389 0 ▶ while(<F>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline F)) 0 0 0
390 0 chomp;
391 0 my ($a,$b) = split /=/;
392 0 $dic->{$a}=$b;
393 }
394 0 close F;
395 0 return $dic;
396 }
397  
398 0 ▶sub gfdict{
Subroutine gfdict: not called CC=6 SCAR=37.4
Pod documented
399 0 my ($word,$dic) = @_;
400 0 ▶ return "" unless ($word =~ /\w/);
Branch: 1 branch
BranchTrueFalseTotal
unless $word =~ /\w/l 0 0 0
401 0 my $res = $dic->{$word};
402 0 ▶ unless($res){ $res = $dic->{$1} if( $word =~ /^(.*)s$/ );
Branch: 2 branches
BranchTrueFalseTotal
unless ($res) 0 0 0
if $word =~ /^(.*)s$/l 0 0 0
403 0 ▶ return "" unless ($res);
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
404 0 ▶ if($res =~ /^!/) {$res .= "s"}
Branch: 1 branch
BranchTrueFalseTotal
if ($res =~ /^!/l) { } 0 0 0
405 0 else {$res .= "S"}
406 }
407 0 $res;
408 }
409  
410 0 ▶sub compara {
Subroutine compara: not called CC=1 SCAR=6.9
Pod documented
411 # ordena pela lista de palavras invertida
412 0 join(" ", reverse(split(" ",$a))) cmp join(" ", reverse(split(" ",$b)));
413 }
414  
415 0 ▶sub compacta {
Subroutine compacta: not called CC=3 SCAR=24.8
Pod documented
416 0 my $s;
417 0 my $p = shift;
418 0 my $r = $p;
419 0 my $q = $names{$p};
420 0 ▶ while ($s = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s = shift()) 0 0 0
421 0 ▶ if ($s =~ (/^(.+) $p/))
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(.+) $p/l) { } 0 0 0
422 {
423 0 $r = "($1) $r" ;
424 0 $q += $names{$s};
425 }
426 else
427 {
428 0 print "$r - $q";
429 0 $r = $s;
430 0 $q = $names{$s};
431 }
432 0 $p=$s;
433 }
434 0 print "$r - $q";
435 }
436  
437 4 my %savit_p = ();
438 4 my $savit_n = 0;
439  
440 0 ▶sub _savit {
Subroutine _savit: not called CC=1 SCAR=6.9
441 0 my $a = shift;
442 0 $savit_p{++$savit_n} = $a ;
443 0 " __MARCA__$savit_n "
444 }
445  
446 0 ▶sub _loadit {
Subroutine _loadit: not called CC=1 SCAR=6.9
447 0 my $a = shift;
448 0 $a =~ s/ ?__MARCA__(\d+) ?/$savit_p{$1}/g;
449 0 $savit_n = 0;
450 0 $a;
451 }
452  
453 4 1;
454  
455 #sub setlogmax{
456 # $maxlog = shift;
457 # $magicF=$maxlog/log($lmax);
458 ### print "Debud .... Maxlog=$maxlog; magic=$magicF\n";
459 #}
460  
461 0 ▶sub _setmax{
Subroutine _setmax: not called CC=1 SCAR=6.9
462 0 $lmax = shift;
463 0 $magicF=$maxlog/log($lmax);
464 ## print "Debud .... Max=$lmax; magic=$magicF\n";
465 }
466  
467 0 ▶sub _logit{
Subroutine _logit: not called CC=2 SCAR=17.9
468 0 my $n=shift;
469 0 ▶ return 0 unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 0 0
470 ## print STDERR "...$n,", log($n*$magicF) ,"\n" ;
471 0 log($n)*$magicF
472 }
473  
474 4 1;
475  
476 __END__
« PLN/Words2Sampa.pm ↑ Summary