line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::Han::CanonicalPinYin; |
2
|
2
|
|
|
2
|
|
66185
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
88
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
105
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = 0.04; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
13
|
use base 'Exporter'; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
413
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = 'canonicalize_pinyin'; |
10
|
2
|
|
|
2
|
|
2989
|
use utf8; |
|
2
|
|
|
|
|
59
|
|
|
2
|
|
|
|
|
11
|
|
11
|
2
|
|
|
2
|
|
5266
|
use Encode; |
|
2
|
|
|
|
|
75116
|
|
|
2
|
|
|
|
|
828
|
|
12
|
|
|
|
|
|
|
my @tones = ( "\x{304}", "\x{301}", "\x{30c}", "\x{300}" ); |
13
|
|
|
|
|
|
|
sub canonicalize_pinyin { |
14
|
80
|
|
|
80
|
0
|
38016
|
my $pinyin = lc shift; |
15
|
80
|
100
|
|
|
|
362
|
$pinyin = decode_utf8( $pinyin ) unless utf8::is_utf8( $pinyin ); |
16
|
80
|
|
|
|
|
1276
|
my $tone; |
17
|
80
|
50
|
|
|
|
519
|
($pinyin, $tone) = ( $1, $2 ) if $pinyin =~ /^(.*)(\d)$/; |
18
|
80
|
50
|
33
|
|
|
414
|
return $pinyin if ! defined $tone || $tone == 5; |
19
|
|
|
|
|
|
|
|
20
|
80
|
50
|
33
|
|
|
315
|
if ( $tone < 1 || $tone > 5 ) { |
21
|
0
|
|
|
|
|
0
|
die "invalid pinyin $pinyin: tone $tone doesn't exist"; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
80
|
|
|
|
|
130
|
$tone = $tones[$tone-1]; |
25
|
80
|
|
|
|
|
134
|
for my $vowel (qw/a o e iu i u v ü/) { |
26
|
280
|
100
|
|
|
|
2765
|
if ( $pinyin =~ /$vowel/ ) { |
27
|
80
|
100
|
|
|
|
180
|
if ( $vowel eq 'v' ) { |
28
|
4
|
|
|
|
|
16
|
$pinyin =~ s/v/u\x{308}$tone/; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
76
|
|
|
|
|
388
|
$pinyin =~ s/$vowel/$vowel$tone/; |
32
|
|
|
|
|
|
|
} |
33
|
80
|
|
|
|
|
138
|
last; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
80
|
|
|
|
|
159
|
$pinyin =~ s/v/ü/g; |
37
|
|
|
|
|
|
|
|
38
|
80
|
|
|
|
|
285
|
return $pinyin; |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |