blib/lib/Lingua/YI/Romanize.pm

filter: Statementstmt 100% 62 / 62 Branchbran 100% 4 / 4 Conditioncond 100% 2 / 3 (1 uncoverable) MC/DCmcdc 100% 0 / 2 (2 uncoverable) Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 100% 81 / 84 (3 uncoverable) CC 8 SCAR 7.8
CC
8
Cov
100%
new
4.0
_gen_charclass
2.0
_normalize
2.0
CRAP 2.2
↑ Summary
1 package Lingua::YI::Romanize;
2 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $VERSION = '0.02';
8  
9 4 ▶use Unicode::Normalize;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 our $normalize_combinings;
12 4 our $yivo2latn;
13 4 our $vowels;
14 4 our $consonants;
15 4 our $consonants_2;
16  
17  
18 6 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
19 6 my $class = shift;
20 # uncoverable condition false
21 6 ▶ bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class;
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 3 3 6
@_ > 1 ? : 1 2 3
Condition100%2/3
ref $class || $class
l!l&&r!l&&!r
420
MC/DC100%0/2
ref $class || $class
ref $class $class
Truth table100%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
22 }
23  
24 15 ▶sub _gen_charclass {
Subroutine _gen_charclass: called CC=2 SCAR=6.9
25 15 my $chartable = shift;
26 15 my $string;
27 15 for my $cons (@{$chartable}) {
28 225 $string .= $cons->[0];
29 }
30 15 return join('|',split('',$string));
31 }
32  
33 5 ▶sub _normalize {
Subroutine _normalize: called CC=2 SCAR=6.9
34 5 my $string = shift;
35 5 for my $rule (@$normalize_combinings) {
36 85 $string =~ s/$rule->[0]/$rule->[1]/g;
37 }
38 5 return $string;
39 }
40  
41 2 ▶sub yivo2latn {
Subroutine yivo2latn: called CC=2 SCAR=6.9
Pod documented
42 2 my ($self, $text) = @_;
43 2 my $string = _normalize(NFC($text));
44  
45 2 my $cons_2 = _gen_charclass($consonants_2);;
46 2 my $cons = _gen_charclass($consonants);
47 2 my $vowels = _gen_charclass($vowels);
48  
49 # "\x{05D9}" HEBREW LETTER YOD|י|y, i
50 # 1.1. y before or after a vowel;
51 # i between consonants;
52 # y after ‫ ט‬t, ‫ ד‬d, ‫ ס‬s, ‫ ז‬z, ‫ ל‬l, ‫ נ‬n; and before a vowel
53 # indicates the palatals in words of Slavic origin.
54  
55 2 $string =~ s/\x{05D9}($vowels)/y$1/g;
56 2 $string =~ s/($vowels)\x{05D9}/${1}y/g;
57 2 $string =~ s/($cons_2)\x{05D9}/${1}y/g;
58 2 $string =~ s/($cons)\x{05D9}($cons)/${1}i${2}/g;
59 2 $string =~ s/\x{05D9}/i/g;
60  
61 2 for my $rule (@$yivo2latn) {
62 88 $string =~ s/$rule->[0]/$rule->[1]/g;
63 }
64 2 return $string;
65 }
66  
67 3 ▶sub yivo2ipa {
Subroutine yivo2ipa: called CC=2 SCAR=6.9
Pod documented
68 3 my ($self, $text) = @_;
69 3 my $string = _normalize(NFC($text));
70  
71 3 my $cons_2 = _gen_charclass($consonants_2);;
72 3 my $cons = _gen_charclass($consonants);
73 3 my $vowels = _gen_charclass($vowels);
74  
75 # "\x{05D9}" HEBREW LETTER YOD|י|y, i
76 # 1.1. y before or after a vowel;
77 # i between consonants;
78 # y after ‫ ט‬t, ‫ ד‬d, ‫ ס‬s, ‫ ז‬z, ‫ ל‬l, ‫ נ‬n; and before a vowel
79 # indicates the palatals in words of Slavic origin.
80  
81 3 $string =~ s/\x{05D9}($vowels)/j$1/g;
82 3 $string =~ s/($vowels)\x{05D9}/${1}j/g;
83 3 $string =~ s/($cons)\x{05D9}($cons)/${1}i${2}/g;
84 3 $string =~ s/($cons_2)\x{05D9}/${1}j/g;
85  
86  
87 3 for my $rule (@$yivo2latn) {
88 132 $string =~ s/$rule->[0]/$rule->[2]/g;
89 }
90 3 return $string;
91 }
92  
93 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
94 4 $normalize_combinings = [
95 ["\x{05D0}\x{05B7}","\x{FB2E}"], # HEBREW LETTER ALEF WITH PATAH
96 ["\x{05D0}\x{05B8}","\x{FB2F}"], # HEBREW LETTER ALEF WITH QAMATS
97 ["\x{05D1}\x{05BC}","\x{FB31}"], # HEBREW LETTER BET WITH DAGESH
98 ["\x{05D1}\x{05BF}","\x{FB4C}"], # HEBREW LETTER BET WITH RAFE
99 ["\x{05D5}\x{05BC}","\x{FB35}"], # HEBREW LETTER VAV WITH DAGESH
100 ["\x{05D5}\x{05D5}","\x{05F0}"], # HEBREW LIGATURE YIDDISH DOUBLE VAV
101 ["\x{05D5}\x{05D9}","\x{05F1}"], # HEBREW LIGATURE YIDDISH VAV YOD
102 ["\x{05D9}\x{05B4}","\x{FB1D}"], # HEBREW LETTER YOD WITH HIRIQ
103 ["\x{05D9}\x{05D9}","\x{05F2}"], # HEBREW LIGATURE YIDDISH DOUBLE YOD
104 ["\x{05F2}\x{05B7}","\x{FB1F}"], # HEBREW LIGATURE YIDDISH YOD YOD PATAH
105 ["\x{05DB}\x{05BC}","\x{FB3B}"], # HEBREW LETTER KAF WITH DAGESH
106 ["\x{05E4}\x{05BC}","\x{FB44}"], # HEBREW LETTER PE WITH DAGESH
107 ["\x{05E4}\x{05BF}","\x{FB4E}"], # HEBREW LETTER PE WITH RAFE
108 ["\x{05E9}\x{05C2}","\x{FB2B}"], # HEBREW LETTER SHIN WITH SIN DOT
109 ["\x{05EA}\x{05BC}","\x{FB4A}"], # HEBREW LETTER TAV WITH DAGESH
110 ["\x{FB20}","\x{05E2}"], # HEBREW LETTER ALTERNATIVE AYIN
111 ["\x{05E4}","\x{05BF}"], # HEBREW LETTER PE
112 ];
113  
114  
115 4 $yivo2latn = [
116 ["\x{05D3}\x{05D6}\x{05E9}", 'dzh', 'd͡ʒ'],
117 ["\x{05D6}\x{05E9}", 'zh', 'ʒ' ],
118 ["\x{05D8}\x{05E9}", 'tsh', 't͡ʃ'],
119 ["\x{05D0}", '', '' ],
120 ["\x{FB2E}", 'a', 'a' ],
121 ["\x{FB2F}", 'o', 'ɔ' ],
122 ["\x{05D1}", 'b', 'b' ],
123 ["\x{FB31}", '', 'b' ],
124 ["\x{FB4C}", 'v', 'v' ],
125 ["\x{05D2}", 'g', 'ɡ' ],
126 ["\x{05D3}", 'd', 'd' ],
127 ["\x{05D4}", 'h', 'h' ],
128 ["\x{05D5}", 'u', 'ʊ' ],
129 ["\x{FB35}", 'u', 'ʊ' ],
130 # "\x{05D5}" HEBREW LETTER VAV,
131 # "\x{05B9}" HEBREW POINT HOLAM
132 # |וֹ|(none)|(none)|ɔ, ɔj|(o,oj)|khoylem|Non-YIVO alternative to אָ and וי.
133 ["\x{05F0}", 'v', 'v' ],
134 ["\x{05F1}", 'oy', 'ɔj' ],
135 ["\x{05D6}", 'z', 'z' ],
136 ["\x{05D7}", 'kh', 'x' ],
137 ["\x{05D8}", 't', 't' ],
138 # TODO "\x{05D9}" HEBREW LETTER YOD
139 # |י|y, i|y, i|j, i|j, i|yud|Consonantal [j]
140 # when the first character in a syllable. Vocalic [i] otherwise.
141 ["\x{FB1D}", 'i', 'i' ],
142 ["\x{05F2}", 'ey', 'ɛj' ],
143 ["\x{FB1F}", 'ay', 'aj' ],
144 ["\x{FB3B}", 'k', 'k' ],
145 ["\x{05DB}", 'kh', 'x' ],
146 ["\x{05DA}", 'kh', 'x' ],
147 ["\x{05DC}", 'l', 'l' ], # TODO: ʎ
148 ["\x{05DE}", 'm', 'm' ],
149 ["\x{05DD}", 'm', 'm' ],
150 ["\x{05E0}", 'n', 'n' ],
151 ["\x{05DF}", 'n', 'n' ], # TODO: ŋ, m
152 ["\x{05E1}", 's', 's' ],
153 ["\x{05E2}", 'e', 'ɛ' ], # TODO: ə
154 ["\x{FB44}", 'p', 'p' ],
155 ["\x{FB4E}", 'f', 'f' ],
156 ["\x{05E3}", 'f', 'f' ],
157 ["\x{05BF}", 'f', 'f' ],
158 ["\x{05E6}", 'ts', 'ts' ],
159 ["\x{05E5}", 'ts', 'ts' ],
160 ["\x{05E7}", 'k', 'k' ],
161 ["\x{05E8}", 'r', 'ʀ' ],
162 ["\x{05E9}", 'sh', 'ʃ' ],
163 ["\x{FB2B}", 's', 's' ],
164 ["\x{FB4A}", 't', 't' ],
165 ["\x{05EA}", 's', 's' ],
166 ];
167  
168 4 $vowels = [
169 ["\x{FB2E}",'a'],
170 ["\x{FB2F}",'o'],
171 ["\x{05D5}",'u'],
172 ["\x{FB35}",'u'],
173 ["\x{05F1}",'oy'],
174 # TODO "\x{05D9}" HEBREW LETTER YOD|י|y, i|y, i|j, i|j, i|yud|Consonantal [j] when the first character in a syllable. Vocalic [i] otherwise.
175 ["\x{FB1D}",'i'],
176 ["\x{05F2}",'ey'],
177 ["\x{FB1F}",'ay'],
178 ["\x{05E2}",'e'],
179 ];
180  
181 4 $consonants = [
182 ["\x{05D1}",'b'],
183 ["\x{FB4C}",'v'],
184 ["\x{05D2}",'g'],
185 ["\x{05D3}",'d'],
186 ["\x{05D4}",'h'],
187 ["\x{05F0}",'v'],
188 ["\x{05D6}",'z'],
189 ["\x{05D7}",'kh'],
190 ["\x{05D8}",'t'],
191 ["\x{FB3B}",'k'],
192 ["\x{05DB}",'kh'],
193 ["\x{05DA}",'kh'],
194 ["\x{05DC}",'l'],
195 ["\x{05DE}",'m'],
196 ["\x{05DD}",'m'],
197 ["\x{05E0}",'n'],
198 ["\x{05DF}",'n'],
199 ["\x{05E1}",'s'],
200 ["\x{FB44}",'p'],
201 ["\x{FB4E}",'f'],
202 ["\x{05E3}",'f'],
203 ["\x{05BF}",'f'],
204 ["\x{05E6}",'ts'],
205 ["\x{05E5}",'ts'],
206 ["\x{05E7}",'k'],
207 ["\x{05E8}",'r'],
208 ["\x{05E9}",'sh'],
209 ["\x{FB2B}",'s'],
210 ["\x{FB4A}",'t'],
211 ["\x{05EA}",'s'],
212 ];
213  
214 4 $consonants_2 = [
215  
216 ["\x{05D3}",'d'],
217 ["\x{05D6}",'z'],
218 ["\x{05D8}",'t'],
219 ["\x{05DC}",'l'],
220 ["\x{05E0}",'n'],
221 ["\x{05E1}",'s'],
222 #["\x{FB4A}",'t'],
223 ];
224 }
225  
226 4 1;
227  
228 __END__
↑ Summary