line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::AIN::Romanize; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
427864
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
153
|
|
4
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
110
|
|
5
|
4
|
|
|
4
|
|
21
|
use Carp; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
493
|
|
6
|
4
|
|
|
4
|
|
3917
|
use version; our $VERSION = qv('0.0.2'); |
|
4
|
|
|
|
|
26922
|
|
|
4
|
|
|
|
|
29
|
|
7
|
4
|
|
|
4
|
|
542
|
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
391
|
|
8
|
4
|
|
|
4
|
|
24
|
use Exporter; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
452
|
|
9
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
@EXPORT = qw(ain_kana2roman ain_roman2kana); |
11
|
|
|
|
|
|
|
@EXPORT_OK = qw(ain_setregex %Ain_Roman2Kana %Ain_Kana2Roman @Ain_VplusiuCase); |
12
|
|
|
|
|
|
|
%EXPORT_TAGS = (setregex => [qw(ain_kana2roman ain_roman2kana ain_setregex %Ain_Roman2Kana %Ain_Kana2Roman @Ain_VplusiuCase)]); |
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
4
|
|
12230
|
use Lingua::JA::Kana; |
|
4
|
|
|
|
|
425327
|
|
|
4
|
|
|
|
|
2200
|
|
15
|
4
|
|
|
4
|
|
64
|
use utf8; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
57
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# 母音 |
18
|
|
|
|
|
|
|
our $Re_Vowels = $Lingua::JA::Kana::Re_Vowels; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# 子音 |
21
|
|
|
|
|
|
|
our $Re_Consonants = qr/[ptksmnwyrhc]/i; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# 撥音用 |
24
|
|
|
|
|
|
|
our $Re_Consonants_t = qr/[ptkcs]/i; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
################################# |
28
|
|
|
|
|
|
|
# ローマ字 -> カナ関連 |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# ローマ字⇒カナ |
31
|
|
|
|
|
|
|
our %Ain_Roman2Kana = ( |
32
|
|
|
|
|
|
|
%Lingua::JA::Kana::Romaji2Kata, |
33
|
|
|
|
|
|
|
qw( |
34
|
|
|
|
|
|
|
ca チャ ci チ cu チュ ce チェ co チョ |
35
|
|
|
|
|
|
|
wo ウォ wu ウ yi イ ya ヤ |
36
|
|
|
|
|
|
|
'a ア 'i イ 'u ウ 'e エ 'o オ |
37
|
|
|
|
|
|
|
), |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
our $Re_Roman2Kata = qr/(?:[aeiou]|s(?:[aeiou]|h[aiou]|y[aou])|d(?:[eiou]|h[aeiou]|y?a)|t(?:[aeio]|y[aeou]|s?u)|x(?:[aeio]|y[aou]|t?u)|c(?:[aeiou]|h[aeiou])|b(?:[aeiou]|y[aou])|h(?:[aeiou]|y[aou])|k(?:[aeiou]|y[aou])|p(?:[aeiou]|y[aou])|'[aeiou]|f[aeiou]|g[aeiou]|l[aeiou]|m[aeiou]|n[aeiou]|r[aeiou]|v[aeiou]|w[aeiou]|y[aeiou]|z[aeiou]|j[aiou])/i; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# 閉音節r |
44
|
|
|
|
|
|
|
our $Re_R_Close = qr/($Re_Vowels)r(?!$Re_Vowels)/i; |
45
|
|
|
|
|
|
|
our %R_Close; |
46
|
|
|
|
|
|
|
$R_Close{hankaku} = {qw( a ラ i リ u ル e レ o ロ )}; |
47
|
|
|
|
|
|
|
$R_Close{unicode} = {qw( a ㇻ i ㇼ u ㇽ e ㇾ o ㇿ )}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# 閉音節h(樺太方言) |
50
|
|
|
|
|
|
|
our $Re_H_Close = qr/($Re_Vowels)h(?!$Re_Vowels)/i; |
51
|
|
|
|
|
|
|
our %H_Close; |
52
|
|
|
|
|
|
|
$H_Close{hankaku} = {qw( a ハ i ヒ u フ e ヘ o ホ )}; |
53
|
|
|
|
|
|
|
$H_Close{unicode} = {qw( a ㇵ i ㇶ u ㇷ e ㇸ o ㇹ )}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# 長音化(樺太方言) |
56
|
|
|
|
|
|
|
our $Re_Long = qr/($Re_Vowels)\1/i; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# その他の閉音節 |
59
|
|
|
|
|
|
|
our $Re_O_Close = qr/(([ptkwysn])(?!$Re_Vowels|\2)|m(?!$Re_Vowels|[mp]))/i; |
60
|
|
|
|
|
|
|
our %O_Close; |
61
|
|
|
|
|
|
|
$O_Close{hankaku} = {qw( p プ t ッ k ク w ウ y イ s シ m ム n ン )}; |
62
|
|
|
|
|
|
|
$O_Close{unicode} = {qw( p ㇷ゚ t ッ k ㇰ w ウ y イ s ㇱ m ㇺ n ン )}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub ain_roman2kana { |
65
|
19
|
|
|
19
|
1
|
87719
|
my $str = shift; |
66
|
19
|
|
50
|
|
|
64
|
my $opt = shift || {}; |
67
|
|
|
|
|
|
|
|
68
|
19
|
100
|
|
|
|
54
|
my $code = $opt->{hankaku} ? 'hankaku' : 'unicode'; |
69
|
19
|
|
50
|
|
|
89
|
my $kara = $opt->{karafuto} || 0; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# 人称の区切りの=を削除 |
72
|
19
|
|
|
|
|
73
|
$str =~ s/[==]//msxgi; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# r閉音節を置き換える |
75
|
19
|
|
|
|
|
41
|
my $R_Close = $R_Close{$code}; |
76
|
19
|
|
|
|
|
347
|
$str =~ s{ $Re_R_Close }{ |
77
|
8
|
|
|
|
|
45
|
$1 . $R_Close->{$1}; |
78
|
|
|
|
|
|
|
}msxgei; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# h閉音節を置き換える(樺太方言) |
81
|
19
|
|
|
|
|
39
|
my $H_Close = $H_Close{$code}; |
82
|
19
|
|
|
|
|
220
|
$str =~ s{ $Re_H_Close }{ |
83
|
0
|
|
|
|
|
0
|
$1 . $H_Close->{$1}; |
84
|
|
|
|
|
|
|
}msxgei; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# 長音化(樺太方言) |
87
|
19
|
50
|
|
|
|
51
|
if ( $kara ) { |
88
|
0
|
|
|
|
|
0
|
$str =~ s{ $Re_Long }{ |
89
|
0
|
|
|
|
|
0
|
$1 . 'ー'; |
90
|
|
|
|
|
|
|
}msxgei; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# その他の閉音節 |
94
|
19
|
|
|
|
|
36
|
my $O_Close = $O_Close{$code}; |
95
|
19
|
|
|
|
|
212
|
$str =~ s{ $Re_O_Close }{ |
96
|
13
|
|
|
|
|
73
|
$O_Close->{$1}; |
97
|
|
|
|
|
|
|
}msxgei; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
19
|
|
|
|
|
3570
|
local %Lingua::JA::Kana::Romaji2Kata = %Ain_Roman2Kana; |
101
|
19
|
|
|
|
|
362
|
local $Lingua::JA::Kana::Re_Romaji2Kata = $Re_Roman2Kata; |
102
|
19
|
|
|
|
|
24
|
local $Lingua::JA::Kana::Re_Consonants = $Re_Consonants_t; |
103
|
|
|
|
|
|
|
|
104
|
19
|
|
|
|
|
68
|
romaji2katakana( $str ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
################################# |
109
|
|
|
|
|
|
|
# カナ -> ローマ字関連 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# カナ⇒ローマ字 |
112
|
|
|
|
|
|
|
our %Ain_Kana2Roman = ( |
113
|
|
|
|
|
|
|
%Lingua::JA::Kana::Kata2Hepburn, |
114
|
|
|
|
|
|
|
qw( |
115
|
|
|
|
|
|
|
ア 'a イ 'i ウ 'u エ 'e オ 'o |
116
|
|
|
|
|
|
|
チャ ca チ ci チュ cu チェ ce チョ co |
117
|
|
|
|
|
|
|
シ si トゥ tu |
118
|
|
|
|
|
|
|
), |
119
|
|
|
|
|
|
|
qw( |
120
|
|
|
|
|
|
|
ラ r リ r ル r レ r ロ r ㇻ r ㇼ r ㇽ r ㇾ r ㇿ r |
121
|
|
|
|
|
|
|
ハ h ヒ h フ h ヘ h ホ h ㇵ h ㇶ h ㇷ h ㇸ h ㇹ h |
122
|
|
|
|
|
|
|
ㇷ゚ p プ p ッ t ク k シ s ム m |
123
|
|
|
|
|
|
|
ㇱ s ン n ㇰ k ㇺ m |
124
|
|
|
|
|
|
|
), |
125
|
|
|
|
|
|
|
); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#our $Re_Kana2Roman = qr/(?-xism:(?:[ァアィゥェエォオカガギクグケゲコゴサザスズセゼソゾタダツヅナニヌネノハバパブプヘベペホボポマミムメモャヤュユョヨラルレロワヰヱヲン]|ウ[ァィェォ]?|チ[ェャュョ]?|ヂ[ェャュョ]?|フ[ァィェォ]?|ヴ[ァィェォ]?|キ[ャュョ]?|シ[ャュョ]?|ジ[ャュョ]?|ヒ[ャュョ]?|ビ[ャュョ]?|ピ[ャュョ]?|リ[ャュョ]?|イェ?|ティ?|ディ?|トゥ?|ドゥ?))/; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
our $Re_Kana2Roman = qr/(?-xism:(?:[ァアィゥェエォオカガギクグケゲコゴサザスズセゼソゾタダッツヅナニヌネノハバパブプヘベペホボポマミムメモャヤュユョヨラルレロワヰヱヲンㇰㇱㇵㇶㇸㇹㇺㇻㇼㇽㇾㇿクシハヒヘホムラリルレロ]|ウ[ァィェォ]?|チ[ェャュョ]?|ヂ[ェャュョ]?|フ[ァィェォ]?|ヴ[ァィェォ]?|キ[ャュョ]?|シ[ャュョ]?|ジ[ャュョ]?|ヒ[ャュョ]?|ビ[ャュョ]?|ピ[ャュョ]?|リ[ャュョ]?|イェ?|ティ?|ディ?|トゥ?|ドゥ?|ㇷ゚?|プ?))/; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
## 閉音節r |
132
|
|
|
|
|
|
|
#our $Re_R_Close_Rv = qr/[ラリルレロㇻㇼㇽㇾㇿ]/; |
133
|
|
|
|
|
|
|
# |
134
|
|
|
|
|
|
|
## 閉音節h(樺太方言) |
135
|
|
|
|
|
|
|
#our $Re_H_Close_Rv = qr/[ハヒフヘホㇵㇶㇷㇸㇹ]/; |
136
|
|
|
|
|
|
|
# |
137
|
|
|
|
|
|
|
## その他の閉音節 |
138
|
|
|
|
|
|
|
#our $Re_O_Close_Rv = qr/(ㇷ゚|プ|[ックシムンㇰㇱㇺ])/; |
139
|
|
|
|
|
|
|
#our %O_Close_Rv = qw( ㇷ゚ p プ p ッ t ク k シ s ム m |
140
|
|
|
|
|
|
|
# ㇱ s ン n ㇰ k ㇺ m ); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# 母音+i、母音+uになるケース用 |
143
|
|
|
|
|
|
|
our @Ain_VplusiuCase = qw( \biyairaykere\b ); # とにかくケースを集める |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
our $Re_VplusiuCase; |
146
|
|
|
|
|
|
|
our %Hs_VplusiuCase; |
147
|
|
|
|
|
|
|
&ain_setregex_vc; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub ain_kana2roman { |
150
|
16
|
|
|
16
|
1
|
43368
|
my $str = shift; |
151
|
16
|
|
50
|
|
|
61
|
my $opt = shift || {}; |
152
|
|
|
|
|
|
|
|
153
|
16
|
|
50
|
|
|
85
|
my $kara = $opt->{karafuto} || 0; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# # r閉音節を置き換える |
156
|
|
|
|
|
|
|
# $str =~ s{ $Re_R_Close_Rv }{ |
157
|
|
|
|
|
|
|
# 'r'; |
158
|
|
|
|
|
|
|
# }msxgei; |
159
|
|
|
|
|
|
|
# |
160
|
|
|
|
|
|
|
# # h閉音節を置き換える(樺太方言) |
161
|
|
|
|
|
|
|
# $str =~ s{ $Re_H_Close_Rv }{ |
162
|
|
|
|
|
|
|
# 'h'; |
163
|
|
|
|
|
|
|
# }msxgei; |
164
|
|
|
|
|
|
|
# |
165
|
|
|
|
|
|
|
# # その他の閉音節 |
166
|
|
|
|
|
|
|
# $str =~ s{ $Re_O_Close_Rv }{ |
167
|
|
|
|
|
|
|
# $O_Close_Rv{$1}; |
168
|
|
|
|
|
|
|
# }msxgei; |
169
|
|
|
|
|
|
|
|
170
|
16
|
|
|
|
|
1681
|
local %Lingua::JA::Kana::Kana2Romaji = %Ain_Kana2Roman; |
171
|
16
|
|
|
|
|
185
|
local $Lingua::JA::Kana::Re_Kana2Romaji = $Re_Kana2Roman; |
172
|
|
|
|
|
|
|
|
173
|
16
|
|
|
|
|
62
|
$str = kana2romaji( $str ); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# 母音+i => y, 母音+u => w |
176
|
16
|
|
|
|
|
1084
|
$str =~ s{ ($Re_Vowels)'?([iu]) }{ |
177
|
8
|
|
|
|
|
13
|
my $ret; |
178
|
8
|
50
|
|
|
|
31
|
if ( $1 eq $2 ) { |
179
|
0
|
|
|
|
|
0
|
$ret = $1.$2; |
180
|
|
|
|
|
|
|
} else { |
181
|
8
|
50
|
|
|
|
33
|
$ret = $1 . ( $2 eq 'i' ? 'y' : 'w' ); |
182
|
|
|
|
|
|
|
} |
183
|
8
|
|
|
|
|
29
|
$ret; |
184
|
|
|
|
|
|
|
}msxgei; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# 子音後に続かない母音の'を取る |
187
|
16
|
|
|
|
|
146
|
$str =~ s{(?
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# 撥音処理 |
190
|
16
|
|
|
|
|
163
|
$str =~ s{t($Re_Consonants)}{$1$1}msgxi; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# m/p前のンはm |
193
|
16
|
|
|
|
|
52
|
$str =~ s{n([mp])}{m$1}msgxi; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# 母音+i、母音+uになるケース用 |
196
|
16
|
|
|
|
|
69
|
$str =~ s{$Re_VplusiuCase}{$Hs_VplusiuCase{$1}}msgxei; |
|
1
|
|
|
|
|
6
|
|
197
|
|
|
|
|
|
|
|
198
|
16
|
|
|
|
|
335
|
$str; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub ain_setregex { |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
0
|
1
|
0
|
eval 'require Regexp::Assemble'; ## no critic |
204
|
|
|
|
|
|
|
|
205
|
0
|
0
|
|
|
|
0
|
croak 'ain_setregex function needs Regexp::Assemble module' if ( $@ ); |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
0
|
$Re_Roman2Kata = do { |
208
|
0
|
|
|
|
|
0
|
my $ra = Regexp::Assemble->new(); |
209
|
0
|
|
|
|
|
0
|
$ra->add($_) for keys %Ain_Roman2Kana; |
210
|
0
|
|
|
|
|
0
|
my $str = $ra->re; |
211
|
0
|
|
|
|
|
0
|
substr( $str, 0, 8, '' ); # remove '(?-xism:' |
212
|
0
|
|
|
|
|
0
|
substr( $str, -1, 1, '' ); # and ')'; |
213
|
0
|
|
|
|
|
0
|
qr/$str/i; # and recompile with i |
214
|
|
|
|
|
|
|
}; |
215
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
0
|
$Re_Kana2Roman = do { |
217
|
0
|
|
|
|
|
0
|
my $ra = Regexp::Assemble->new(); |
218
|
0
|
|
|
|
|
0
|
$ra->add($_) for keys %Ain_Kana2Roman; |
219
|
0
|
|
|
|
|
0
|
$ra->re; |
220
|
|
|
|
|
|
|
}; |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
0
|
&ain_setregex_vc; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub ain_setregex_vc { |
226
|
4
|
|
|
4
|
1
|
21
|
$Re_VplusiuCase = ''; |
227
|
4
|
|
|
|
|
9
|
%Hs_VplusiuCase = (); |
228
|
4
|
|
|
|
|
13
|
foreach my $key ( @Ain_VplusiuCase ) { |
229
|
4
|
|
|
|
|
9
|
my $from = $key; |
230
|
4
|
|
|
|
|
7
|
my $to = $key; |
231
|
|
|
|
|
|
|
|
232
|
4
|
50
|
|
|
|
140
|
$from =~ s{($Re_Vowels)([iu])}{ $1 . ($2 eq 'i' ? 'y' : 'w') }ge; |
|
4
|
|
|
|
|
48
|
|
233
|
|
|
|
|
|
|
|
234
|
4
|
50
|
|
|
|
16
|
$Re_VplusiuCase .= $Re_VplusiuCase eq '' ? '(' : '|'; |
235
|
4
|
|
|
|
|
7
|
$Re_VplusiuCase .= $from; |
236
|
|
|
|
|
|
|
|
237
|
4
|
|
|
|
|
29
|
$from =~ s/\\b//g; |
238
|
4
|
|
|
|
|
13
|
$to =~ s/\\b//g; |
239
|
|
|
|
|
|
|
|
240
|
4
|
|
|
|
|
26
|
$Hs_VplusiuCase{$from} = $to; |
241
|
|
|
|
|
|
|
} |
242
|
4
|
|
|
|
|
8
|
$Re_VplusiuCase .= ')'; |
243
|
4
|
|
|
|
|
50
|
$Re_VplusiuCase = qr/$Re_VplusiuCase/i; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
1; |
248
|
|
|
|
|
|
|
__END__ |