| 1 | package Lingua::Han::CanonicalPinYin; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = 0.04; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | our @EXPORT_OK = 'canonicalize_pinyin'; | |||||||||||||||||||||||||||
| 10 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | my @tones = ( "\x{304}", "\x{301}", "\x{30c}", "\x{300}" ); | |||||||||||||||||||||||||||
| 13 | 80 | ▶ | sub canonicalize_pinyin { | ||||||||||||||||||||||||||
|
Subroutine
canonicalize_pinyin: called CC=10 SCAR=24.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 80 | my $pinyin = lc shift; | |||||||||||||||||||||||||||
| 15 | 80 | ▶ | $pinyin = decode_utf8( $pinyin ) unless utf8::is_utf8( $pinyin ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 80 | my $tone; | |||||||||||||||||||||||||||
| 17 | 80 | ▶ | ($pinyin, $tone) = ( $1, $2 ) if $pinyin =~ /^(.*)(\d)$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 80 | ▶ | return $pinyin if ! defined $tone || $tone == 5; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $tone or $tone == 5
MC/DC0%0/2
not defined $tone or $tone == 5
not defined $tone
$tone == 5
Truth table33%1/3
not(A) or B
A= not defined $toneB= $tone == 5
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 80 | ▶ | if ( $tone < 1 || $tone > 5 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$tone < 1 or $tone > 5
MC/DC0%0/2
$tone < 1 or $tone > 5
$tone < 1
$tone > 5
Truth table33%1/3
A or B
A= $tone < 1B= $tone > 5
| |||||||||||||||||||||||||||||
| 21 | 0 | die "invalid pinyin $pinyin: tone $tone doesn't exist"; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 80 | $tone = $tones[$tone-1]; | |||||||||||||||||||||||||||
| 25 | 80 | for my $vowel (qw/a o e iu i u v ü/) { | |||||||||||||||||||||||||||
| 26 | 280 | ▶ | if ( $pinyin =~ /$vowel/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 80 | ▶ | if ( $vowel eq 'v' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 4 | $pinyin =~ s/v/u\x{308}$tone/; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | else { | ||||||||||||||||||||||||||||
| 31 | 76 | $pinyin =~ s/$vowel/$vowel$tone/; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 80 | last; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 80 | $pinyin =~ s/v/ü/g; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 80 | return $pinyin; | |||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | 1; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | __END__ | ||||||||||||||||||||||||||||