blib/lib/Lingua/FI/Kontti.pm

filter: Statementstmt 94.1% 96 / 102 Branchbran 89.2% 50 / 56 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 89.8% 151 / 168 CC 31 SCAR 33.8
CC
31
Cov
91%
kontita
32.0
BEGIN
1.0
BEGIN
1.0
CRAP 29.3
↑ Summary
1 package Lingua::FI::Kontti;
2  
3 =pod
4  
5 =head1 NAME
6  
7 Lingua::FI::Kontti - Finnish Pig Latin (kontinkieli)
8  
9 =head1 NIMI
10  
11 Lingua::FI::Kontti - kontinkieli
12  
13 =head1 SYNOPSIS
14  
15 use Lingua::FI::Kontti qw(kontita);
16  
17 print kontita("on meillä hauska täti"), "\n";
18 # will print "kon ontti keillä montti kauska hontti koti täntti\n";
19  
20 print kontita("on meillä hauska täti", "tunkki"), "\n";
21 # will print "tun onkki teillä munkki tauska hunkki tuti tänkki\n";
22  
23 =head1 KÄYTTÖ
24  
25 use Lingua::FI::Kontti qw(kontita);
26  
27 print kontita("on meillä hauska täti"), "\n";
28 # tulostaa "kon ontti keillä montti kauska hontti koti täntti\n";
29  
30 print kontita("on meillä hauska täti", "tunkki"), "\n";
31 # tulostaa "tun onkki teillä munkki tauska hunkki tuti tänkki\n";
32  
33 =head1 DESCRIPTION
34  
35 Similar to Pig Latin of English
36  
37 English We're gonna rock around the clock tonight
38 Pig Latin E'reway onnagay ockray aroundway ethay ockclay onighttay
39  
40 there's a tongue-and-brain-twisting "secret" kids' language for
41 Finnish, called "kontinkieli" ("kontti speak"). In principle the
42 transformation is simple: the beginning of the word you want to
43 translate is switched with the beginning of the word "kontti". In
44 practice it's a little bit more complicated that that because one has
45 to know the Finnish syllable division and vowel harmony rules.
46  
47 With this module you can converse like a pro with Finnish kids.
48  
49 In addition to the standard "secret key" I<kontti> you can use
50 any other word that according to Finnish syllable division rules
51 starts with CVCC (consonant-vowel-consonant-constant) syllable,
52 like for example I<kirppu>, I<linssi>, I<portti>, I<salkku>, I<turkki>.
53 Give the keyword as the second argument.
54  
55 =head1 KUVAUS
56  
57 Tällä modulilla voit kääntää suomea kontiksi.
58  
59 "Salaisen avaimen" I<kontti> sijasta voit käyttää mitä tahansa sanaa joka
60 suomeksi tavutettuna alkaa KVKK-tavulla (konsonantti-vokaali-konsonantti-
61 konsonantti), kuten esimerkiksi I<kirppu>, I<linssi>, I<portti>, I<salkku>,
62 I<turkki>. Anna avainsana toisena argumenttina.
63  
64 Englannin puhujilla on samankaltainen lastenkieli, "sikalatina" (Pig Latin),
65 yllä esimerkki.
66  
67 =head1 ACKNOWLEDGEMENTS
68  
69 =over 4
70  
71 =item *
72  
73 Pig Latin translator
74  
75 http://www.snowcrest.net/donnelly/piglatin.html
76  
77 =item *
78  
79 Rock Around the Clock
80  
81 Bill Haley and the Comets
82  
83 =back
84  
85 =head1 KIITOKSET
86  
87 =over 4
88  
89 =item *
90  
91 Sikalatinakäännin
92  
93 http://www.snowcrest.net/donnelly/piglatin.html
94  
95 =item *
96  
97 Rock Around the Clock
98  
99 Bill Haley and the Comets
100  
101 =back
102  
103 =head1 AUTHOR
104  
105 Jarkko Hietaniemi <jhi@iki.fi>
106  
107 =head1 COPYRIGHT
108  
109 Copyright 2001 Jarkko Hietaniemi
110  
111 =head1 LICENSE
112  
113 This library is free software; you can redistribute it and/or modify
114 it under the same terms as Perl itself.
115  
116 =head1 TEKIJÄ
117  
118 Jarkko Hietaniemi <jhi@iki.fi>
119  
120 =head1 TEKIJÄNOIKEUS
121  
122 Copyright 2001 Jarkko Hietaniemi
123  
124 =head1 LISENSSI
125  
126 Tämä kirjastomoduli on vapaa; voit jakaa ja/tai muuttaa sitä samojen
127 ehtojen mukaisesti kuin Perliä itseään.
128  
129 =cut
130  
131 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
132  
133 1 ▶use vars qw($VERSION @ISA @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
134  
135 1 $VERSION = 0.02;
136  
137 1 require Exporter;
138 1 @ISA = qw(Exporter);
139 1 @EXPORT_OK = qw(kontita);
140  
141 1 ▶use Lingua::FI::Hyphenate 'tavuta';
Subroutine BEGIN: called CC=1 SCAR=0.0
142  
143 1 my $vp = "aeiouyäåö";
144 1 my $vI = "AEIOUYÅÄÖ";
145 1 my $v = "$vp$vI";
146 1 my $kp = "bcdfghjklmnpqrstvwxz";
147 1 my $kI = "BCDFGHJKLMNPQRSTVWXZ";
148 1 my $k = "$kp$kI";
149 1 my $V = "[$v]";
150 1 my $K = "[$k]";
151 1 my $p = "$vp$kp";
152 1 my $I = "$vI$kI";
153  
154 43 ▶sub kontita {
Subroutine kontita: called CC=31 SCAR=34.7
Pod undocumented
155 43 my $s = shift;
156  
157 43 ▶ my $kontti = @_ ? shift : "kontti";
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 43 43
158  
159 43 my @ak = tavuta($kontti);
160  
161 43 ▶ die "kontita: '$kontti' ei ala KVKK\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $ak[0] =~ /^($K)($V)($K)($K)/ 0 43 43
162 unless $ak[0] =~ /^($K)($V)($K)($K)/;
163  
164 43 my $k1 = substr($kontti, 0, 1);
165 43 my $v1 = substr($kontti, 1, 1);
166 43 my $k2 = substr($kontti, 2, 1);
167 43 my $k3 = substr($kontti, 3, 1);
168  
169 43 my $kontitettu = '';
170  
171 43 for my $s (split(/([$v$k]+)/, $s)) {
172 86 ▶ $kontitettu .= $s, next unless $s =~ /[$v$k]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /[$v$k]/ 43 43 86
173 43 my @k = @ak;
174 43 my @t = tavuta($s);
175 43 ▶ if ($t[0] =~ /^($K)($V)$/) { # talo
Branch: 15 branches
BranchTrueFalseTotal
if ($t[0] =~ /^($K)($V)$/) { } 4 39 43
elsif ($t[0] =~ /^($K)($V)($K)$/) { } 1 38 39
elsif ($t[0] =~ /^($K)($V)($V)$/) { } 9 29 38
elsif ($t[0] =~ /^($K)($V)($V)($K)$/) { } 7 22 29
elsif ($t[0] =~ /^($V)($K)$/) { } 4 18 22
elsif ($t[0] =~ /^($V)$/) { } 5 13 18
elsif ($t[0] =~ /^($V)($V)$/) { } 4 9 13
elsif ($t[0] =~ /^($K)($V)($K)($K)$/) { } 0 9 9
elsif ($t[0] =~ /^($V)($V)($K)$/) { } 2 7 9
elsif ($t[0] =~ /^($V)($K)($K)$/) { } 1 6 7
elsif ($t[0] =~ /^($K)($K)($V)$/) { } 2 4 6
elsif ($t[0] =~ /^($K)($K)($V)($K)$/) { } 1 3 4
elsif ($t[0] =~ /^($K)($K)($V)($V)$/) { } 2 1 3
elsif ($t[0] =~ /^($K)($K)($V)($V)($K)$/) { } 0 1 1
elsif ($t[0] =~ /^($K)($K)($V)($K)($K)$/) { } 1 0 1
176 4 $t[0] = $k1 . $v1 ; # kolo
177 4 $k[0] = $1 . $2 . $k2 . $k3; # tantti
178 } elsif ($t[0] =~ /^($K)($V)($K)$/) { # marras
179 1 $t[0] = $k1 . $v1 . $3; # korras
180 1 $k[0] = $1 . $2 . $k2 . $k3; # mantti
181 } elsif ($t[0] =~ /^($K)($V)($V)$/) {
182 9 ▶ if ($2 eq $3) { # saari
Branch: 2 branches
BranchTrueFalseTotal
if ($2 eq $3) { } 4 5 9
elsif ($3 eq $v1) { } 1 4 5
183 4 $t[0] = $k1 . $v1 . $v1; # koori
184 4 $k[0] = $1 . $2 . $k2 . $k3; # santti
185 } elsif ($3 eq $v1) { # huomenta
186 1 $t[0] = $k1 . $v1 . $2; # koumenta
187 1 $k[0] = $1 . $2 . $k2 . $k3; # huntti
188 } else { # taivas
189 4 $t[0] = $k1 . $v1 . $3; # koivas
190 4 $k[0] = $1 . $2 . $k2 . $k3; # tantti
191 }
192 } elsif ($t[0] =~ /^($K)($V)($V)($K)$/) {
193 7 ▶ if ($2 eq $3) { # saarni
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq $3) { } 2 5 7
194 2 $t[0] = $k1 . $v1 . $v1 . $4; # koorni
195 2 $k[0] = $1 . $2 . $k2 . $k3; # kantti
196 } else { # hiekka
197 5 $t[0] = $k1 . $2 . $3 . $4; # kiekka
198 5 $k[0] = $1 . $v1 . $k2 . $k3; # hontti
199 }
200 } elsif ($t[0] =~ /^($V)($K)$/) { # alku
201 4 $t[0] = $k1 . $v1 . $2; # kolku
202 4 $k[0] = $1 . $k2 . $k3; # antti
203 } elsif ($t[0] =~ /^($V)$/) { # ase
204 5 $t[0] = $k1 . $v1; # kose
205 5 $k[0] = $1 . $k2 . $k3; # antti
206 } elsif ($t[0] =~ /^($V)($V)$/) {
207 4 ▶ if ($1 eq $2) { # aari
Branch: 2 branches
BranchTrueFalseTotal
if ($1 eq $2) { } 1 3 4
elsif ($2 eq "\366") { } 1 2 3
208 1 $t[0] = $k1 . $v1 . $v1; # koori
209 1 $k[0] = $1 . $k2 . $k3; # antti
210 } elsif ($2 eq 'ö') { # yö
211 1 $t[0] = $k1 . $2 . $1; # köy
212 1 $k[0] = $1 . $k2 . $k3; # yntti
213 } else { # autio
214 2 $t[0] = $k1 . $v1 . $2; # koutio
215 2 $k[0] = $1 . $k2 . $k3; # antti
216 }
217 } elsif ($t[0] =~ /^($K)($V)($K)($K)$/) { # tausta
218 0 $t[0] = $k1 . $v1 . $3 . $4; # kousta
219 0 $k[0] = $1 . $2 . $k2 . $k3; # tantti
220 } elsif ($t[0] =~ /^($V)($V)($K)$/) {
221 2 ▶ if ($1 eq $2) { # aarni
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq $2) { } 1 1 2
222 1 $t[0] = $k1 . $v1 . $v1 . $3; # koorni
223 1 $k[0] = $1 . $k2 . $k3; # antti
224 } else { # aukko
225 1 $t[0] = $k1 . $v1 . $2 . $3; # koukko
226 1 $k[0] = $1 . $k2 . $k3; # antti
227 }
228 } elsif ($t[0] =~ /^($V)($K)($K)$/) { # arkku
229 1 $t[0] = $k1 . $v1 . $2 . $3; # korkku
230 1 $k[0] = $1 . $k2 . $k3; # antti
231 } elsif ($t[0] =~ /^($K)($K)($V)$/) { # trapetsi
232 2 $t[0] = $k1 . $v1; # kopetsi
233 2 $k[0] = $1 . $2 . $3 . $k2 . $k3; # trantti
234 } elsif ($t[0] =~ /^($K)($K)($V)($K)$/) { # traktori
235 1 $t[0] = $k1 . $2 . $v1 . $4; # kroktori
236 1 $k[0] = $1 . $3 . $k2 . $k3; # tantti
237 } elsif ($t[0] =~ /^($K)($K)($V)($V)$/) {
238 2 ▶ if ($3 eq $4) { # traani
Branch: 1 branch
BranchTrueFalseTotal
if ($3 eq $4) { } 1 1 2
239 1 $t[0] = $k1 . $v1 . $v1; # kooni
240 1 $k[0] = $1 . $2 . $3 . $k2 . $k3; # trantti
241 } else { # trauma
242 1 $t[0] = $k1 . $v1 . $4; # kouma
243 1 $k[0] = $1 . $2 . $3 . $k2 . $k3; # trantti
244 }
245 } elsif ($t[0] =~ /^($K)($K)($V)($V)($K)$/) { # truantti
246 0 $t[0] = $k1 . $v1 . $4 . $5; # koantti
247 0 $k[0] = $1 . $2 . $3 . $k2 . $k3; # trantti
248 } elsif ($t[0] =~ /^($K)($K)($V)($K)($K)$/) { # transsi
249 1 $t[0] = $k1 . $v1 . $4 . $5; # konssi
250 1 $k[0] = $1 . $2 . $3 . $k2 . $k3; # trantti
251 }
252
253 # vokaalisointu
254  
255 43 ▶ @t = map { tr/aouAOU/äöyÄÖY/; $_ } @t if grep { /[yäöYÄÖ]/ } @t;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/[y\344\366Y\304\326]/;} @t 9 34 43
256 43 ▶ @k = map { tr/aouAOU/äöyÄÖY/; $_ } @k if grep { /[yäöYÄÖ]/ } @k;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/[y\344\366Y\304\326]/;} @k 11 32 43
257  
258 # Iso alkukirjain
259 43 my $a = substr($t[0], 0, 1);
260 43 my $b = substr($k[0], 0, 1);
261 43 ▶ if ($a =~ /^[$p]/ && $b =~ /^[$I]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a =~ /^[$p]/ and $b =~ /^[$I]/) 0 43 43
Condition33%1/3
$a =~ /^[$p]/ and $b =~ /^[$I]/
!ll&&!rl&&r
0430
MC/DC0%0/2
$a =~ /^[$p]/ and $b =~ /^[$I]/
$a =~ /^[$p]/ $b =~ /^[$I]/
Truth table33%1/3
A and B
A= $a =~ /^[$p]/B= $b =~ /^[$I]/
ABresult
0X0
100
111
262 0 substr($t[0], 0, 1) = substr($I, index($p, $a), 1);
263 0 substr($k[0], 0, 1) = substr($p, index($I, $b), 1);
264 }
265  
266 43 $kontitettu .= join("", @t) . " " . join("", @k)
267 }
268  
269 43 return $kontitettu;
270 }
271  
272 1 1;
↑ Summary