| 1 | # Korean Transliterator Generator | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | # $Id: TransliteratorGenerator.pm,v 1.7 2007/11/29 14:25:31 you Exp $ | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | package Encode::Korean::TransliteratorGenerator; | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 11 | our $VERSION = do { q$Revision: 1.7 $ =~ /\d+\.(\d+)/; sprintf "%.2f", $1 / 100 }; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use 5.008008; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | # == CONSTANTS == | ||||||||||||||||||||||||||||||||
| 14 | 11 | my $NotFound = '-1'; | |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 11 | my $CamelCase = 0; | |||||||||||||||||||||||||||||||
| 17 | 11 | my $GREEDY_SEP =1; | |||||||||||||||||||||||||||||||
| 18 | 11 | my $SMART_SEP = 2; | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 11 | my %MODE = ( | |||||||||||||||||||||||||||||||
| 21 | 'CamelCase' => $CamelCase, | ||||||||||||||||||||||||||||||||
| 22 | 'camel' => $CamelCase, | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 'greedy_sep' => $GREEDY_SEP, | ||||||||||||||||||||||||||||||||
| 25 | 'greedy' => $GREEDY_SEP, | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 'smart_sep' => $SMART_SEP, | ||||||||||||||||||||||||||||||||
| 28 | 'smart' => $SMART_SEP | ||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | # == CONSTRUCTOR == | ||||||||||||||||||||||||||||||||
| 32 | 11 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 33 | 11 | my ($class) = @_; | |||||||||||||||||||||||||||||||
| 34 | 11 | my $self = { | |||||||||||||||||||||||||||||||
| 35 | CONSONANTS => [], | ||||||||||||||||||||||||||||||||
| 36 | VOWELS => [], | ||||||||||||||||||||||||||||||||
| 37 | EL => undef, | ||||||||||||||||||||||||||||||||
| 38 | ELL => undef, | ||||||||||||||||||||||||||||||||
| 39 | NAUGHT => undef, | ||||||||||||||||||||||||||||||||
| 40 | SEP => undef, | ||||||||||||||||||||||||||||||||
| 41 | ENMODE => [], | ||||||||||||||||||||||||||||||||
| 42 | DEMODE => [], | ||||||||||||||||||||||||||||||||
| 43 | HEAD => [], | ||||||||||||||||||||||||||||||||
| 44 | BODY => [], | ||||||||||||||||||||||||||||||||
| 45 | FOOT => [], | ||||||||||||||||||||||||||||||||
| 46 | HEADMAP => {}, | ||||||||||||||||||||||||||||||||
| 47 | BODYMAP => {}, | ||||||||||||||||||||||||||||||||
| 48 | FOOTMAP => {} | ||||||||||||||||||||||||||||||||
| 49 | }; | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 11 | bless $self, $class; | |||||||||||||||||||||||||||||||
| 52 | 11 | return $self; | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | # == METHODS == | ||||||||||||||||||||||||||||||||
| 56 | # accessor | ||||||||||||||||||||||||||||||||
| 57 | 67 | ▶ | sub consonants { | ||||||||||||||||||||||||||||||
|
Subroutine
consonants: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 58 | 67 | my $self = shift; | |||||||||||||||||||||||||||||||
| 59 | 67 | ▶ | if(@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | 11 | @{ $self->{CONSONANTS} } = @_; | |||||||||||||||||||||||||||||||
| 61 | 11 | $self->head(@_); | |||||||||||||||||||||||||||||||
| 62 | 11 | @ { $self->{FOOT} } = ( | |||||||||||||||||||||||||||||||
| 63 | '', # NULL | ||||||||||||||||||||||||||||||||
| 64 | $self->{CONSONANTS}->[0], # kiyeok (ㄱ) | ||||||||||||||||||||||||||||||||
| 65 | $self->{CONSONANTS}->[1], # ssangkiyeok (ㄲ) | ||||||||||||||||||||||||||||||||
| 66 | $self->{CONSONANTS}->[0] . $self->{CONSONANTS}->[9], # kiyeok sios (ㄳ) | ||||||||||||||||||||||||||||||||
| 67 | $self->{CONSONANTS}->[2], # nieun (ㄴ) | ||||||||||||||||||||||||||||||||
| 68 | $self->{CONSONANTS}->[2] . $self->{CONSONANTS}->[12], # nieun cieuc (ㄵ) | ||||||||||||||||||||||||||||||||
| 69 | $self->{CONSONANTS}->[2] . $self->{CONSONANTS}->[18], # nieun hieuh (ㄶ) | ||||||||||||||||||||||||||||||||
| 70 | $self->{CONSONANTS}->[3], # tikeut (ㄷ) | ||||||||||||||||||||||||||||||||
| 71 | $self->{CONSONANTS}->[5], # rieul (ㄹ) | ||||||||||||||||||||||||||||||||
| 72 | $self->{CONSONANTS}->[5] . $self->{CONSONANTS}->[0], # rieul kiyeok (ㄺ) | ||||||||||||||||||||||||||||||||
| 73 | $self->{CONSONANTS}->[5] . $self->{CONSONANTS}->[6], # rieul mieum (ㄻ) | ||||||||||||||||||||||||||||||||
| 74 | $self->{CONSONANTS}->[5] . $self->{CONSONANTS}->[7], # rieul pieup (ㄼ) | ||||||||||||||||||||||||||||||||
| 75 | $self->{CONSONANTS}->[5] . $self->{CONSONANTS}->[9], # rieul sios (ㄽ) | ||||||||||||||||||||||||||||||||
| 76 | $self->{CONSONANTS}->[5] . $self->{CONSONANTS}->[16], # rieul thieuth (ㄾ) | ||||||||||||||||||||||||||||||||
| 77 | $self->{CONSONANTS}->[5] . $self->{CONSONANTS}->[17], # rieul phieuph (ㄿ) | ||||||||||||||||||||||||||||||||
| 78 | $self->{CONSONANTS}->[5] . $self->{CONSONANTS}->[18], # rieul hieuh (ㅀ) | ||||||||||||||||||||||||||||||||
| 79 | $self->{CONSONANTS}->[6], # mieum (ㅁ) | ||||||||||||||||||||||||||||||||
| 80 | $self->{CONSONANTS}->[7], # pieup (ㅂ) | ||||||||||||||||||||||||||||||||
| 81 | $self->{CONSONANTS}->[7] . $self->{CONSONANTS}->[9], # pieup sios (ㅄ) | ||||||||||||||||||||||||||||||||
| 82 | $self->{CONSONANTS}->[9], # sios (ㅅ) | ||||||||||||||||||||||||||||||||
| 83 | $self->{CONSONANTS}->[10], # ssangsios (ㅆ) | ||||||||||||||||||||||||||||||||
| 84 | $self->{CONSONANTS}->[11], # ieung (ㅇ) | ||||||||||||||||||||||||||||||||
| 85 | $self->{CONSONANTS}->[12], # cieuc (ㅈ) | ||||||||||||||||||||||||||||||||
| 86 | $self->{CONSONANTS}->[14], # chieuch (ㅊ) | ||||||||||||||||||||||||||||||||
| 87 | $self->{CONSONANTS}->[15], # khieukh (ㅋ) | ||||||||||||||||||||||||||||||||
| 88 | $self->{CONSONANTS}->[16], # thieuth (ㅌ) | ||||||||||||||||||||||||||||||||
| 89 | $self->{CONSONANTS}->[17], # phieuph (ㅍ) | ||||||||||||||||||||||||||||||||
| 90 | 11 | $self->{CONSONANTS}->[18] # hieuh (ㅎ) | |||||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | 67 | return $self->{CONSONANTS}; | |||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 858 | ▶ | sub head { | ||||||||||||||||||||||||||||||
|
Subroutine
head: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 97 | 858 | my $self = shift; | |||||||||||||||||||||||||||||||
| 98 | 858 | ▶ | if (@_) { @{ $self->{HEAD} } = @_; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 99 | 858 | return $self->{HEAD}; | |||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 691 | ▶ | sub foot { | ||||||||||||||||||||||||||||||
|
Subroutine
foot: called CC=2 SCAR=8.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 103 | 691 | my $self = shift; | |||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if (@_) { @{ $self->{FOOT} } = @_; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 105 | 691 | return $self->{FOOT}; | |||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | # accessor | ||||||||||||||||||||||||||||||||
| 109 | 11 | ▶ | sub vowels { | ||||||||||||||||||||||||||||||
|
Subroutine
vowels: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 110 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||
| 111 | 11 | ▶ | if(@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 112 | 11 | @{ $self->{VOWELS} } = @_; | |||||||||||||||||||||||||||||||
| 113 | 11 | $self->body(@_); | |||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | 11 | return $self->{VOWELS}; | |||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 1177 | ▶ | sub body { | ||||||||||||||||||||||||||||||
|
Subroutine
body: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 119 | 1177 | my $self = shift; | |||||||||||||||||||||||||||||||
| 120 | 1177 | ▶ | if (@_) { @{ $self->{BODY} } = @_; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 121 | 1177 | return $self->{BODY}; | |||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | # accessor | ||||||||||||||||||||||||||||||||
| 127 | 8 | ▶ | sub el { | ||||||||||||||||||||||||||||||
|
Subroutine
el: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 128 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||
| 129 | 8 | ▶ | if(@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 130 | 8 | $self->{EL} = shift; | |||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | # Sets jongseongs with rieul | ||||||||||||||||||||||||||||||||
| 133 | 8 | $self->foot->[8] = $self->{EL}; # rieul (ㄹ) | |||||||||||||||||||||||||||||||
| 134 | 8 | $self->foot->[9] = $self->{EL} . $self->consonants->[0]; # rieul kiyeok (ㄺ) | |||||||||||||||||||||||||||||||
| 135 | 8 | $self->foot->[10] = $self->{EL} . $self->consonants->[6]; # rieul mieum (ㄻ) | |||||||||||||||||||||||||||||||
| 136 | 8 | $self->foot->[11] = $self->{EL} . $self->consonants->[7]; # rieul pieup (ㄼ) | |||||||||||||||||||||||||||||||
| 137 | 8 | $self->foot->[12] = $self->{EL} . $self->consonants->[9]; # rieul sios (ㄽ) | |||||||||||||||||||||||||||||||
| 138 | 8 | $self->foot->[13] = $self->{EL} . $self->consonants->[16]; # rieul thieuth (ㄾ) | |||||||||||||||||||||||||||||||
| 139 | 8 | $self->foot->[14] = $self->{EL} . $self->consonants->[17]; # rieul phieuph (ㄿ) | |||||||||||||||||||||||||||||||
| 140 | 8 | $self->foot->[15] = $self->{EL} . $self->consonants->[18]; # rieul hieuh (ㅀ) | |||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||
| 142 | 8 | return $self->{EL}; | |||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | # accessor | ||||||||||||||||||||||||||||||||
| 146 | 8 | ▶ | sub ell { | ||||||||||||||||||||||||||||||
|
Subroutine
ell: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 147 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||
| 148 | 8 | ▶ | if(@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 149 | 8 | $self->{ELL} = shift; | |||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||
| 151 | 8 | return $self->{ELL}; | |||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | # accessor | ||||||||||||||||||||||||||||||||
| 155 | 10 | ▶ | sub naught { | ||||||||||||||||||||||||||||||
|
Subroutine
naught: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 156 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||
| 157 | 10 | ▶ | if(@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 158 | 10 | $self->{NAUGHT} = shift; | |||||||||||||||||||||||||||||||
| 159 | 10 | $self->{HEAD}->[11] = $self->{NAUGHT}; | |||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||
| 161 | 10 | return $self->{NAUGHT}; | |||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | # accessor | ||||||||||||||||||||||||||||||||
| 165 | 11 | ▶ | sub sep { | ||||||||||||||||||||||||||||||
|
Subroutine
sep: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 166 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||
| 167 | 11 | ▶ | if(@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 168 | 11 | $self->{SEP} = shift; | |||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | 11 | return $self->{SEP}; | |||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | # accessor | ||||||||||||||||||||||||||||||||
| 174 | 12 | ▶ | sub enmode { | ||||||||||||||||||||||||||||||
|
Subroutine
enmode: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 175 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||
| 176 | 12 | ▶ | if(@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 177 | 12 | $self->{ENMODE} = shift; | |||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||
| 179 | 12 | return $self->{ENMODE}; | |||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | 10 | ▶ | sub demode { | ||||||||||||||||||||||||||||||
|
Subroutine
demode: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 183 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||
| 184 | 10 | ▶ | if(@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 185 | 10 | $self->{DEMODE} = shift; | |||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||
| 187 | 10 | return $self->{DEMODE}; | |||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | 11 | ▶ | sub make { | ||||||||||||||||||||||||||||||
|
Subroutine
make: called CC=9 SCAR=22.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 193 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | 11 | ▶ | for ( my $i=0; $i <= $#{$self->head}; ++$i ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 196 | 209 | ▶ | if ($self->head->[$i] eq "" && $i != 11) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->head->[$i] eq "" and $i != 11
MC/DC0%0/2
$self->head->[$i] eq "" and $i != 11
$self->head->[$i] eq ""
$i != 11
Truth table66%2/3
A and B
A= $self->head->[$i] eq ""B= $i != 11
| |||||||||||||||||||||||||||||||||
| 197 | #printf "error: empty slot. fill the transliteration for /%s/!<br />", | ||||||||||||||||||||||||||||||||
| 198 | # encode::encode("utf8", $han_consonant[$i]); exit(1); | ||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||
| 200 | 209 | ▶ | if (exists $self->{HEADMAP}->{$self->head->[$i]}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 201 | #print_mapping_error($self::head[$i], $self::head{$self::head[$i]}, $i); | ||||||||||||||||||||||||||||||||
| 202 | 0 | exit(1); | |||||||||||||||||||||||||||||||
| 203 | } else { | ||||||||||||||||||||||||||||||||
| 204 | 209 | $self->{HEADMAP}->{$self->head->[$i]} = $i; | |||||||||||||||||||||||||||||||
| 205 | }; | ||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | 11 | ▶ | for ( my $i=0; $i <= $#{$self->body}; ++$i ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 209 | 231 | ▶ | if ($self->body->[$i] eq "") { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 210 | #printf "error: empty slot. fill the transliteration for /%s/!<br />", | ||||||||||||||||||||||||||||||||
| 211 | # Encode::encode("utf8", $HAN_VOWEL[$i]); | ||||||||||||||||||||||||||||||||
| 212 | 0 | exit(1); | |||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||
| 214 | 231 | ▶ | if (exists $self->{BODYMAP}->{$self->body->[$i]}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 215 | #print_mapping_error($self::BODY[$i], $self::BODY{$self::BODY[$i]}, $i); | ||||||||||||||||||||||||||||||||
| 216 | 0 | exit(1); | |||||||||||||||||||||||||||||||
| 217 | } else { | ||||||||||||||||||||||||||||||||
| 218 | 231 | $self->{BODYMAP}->{$self->body->[$i]} = $i; | |||||||||||||||||||||||||||||||
| 219 | }; | ||||||||||||||||||||||||||||||||
| 220 | 231 | $self->{BODYMAP}->{$self->body->[$i]} = $i; | |||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||
| 222 | 11 | ▶ | for ( my $i=0; $i <= $#{$self->foot}; ++$i ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 223 | 308 | $self->{FOOTMAP}->{$self->foot->[$i]} = $i; | |||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | 11 | return $self; | |||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||
| 230 | # encode($string [,$check]) | ||||||||||||||||||||||||||||||||
| 231 | # = transliteration (romanization) | ||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | sub encode($$;$) { | ||||||||||||||||||||||||||||||
|
Subroutine
encode: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 233 | 0 | my ($obj, $str, $chk) = @_; | |||||||||||||||||||||||||||||||
| 234 | 0 | my $tr = $obj->transliterate($str); | |||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | $_[1] = '' if $chk; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 236 | 0 | return $tr; | |||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | # decode($octets [,$check]) | ||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | sub decode ($$;$) { | ||||||||||||||||||||||||||||||
|
Subroutine
decode: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 241 | 0 | my ($obj, $str, $chk) = @_; | |||||||||||||||||||||||||||||||
| 242 | 0 | my $han = $obj->hangulize($str); | |||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | $_[1] = '' if $chk; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 244 | 0 | return $han; | |||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | # to work with encoding pragma | ||||||||||||||||||||||||||||||||
| 248 | # cat_decode($destination, $octets, $offset, $terminator [,$check]) | ||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | # = HAN TRANSLITERATOR = | ||||||||||||||||||||||||||||||||
| 256 | # romanizer and hangulizer | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | # == hangul composer and decomposer == | ||||||||||||||||||||||||||||||||
| 259 | # | ||||||||||||||||||||||||||||||||
| 260 | # Unicode : 0xAC00 (가) -- 0xD7A3 (힣) | ||||||||||||||||||||||||||||||||
| 261 | # | ||||||||||||||||||||||||||||||||
| 262 | # foot (28 types) : 가각갂갃간갅갆갇갈갉갊갋갌갍갎갏감갑값갓갔강갖갗갘같갚갛 | ||||||||||||||||||||||||||||||||
| 263 | # body (21 types) : 가개갸걔거게겨계고과괘괴교구궈궤귀규그긔기 | ||||||||||||||||||||||||||||||||
| 264 | # head (19 types) : 가까나다따라마바빠사싸아자짜차카타파하 | ||||||||||||||||||||||||||||||||
| 265 | # | ||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | # === decompose === | ||||||||||||||||||||||||||||||||
| 269 | # decomposes an unicode hangul chr into a hancode ($head, $body, $foot) | ||||||||||||||||||||||||||||||||
| 270 | # for example, decompose('한') returns (18, 0, 4) | ||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | sub decompose { | ||||||||||||||||||||||||||||||
|
Subroutine
decompose: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 272 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | 0 | my($chr) = @_; | |||||||||||||||||||||||||||||||
| 275 | 0 | my $unicode = ord($chr); | |||||||||||||||||||||||||||||||
| 276 | 0 | my $head = int(($unicode - 0xAC00) / (28*21)); | |||||||||||||||||||||||||||||||
| 277 | 0 | my $body = int(($unicode - 0xAC00 - $head*28*21) /28); | |||||||||||||||||||||||||||||||
| 278 | 0 | my $foot = $unicode - 0xAC00 - $head*28*21 - $body*28; | |||||||||||||||||||||||||||||||
| 279 | 0 | return ($head, $body, $foot); | |||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||
| 282 | # === compose === | ||||||||||||||||||||||||||||||||
| 283 | # composes an unicode hangul chr from a hancode ($head, $body, $foot) | ||||||||||||||||||||||||||||||||
| 284 | # for example, compose((18,0,4)) returns '한' | ||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | sub compose { | ||||||||||||||||||||||||||||||
|
Subroutine
compose: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 286 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||
| 288 | 0 | my($head, $body, $foot) = @_; | |||||||||||||||||||||||||||||||
| 289 | 0 | my $unicode = 0xAC00 + $head*28*21 + $body*28 + $foot; | |||||||||||||||||||||||||||||||
| 290 | 0 | return chr($unicode); | |||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||
| 295 | # == ROMANIZE (TRANSLITERATE) == | ||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||
| 297 | # === transliterates a hangul chr (unicode hangul syllable) === | ||||||||||||||||||||||||||||||||
| 298 | # for example, transliterate('한') returns ('h', 'a', 'n') | ||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | sub transliterate_chr { | ||||||||||||||||||||||||||||||
|
Subroutine
transliterate_chr: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 300 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 301 | 0 | my($chr) = @_; | |||||||||||||||||||||||||||||||
| 302 | 0 | my($head,$body,$foot) = $self->decompose($chr); | |||||||||||||||||||||||||||||||
| 303 | #return ($self->head->[$head], $self->body->[$body], $self->foot->[$foot]); | ||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | if ($self->enmode eq 'greedy' && $head == 11) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->enmode eq "greedy" and $head == 11
MC/DC0%0/2
$self->enmode eq "greedy" and $head == 11
$self->enmode eq "greedy"
$head == 11
Truth table0%0/3
A and B
A= $self->enmode eq "greedy"B= $head == 11
| |||||||||||||||||||||||||||||||||
| 305 | 0 | return $self->body->[$body] . $self->foot->[$foot]; | |||||||||||||||||||||||||||||||
| 306 | } else { | ||||||||||||||||||||||||||||||||
| 307 | 0 | return $self->head->[$head] . $self->body->[$body] . $self->foot->[$foot]; | |||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | sub transliterate_first_chr_of_word { | ||||||||||||||||||||||||||||||
|
Subroutine
transliterate_first_chr_of_word: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 311 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 312 | 0 | my($chr) = @_; | |||||||||||||||||||||||||||||||
| 313 | 0 | my($head, $body, $foot) = $self->decompose ($chr); | |||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | if ($head == 11) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 315 | 0 | return $self->body->[$body] . $self->foot->[$foot]; | |||||||||||||||||||||||||||||||
| 316 | } else { | ||||||||||||||||||||||||||||||||
| 317 | 0 | return $self->head->[$head] . $self->body->[$body] . $self->foot->[$foot]; | |||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||
| 322 | # === transliterate a hangul word === | ||||||||||||||||||||||||||||||||
| 323 | # Transliterates a hangul word (a string containing | ||||||||||||||||||||||||||||||||
| 324 | # only hangul syllables) | ||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | sub transliterate_hangul_word { | ||||||||||||||||||||||||||||||
|
Subroutine
transliterate_hangul_word: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 326 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 327 | 0 | my($word) = @_; | |||||||||||||||||||||||||||||||
| 328 | 0 | my(@char) = split //, $word; | |||||||||||||||||||||||||||||||
| 329 | 0 | my $tr = $self->transliterate_first_chr_of_word($char[0]); | |||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | for (my $i=1; $i <= $#char; ++$i) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ($MODE{$self->enmode} == $GREEDY_SEP) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 332 | 0 | $tr = $tr . $self->sep . $self->transliterate_chr($char[$i]); | |||||||||||||||||||||||||||||||
| 333 | } else { | ||||||||||||||||||||||||||||||||
| 334 | 0 | $tr = $tr . $self->transliterate_chr($char[$i]); | |||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||
| 337 | 0 | return $tr; | |||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||
| 340 | # === transliterate a string === | ||||||||||||||||||||||||||||||||
| 341 | # The input string may contain any character. | ||||||||||||||||||||||||||||||||
| 342 | # Transliterates only unicode hangul syllables (AC00-D7A3), | ||||||||||||||||||||||||||||||||
| 343 | # returns other characters including hangul jamo (1100-11F9) | ||||||||||||||||||||||||||||||||
| 344 | # and hangul compatibility jamo. | ||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | sub transliterate_line { | ||||||||||||||||||||||||||||||
|
Subroutine
transliterate_line: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 346 | 0 | my($str) = @_; | |||||||||||||||||||||||||||||||
| 347 | 0 | my $tr; | |||||||||||||||||||||||||||||||
| 348 | 0 | my(@char) = split(//,$str); | |||||||||||||||||||||||||||||||
| 349 | 0 | foreach my $c (@char) { | |||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | if (ord($c)>=0xAC00 && ord($c)<=0xD7A3){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ord $c >= 44032 and ord $c <= 55203
MC/DC0%0/2
ord $c >= 44032 and ord $c <= 55203
ord $c >= 44032
ord $c <= 55203
Truth table0%0/3
A and B
A= ord $c >= 44032B= ord $c <= 55203
| |||||||||||||||||||||||||||||||||
| 351 | 0 | $tr = $tr . transliterate_chr($c); | |||||||||||||||||||||||||||||||
| 352 | } else { | ||||||||||||||||||||||||||||||||
| 353 | 0 | $tr = $tr . $c; | |||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||
| 356 | 0 | return $tr; | |||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||
| 359 | # === transliterate === | ||||||||||||||||||||||||||||||||
| 360 | # Transliterates word by word | ||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | sub transliterate { | ||||||||||||||||||||||||||||||
|
Subroutine
transliterate: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 362 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||
| 364 | #my($str) = @_; | ||||||||||||||||||||||||||||||||
| 365 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||
| 366 | 0 | my $tr; | |||||||||||||||||||||||||||||||
| 367 | 0 | my(@word) = split /([^\x{AC00}-\x{D7A3}]+)/, $str; | |||||||||||||||||||||||||||||||
| 368 | 0 | foreach my $w (@word) { | |||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if ($w =~ m/^[\x{AC00}-\x{D7A3}]+$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 370 | 0 | $tr = $tr . $self->transliterate_hangul_word($w); | |||||||||||||||||||||||||||||||
| 371 | } else { | ||||||||||||||||||||||||||||||||
| 372 | 0 | $tr = $tr . $w; | |||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||
| 376 | 0 | return $tr; | |||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||
| 380 | # | ||||||||||||||||||||||||||||||||
| 381 | # == HANGULIZE (REVERSE TRANSLITERATION) == | ||||||||||||||||||||||||||||||||
| 382 | # | ||||||||||||||||||||||||||||||||
| 383 | # H: head, B: body, F: foot | ||||||||||||||||||||||||||||||||
| 384 | # H?BF?(HBF?)* | ||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||
| 386 | # === hangulize === | ||||||||||||||||||||||||||||||||
| 387 | # reverse transliteration : hangulizes a transliterated strings | ||||||||||||||||||||||||||||||||
| 388 | # for example: hangulize('hangugmal') returns '한국말' | ||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | sub hangulize { | ||||||||||||||||||||||||||||||
|
Subroutine
hangulize: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 390 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 391 | 0 | my $sep = $self->sep; | |||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||
| 393 | 0 | my($str) = @_; | |||||||||||||||||||||||||||||||
| 394 | 0 | my $h; | |||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | if ($sep ne '') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 397 | 0 | my @word = split(/\Q$sep\E/, $str); | |||||||||||||||||||||||||||||||
| 398 | 0 | foreach(@word) { $h = $h . $self->get_han($_); } | |||||||||||||||||||||||||||||||
| 399 | } else { | ||||||||||||||||||||||||||||||||
| 400 | 0 | $h = $h . $self->get_han($str); | |||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||
| 402 | 0 | return $h; | |||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||
| 405 | #------------------------------ | ||||||||||||||||||||||||||||||||
| 406 | # hangulizes an array of alphabets into one hangul chr | ||||||||||||||||||||||||||||||||
| 407 | # for example, hangulize_code(('h', 'a', 'n')) returns '한' | ||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | sub hangulize_code { | ||||||||||||||||||||||||||||||
|
Subroutine
hangulize_code: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 409 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||
| 411 | 0 | my($head, $body, $foot) = @_; | |||||||||||||||||||||||||||||||
| 412 | 0 | my @hancode = ($self->{HEADMAP}->{$head}, $self->{BODYMAP}->{$body}, $self->{FOOTMAP}->{$foot}); | |||||||||||||||||||||||||||||||
| 413 | 0 | return $self->compose(@hancode); | |||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||
| 417 | #------------------------------- | ||||||||||||||||||||||||||||||||
| 418 | # lookup $str, @list_of_jamo_transliteration | ||||||||||||||||||||||||||||||||
| 419 | # eg. lookup('ssan', @CONSONANT) returns ('ss', 'an') | ||||||||||||||||||||||||||||||||
| 420 | # where @CONSONANT has an item 'ss' | ||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | sub lookup { | ||||||||||||||||||||||||||||||
|
Subroutine
lookup: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 422 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||
| 424 | 0 | my($str, @where) = @_; | |||||||||||||||||||||||||||||||
| 425 | 0 | my $found = $NotFound; | |||||||||||||||||||||||||||||||
| 426 | 0 | my $rest = $str; | |||||||||||||||||||||||||||||||
| 427 | 0 | foreach(@where) { | |||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | if ($_ eq substr($str, 0, length($_))) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | if ($found eq $NotFound) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 430 | 0 | $found = $_; | |||||||||||||||||||||||||||||||
| 431 | 0 | $rest = substr($str, length($_)); | |||||||||||||||||||||||||||||||
| 432 | } elsif (length($found) < length($_)) { | ||||||||||||||||||||||||||||||||
| 433 | 0 | $found = $_; | |||||||||||||||||||||||||||||||
| 434 | 0 | $rest = substr($str, length($_)); | |||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||
| 438 | # if($found eq $NotFound) { | ||||||||||||||||||||||||||||||||
| 439 | # if(@where == @HEAD) {$found = $HEAD[11];} | ||||||||||||||||||||||||||||||||
| 440 | # elsif (@where == @BODY) {$found = $NotFound;} | ||||||||||||||||||||||||||||||||
| 441 | # elsif (@where == @FOOT) {$found = $FOOT[0];} | ||||||||||||||||||||||||||||||||
| 442 | # $rest = $str; | ||||||||||||||||||||||||||||||||
| 443 | # } | ||||||||||||||||||||||||||||||||
| 444 | 0 | return ($found, $rest); | |||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||
| 447 | #------------------------------- | ||||||||||||||||||||||||||||||||
| 448 | # $SEP = "/"; $NAUGHT = "'"; | ||||||||||||||||||||||||||||||||
| 449 | # isse = 이써 | ||||||||||||||||||||||||||||||||
| 450 | # iss'e = 있어 : is/se = 잇서 | ||||||||||||||||||||||||||||||||
| 451 | # ibsi = 입시 | ||||||||||||||||||||||||||||||||
| 452 | # ibs'i = 잆이 | ||||||||||||||||||||||||||||||||
| 453 | # ibsse = 입써 : ibs/se = 잆서 | ||||||||||||||||||||||||||||||||
| 454 | # ibssse = 잆써 | ||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||
| 456 | #------------------------------- | ||||||||||||||||||||||||||||||||
| 457 | # get_head($str) | ||||||||||||||||||||||||||||||||
| 458 | # eg. get_head("ssan") retunrs ("ss", "an") | ||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | sub get_head { | ||||||||||||||||||||||||||||||
|
Subroutine
get_head: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 460 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||
| 462 | 0 | my($str) = @_; | |||||||||||||||||||||||||||||||
| 463 | 0 | my($head, $rest) = $self->lookup($str, @{$self->head}); | |||||||||||||||||||||||||||||||
| 464 | 0 | return ($head, $rest); | |||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||
| 467 | #------------------------------- | ||||||||||||||||||||||||||||||||
| 468 | # get_body($str) | ||||||||||||||||||||||||||||||||
| 469 | # eg. get_body("wan") returns ("wa", "n") | ||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | sub get_body { | ||||||||||||||||||||||||||||||
|
Subroutine
get_body: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 471 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||
| 473 | 0 | my($str) = @_; | |||||||||||||||||||||||||||||||
| 474 | 0 | my($body, $rest) = $self->lookup($str, @{$self->body}); | |||||||||||||||||||||||||||||||
| 475 | 0 | return ($body, $rest); | |||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||
| 477 | #------------------------------- | ||||||||||||||||||||||||||||||||
| 478 | # get_foot($str) | ||||||||||||||||||||||||||||||||
| 479 | # eg. get_foot("bssan") returns ("bs", "san") | ||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | sub get_foot { | ||||||||||||||||||||||||||||||
|
Subroutine
get_foot: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 481 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||
| 483 | 0 | my($str) = @_; | |||||||||||||||||||||||||||||||
| 484 | 0 | my($foot, $rest) = $self->lookup($str, @{$self->foot}); | |||||||||||||||||||||||||||||||
| 485 | 0 | return ($foot, $rest); | |||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||
| 488 | #------------------------------- | ||||||||||||||||||||||||||||||||
| 489 | # look_ahead for the next head - body sequence | ||||||||||||||||||||||||||||||||
| 490 | # case : | ||||||||||||||||||||||||||||||||
| 491 | # normal : look_ahead("mal") == "m"; | ||||||||||||||||||||||||||||||||
| 492 | # no_head: look_ahead("an") == ""; | ||||||||||||||||||||||||||||||||
| 493 | # no_body: look_ahead("kkkkk") eq $NotFound; | ||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | sub look_ahead { | ||||||||||||||||||||||||||||||
|
Subroutine
look_ahead: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 495 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||
| 497 | 0 | my ($right) = @_; | |||||||||||||||||||||||||||||||
| 498 | 0 | my $head; | |||||||||||||||||||||||||||||||
| 499 | my $body; | ||||||||||||||||||||||||||||||||
| 500 | 0 | ($head, $right) = $self->get_head($right); | |||||||||||||||||||||||||||||||
| 501 | 0 | ($body, $right) = $self->get_body($right); | |||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | if ($body eq $NotFound) { return $NotFound;} | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 504 | 0 | elsif($head eq $NotFound) {return "";} | |||||||||||||||||||||||||||||||
| 505 | 0 | else { return $head;} | |||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||
| 508 | #------------------------------- | ||||||||||||||||||||||||||||||||
| 509 | # get a hangul string from a transliteration : | ||||||||||||||||||||||||||||||||
| 510 | # Makes the first hangul syllable from a transliterated string | ||||||||||||||||||||||||||||||||
| 511 | # and recursively processes the rest. | ||||||||||||||||||||||||||||||||
| 512 | # for example: get_han('hangugmal') returns unicode string '한국말' | ||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | sub get_han { | ||||||||||||||||||||||||||||||
|
Subroutine
get_han: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 514 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 515 | 0 | my $NAUGHT = $self->naught; | |||||||||||||||||||||||||||||||
| 516 | 0 | my $FILL = ""; # jongseong filler | |||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||
| 518 | 0 | my ($right) = @_; | |||||||||||||||||||||||||||||||
| 519 | 0 | my $head; | |||||||||||||||||||||||||||||||
| 520 | my $body; | ||||||||||||||||||||||||||||||||
| 521 | 0 | my $foot; | |||||||||||||||||||||||||||||||
| 522 | 0 | my $look_ahead_token; | |||||||||||||||||||||||||||||||
| 523 | 0 | my $h; | |||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||
| 526 | 0 | show_process(0, "begin", $h, $head, $body, $foot, $look_ahead_token, $right); | |||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||
| 528 | 0 | ($head, $right) = $self->get_head($right); | |||||||||||||||||||||||||||||||
| 529 | 0 | show_process(1, "get_head", $h, $head, $body, $foot, $look_ahead_token, $right); | |||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||
| 531 | 0 | ($body, $right) = $self->get_body($right); | |||||||||||||||||||||||||||||||
| 532 | 0 | show_process(2, "get_body", $h, $head, $body, $foot, $look_ahead_token, $right); | |||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | if ($head eq $NotFound && $body eq $NotFound ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$head eq $NotFound and $body eq $NotFound
MC/DC0%0/2
$head eq $NotFound and $body eq $NotFound
$head eq $NotFound
$body eq $NotFound
Truth table0%0/3
A and B
A= $head eq $NotFoundB= $body eq $NotFound
| |||||||||||||||||||||||||||||||||
| 535 | 0 | $h = $h . substr($right,0,1); | |||||||||||||||||||||||||||||||
| 536 | 0 | show_process(21, "no head", $h, $head, $body, $foot, $look_ahead_token, $right); | |||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | if($right ne "") {$h = $h . $self->get_han(substr($right,1));} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 538 | ▶ | } elsif ($head ne $NotFound && $body eq $NotFound) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$head ne $NotFound and $body eq $NotFound
MC/DC0%0/2
$head ne $NotFound and $body eq $NotFound
$head ne $NotFound
$body eq $NotFound
Truth table0%0/3
A and B
A= $head ne $NotFoundB= $body eq $NotFound
| |||||||||||||||||||||||||||||||||
| 539 | 0 | $h = $h . $head; | |||||||||||||||||||||||||||||||
| 540 | 0 | show_process(22, "no body", $h, $head, $body, $foot, $look_ahead_token, $right); | |||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | if($right ne "") {$h = $h . substr($right, 0, 1) . $self->get_han(substr($right,1));} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 542 | } else { | ||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | if($head eq $NotFound) { $head = $NAUGHT; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 544 | 0 | ($foot, $right) = $self->get_foot($right); | |||||||||||||||||||||||||||||||
| 545 | 0 | show_process(3, "get_foot", $h, $head, $body, $foot, $look_ahead_token, $right); | |||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | if ($foot eq $NotFound || $foot eq $FILL) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$foot eq $NotFound or $foot eq $FILL
MC/DC0%0/2
$foot eq $NotFound or $foot eq $FILL
$foot eq $NotFound
$foot eq $FILL
Truth table0%0/3
A or B
A= $foot eq $NotFoundB= $foot eq $FILL
| |||||||||||||||||||||||||||||||||
| 547 | 0 | $h = $h . $self->hangulize_code($head, $body, $FILL); | |||||||||||||||||||||||||||||||
| 548 | 0 | show_process(31, "no foot", $h, $head, $body, $foot, $look_ahead_token, $right); | |||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | if($right ne "") {$h = $h . $self->get_han($right);} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 550 | } elsif($right eq "") { | ||||||||||||||||||||||||||||||||
| 551 | 0 | $h = $h . $self->hangulize_code($head, $body, $foot); | |||||||||||||||||||||||||||||||
| 552 | 0 | show_process(32, "eof", $h, $head, $body, $foot, $look_ahead_token, $right); | |||||||||||||||||||||||||||||||
| 553 | } else { | ||||||||||||||||||||||||||||||||
| 554 | 0 | $look_ahead_token = $self->look_ahead($right); | |||||||||||||||||||||||||||||||
| 555 | 0 | show_process(4, "look_ahead", $h, $head, $body, $foot, $look_ahead_token, $right); | |||||||||||||||||||||||||||||||
| 556 | 0 | ▶ | if ($look_ahead_token eq $NotFound || $look_ahead_token eq $NAUGHT) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$look_ahead_token eq $NotFound or $look_ahead_token eq $NAUGHT
MC/DC0%0/2
$look_ahead_token eq $NotFound or $look_ahead_token eq $NAUGHT
$look_ahead_token eq $NotFound
$look_ahead_token eq $NAUGHT
Truth table0%0/3
A or B
A= $look_ahead_token eq $NotFoundB= $look_ahead_token eq $NAUGHT
| |||||||||||||||||||||||||||||||||
| 557 | 0 | $h = $h . $self->hangulize_code($head, $body, $foot); | |||||||||||||||||||||||||||||||
| 558 | 0 | show_process(41, "no look", $h, $head, $body, $foot, $look_ahead_token, $right); | |||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | if($right ne "") {$h = $h . $self->get_han($right);} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 560 | } else { | ||||||||||||||||||||||||||||||||
| 561 | 0 | ($foot, $right) = $self->get_correct_foot($foot, $look_ahead_token, $right); | |||||||||||||||||||||||||||||||
| 562 | 0 | $h = $h . $self->hangulize_code($head, $body, $foot); | |||||||||||||||||||||||||||||||
| 563 | 0 | show_process(42, "get_correct_foot", $h, $head, $body, $foot, $look_ahead_token, $right); | |||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | if($right ne "") {$h = $h . $self->get_han($right);} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||
| 569 | 0 | return $h; | |||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||
| 574 | 11 | $, = "\t"; | |||||||||||||||||||||||||||||||
| 575 | 0 | ▶ | sub show_process { | ||||||||||||||||||||||||||||||
|
Subroutine
show_process: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 576 | 0 | if(0) { | |||||||||||||||||||||||||||||||
| 577 | my($id, $desc, $h, $head, $body, $foot, $look_ahead_token, $right) = @_; | ||||||||||||||||||||||||||||||||
| 578 | print $id , $desc, $h, $head, $body, $foot, $look_ahead_token, $right, "\n"; | ||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||
| 582 | #------------------------------- | ||||||||||||||||||||||||||||||||
| 583 | # correct foot | ||||||||||||||||||||||||||||||||
| 584 | # <n:a:nh>($NAUGHT)a --> <n:a:n>ha | ||||||||||||||||||||||||||||||||
| 585 | # <n:a:bs>(s)sa --> <n:a:b>ssa | ||||||||||||||||||||||||||||||||
| 586 | # <n:a:nh>(t)ta --> <n:a:nh>ta | ||||||||||||||||||||||||||||||||
| 587 | #my $foot_p, my $look_ahead_token, my $right_p; | ||||||||||||||||||||||||||||||||
| 588 | #my $foot, my $right; | ||||||||||||||||||||||||||||||||
| 589 | 0 | ▶ | sub get_correct_foot { | ||||||||||||||||||||||||||||||
|
Subroutine
get_correct_foot: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 590 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||
| 592 | 0 | my ($foot_p, $look_ahead_token, $right_p) = @_; | |||||||||||||||||||||||||||||||
| 593 | 0 | my $foot, my $right; | |||||||||||||||||||||||||||||||
| 594 | 0 | $foot_p = $foot_p . $look_ahead_token;; | |||||||||||||||||||||||||||||||
| 595 | 0 | $right_p = substr($right_p, length($look_ahead_token)); | |||||||||||||||||||||||||||||||
| 596 | 0 | $foot = $foot_p; | |||||||||||||||||||||||||||||||
| 597 | 0 | $right = $right_p; | |||||||||||||||||||||||||||||||
| 598 | 0 | my $found = $NotFound; | |||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||
| 600 | 0 | foreach(@{$self->head}) { | |||||||||||||||||||||||||||||||
| 601 | 0 | ▶ | if ($_ eq substr($foot_p, length($foot_p) - length($_))) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | if ($found eq $NotFound) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 603 | 0 | $found = $_; | |||||||||||||||||||||||||||||||
| 604 | 0 | $foot = substr($foot_p, 0, length($foot)-length($found)); | |||||||||||||||||||||||||||||||
| 605 | 0 | $right = $found . $right_p; | |||||||||||||||||||||||||||||||
| 606 | } elsif (length($found) < length($_)) { | ||||||||||||||||||||||||||||||||
| 607 | 0 | $found = $_; | |||||||||||||||||||||||||||||||
| 608 | 0 | $foot = substr($foot_p, 0, length($foot_p)-length($found)); | |||||||||||||||||||||||||||||||
| 609 | 0 | $right = $found . $right_p; | |||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||
| 614 | 0 | return ($foot, $right); | |||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||
| 617 | 11 | 1; | |||||||||||||||||||||||||||||||
| 618 | __END__ | ||||||||||||||||||||||||||||||||