File Coverage

blib/lib/Lingua/YI/Romanize.pm
Criterion Covered Total %
statement 55 55 100.0
branch 4 4 100.0
condition 2 3 100.0
subroutine 10 10 100.0
pod 3 3 100.0
total 74 75 100.0


line stmt bran cond sub pod time code
1             package Lingua::YI::Romanize;
2 3     3   1825 use utf8;
  3         5  
  3         22  
3              
4 3     3   85 use strict;
  3         3  
  3         61  
5 3     3   25 use warnings;
  3         10  
  3         147  
6              
7             our $VERSION = '0.01';
8              
9 3     3   2060 use Unicode::Normalize;
  3         512556  
  3         3386  
10              
11             our $normalize_combinings;
12             our $yivo2latn;
13             our $vowels;
14             our $consonants;
15             our $consonants_2;
16              
17              
18             sub new {
19 6     6 1 699 my $class = shift;
20             # uncoverable condition false
21 6 100 66     37 bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class;
  2 100       11  
22             }
23              
24             sub _gen_charclass {
25 12     12   13 my $chartable = shift;
26 12         9 my $string;
27 12         11 for my $cons (@{$chartable}) {
  12         68  
28 180         192 $string .= $cons->[0];
29             }
30 12         61 return join('|',split('',$string));
31             }
32              
33             sub _normalize {
34 4     4   123914 my $string = shift;
35 4         17 for my $rule (@$normalize_combinings) {
36 68         2074 $string =~ s/$rule->[0]/$rule->[1]/g;
37             }
38 4         12 return $string;
39             }
40              
41             sub yivo2latn {
42 2     2 1 417 my ($self, $text) = @_;
43 2         8 my $string = _normalize(NFC($text));
44              
45 2         443 my $cons_2 = _gen_charclass($consonants_2);;
46 2         6 my $cons = _gen_charclass($consonants);
47 2         10 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         280 $string =~ s/\x{05D9}($vowels)/y$1/g;
56 2         173 $string =~ s/($vowels)\x{05D9}/${1}y/g;
57 2         151 $string =~ s/($cons_2)\x{05D9}/${1}y/g;
58 2         329 $string =~ s/($cons)\x{05D9}($cons)/${1}i${2}/g;
59 2         69 $string =~ s/\x{05D9}/i/g;
60              
61 2         25 for my $rule (@$yivo2latn) {
62 88         2459 $string =~ s/$rule->[0]/$rule->[1]/g;
63             }
64 2         62 return $string;
65             }
66              
67             sub yivo2ipa {
68 2     2 1 330 my ($self, $text) = @_;
69 2         7 my $string = _normalize(NFC($text));
70              
71 2         406 my $cons_2 = _gen_charclass($consonants_2);;
72 2         5 my $cons = _gen_charclass($consonants);
73 2         6 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 2         260 $string =~ s/\x{05D9}($vowels)/j$1/g;
82 2         120 $string =~ s/($vowels)\x{05D9}/${1}j/g;
83 2         276 $string =~ s/($cons)\x{05D9}($cons)/${1}i${2}/g;
84 2         89 $string =~ s/($cons_2)\x{05D9}/${1}j/g;
85              
86              
87 2         8 for my $rule (@$yivo2latn) {
88 88         2359 $string =~ s/$rule->[0]/$rule->[2]/g;
89             }
90 2         54 return $string;
91             }
92              
93             BEGIN {
94 3     3   22 $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 3         50 $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,"\x{05B9}" HEBREW POINT HOLAM|וֹ|(none)|(none)|ɔ, ɔj|(o,oj)|khoylem|Non-YIVO alternative to אָ and וי.
131             ["\x{05F0}",'v','v'],
132             ["\x{05F1}",'oy','ɔj'],
133             ["\x{05D6}",'z','z'],
134             ["\x{05D7}",'kh','x'],
135             ["\x{05D8}",'t','t'],
136             # 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.
137             ["\x{FB1D}",'i','i'],
138             ["\x{05F2}",'ey','ɛj'],
139             ["\x{FB1F}",'ay','aj'],
140             ["\x{FB3B}",'k','k'],
141             ["\x{05DB}",'kh','x'],
142             ["\x{05DA}",'kh','x'],
143             ["\x{05DC}",'l','l'], # TODO: ʎ
144             ["\x{05DE}",'m','m'],
145             ["\x{05DD}",'m','m'],
146             ["\x{05E0}",'n','n'],
147             ["\x{05DF}",'n','n'], # TODO: ŋ, m
148             ["\x{05E1}",'s','s'],
149             ["\x{05E2}",'e','ɛ'], # TODO: ə
150             ["\x{FB44}",'p','p'],
151             ["\x{FB4E}",'f','f'],
152             ["\x{05E3}",'f','f'],
153             ["\x{05BF}",'f','f'],
154             ["\x{05E6}",'ts','ts'],
155             ["\x{05E5}",'ts','ts'],
156             ["\x{05E7}",'k','k'],
157             ["\x{05E8}",'r','ʀ'],
158             ["\x{05E9}",'sh','ʃ'],
159             ["\x{FB2B}",'s','s'],
160             ["\x{FB4A}",'t','t'],
161             ["\x{05EA}",'s','s'],
162             ];
163              
164 3         22 $vowels = [
165             ["\x{FB2E}",'a'],
166             ["\x{FB2F}",'o'],
167             ["\x{05D5}",'u'],
168             ["\x{FB35}",'u'],
169             ["\x{05F1}",'oy'],
170             # 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.
171             ["\x{FB1D}",'i'],
172             ["\x{05F2}",'ey'],
173             ["\x{FB1F}",'ay'],
174             ["\x{05E2}",'e'],
175             ];
176              
177 3         24 $consonants = [
178             ["\x{05D1}",'b'],
179             ["\x{FB4C}",'v'],
180             ["\x{05D2}",'g'],
181             ["\x{05D3}",'d'],
182             ["\x{05D4}",'h'],
183             ["\x{05F0}",'v'],
184             ["\x{05D6}",'z'],
185             ["\x{05D7}",'kh'],
186             ["\x{05D8}",'t'],
187             ["\x{FB3B}",'k'],
188             ["\x{05DB}",'kh'],
189             ["\x{05DA}",'kh'],
190             ["\x{05DC}",'l'],
191             ["\x{05DE}",'m'],
192             ["\x{05DD}",'m'],
193             ["\x{05E0}",'n'],
194             ["\x{05DF}",'n'],
195             ["\x{05E1}",'s'],
196             ["\x{FB44}",'p'],
197             ["\x{FB4E}",'f'],
198             ["\x{05E3}",'f'],
199             ["\x{05BF}",'f'],
200             ["\x{05E6}",'ts'],
201             ["\x{05E5}",'ts'],
202             ["\x{05E7}",'k'],
203             ["\x{05E8}",'r'],
204             ["\x{05E9}",'sh'],
205             ["\x{FB2B}",'s'],
206             ["\x{FB4A}",'t'],
207             ["\x{05EA}",'s'],
208             ];
209              
210 3         121 $consonants_2 = [
211              
212             ["\x{05D3}",'d'],
213             ["\x{05D6}",'z'],
214             ["\x{05D8}",'t'],
215             ["\x{05DC}",'l'],
216             ["\x{05E0}",'n'],
217             ["\x{05E1}",'s'],
218             #["\x{FB4A}",'t'],
219             ];
220             }
221              
222             1;
223              
224             __END__