line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::KO::Munja; |
2
|
|
|
|
|
|
|
require Exporter; |
3
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
4
|
|
|
|
|
|
|
@EXPORT_OK = qw/roman2hangul hangul2roman/; |
5
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
6
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
7
|
|
|
|
|
|
|
); |
8
|
2
|
|
|
2
|
|
16536
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
68
|
|
9
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
26
|
|
|
2
|
|
|
|
|
71
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
11
|
2
|
|
|
2
|
|
936
|
use Convert::Moji 'make_regex'; |
|
2
|
|
|
|
|
2907
|
|
|
2
|
|
|
|
|
1169
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $verbose; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub makearegex |
16
|
|
|
|
|
|
|
{ |
17
|
6
|
|
|
6
|
0
|
15
|
my @possibles = @_; |
18
|
6
|
|
|
|
|
7
|
@possibles = map {$_ =~ s/^-$//; $_} @possibles; |
|
136
|
|
|
|
|
89
|
|
|
136
|
|
|
|
|
110
|
|
19
|
6
|
|
|
|
|
20
|
make_regex (@possibles); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my @initial = qw( |
23
|
|
|
|
|
|
|
g kk n d tt r m b pp s ss - j jj |
24
|
|
|
|
|
|
|
ch k t p h |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $initial_re = makearegex (@initial); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my %initial = a2h (@initial); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my @peak = qw( |
32
|
|
|
|
|
|
|
a ae ya yae eo e yeo ye o wa wae oe yo u |
33
|
|
|
|
|
|
|
wo we wi yu eu ui i |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $peak_re = makearegex (@peak); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my %peak = a2h (@peak); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my @final = qw( |
41
|
|
|
|
|
|
|
- g kk ks n nj nh d l lg lm lb ls lt |
42
|
|
|
|
|
|
|
lp lh m b ps s ss ng j c k t p h |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $final_re = makearegex (@final); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my %final = a2h (@final); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub hangul |
50
|
|
|
|
|
|
|
{ |
51
|
17
|
|
|
17
|
0
|
27
|
my ($initial, $peak, $final) = @_; |
52
|
17
|
|
|
|
|
17
|
for ($initial, $peak, $final) { |
53
|
51
|
100
|
|
|
|
62
|
if (! $_) { |
54
|
15
|
|
|
|
|
16
|
$_ = '-'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
17
|
50
|
|
|
|
33
|
if ($verbose) { |
58
|
0
|
|
|
|
|
0
|
print "Initial = $initial, peak = $peak, final = $final\n"; |
59
|
0
|
|
|
|
|
0
|
print "Initial = $initial{$initial}, peak = $peak{$peak}, final = $final{$final}\n"; |
60
|
|
|
|
|
|
|
} |
61
|
17
|
|
|
|
|
38
|
my $x = (($initial{$initial} * 21) + $peak{$peak}) * 28 + $final{$final}; |
62
|
17
|
|
|
|
|
20
|
my $hangul = chr (0xAC00 + $x); |
63
|
17
|
|
|
|
|
30
|
return $hangul; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub roman2hangul |
67
|
|
|
|
|
|
|
{ |
68
|
6
|
|
|
6
|
1
|
8883
|
my ($input) = @_; |
69
|
6
|
|
|
|
|
11
|
my $match = "$initial_re$peak_re$final_re"; |
70
|
6
|
|
|
|
|
12
|
$match =~ s/\\-//g; |
71
|
6
|
|
|
|
|
199
|
while ($input =~ s/((?:$match)+)/ROMAN/) { |
72
|
7
|
|
|
|
|
22
|
my $i = $1; |
73
|
7
|
50
|
|
|
|
14
|
if ($verbose) { |
74
|
0
|
|
|
|
|
0
|
print "Looking at '$i' from '$input'.\n"; |
75
|
|
|
|
|
|
|
} |
76
|
7
|
|
|
|
|
6
|
my @syllables; |
77
|
7
|
|
|
|
|
195
|
while ($i =~ s/($match)$//g) { |
78
|
17
|
50
|
|
|
|
30
|
if ($verbose) { |
79
|
0
|
|
|
|
|
0
|
print "pushing $1\n"; |
80
|
|
|
|
|
|
|
} |
81
|
17
|
|
|
|
|
75
|
unshift @syllables, $1; |
82
|
|
|
|
|
|
|
} |
83
|
7
|
|
|
|
|
6
|
my @hangul; |
84
|
7
|
|
|
|
|
9
|
for my $s (@syllables) { |
85
|
17
|
|
|
|
|
13
|
my $h = $s; |
86
|
17
|
|
|
|
|
185
|
$h =~ s/^$match$/hangul ($1, $2, $3)/ge; |
|
17
|
|
|
|
|
21
|
|
87
|
17
|
|
|
|
|
36
|
push @hangul, $h; |
88
|
|
|
|
|
|
|
} |
89
|
7
|
|
|
|
|
11
|
my $output = join '', @hangul; |
90
|
7
|
|
|
|
|
50
|
$input =~ s/ROMAN/$output/; |
91
|
|
|
|
|
|
|
} |
92
|
6
|
|
|
|
|
15
|
return $input; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub a2h { |
96
|
6
|
|
|
6
|
0
|
17
|
my @array = @_; |
97
|
6
|
|
|
|
|
10
|
my %hash; |
98
|
6
|
|
|
|
|
5
|
my $count = 0; |
99
|
6
|
|
|
|
|
8
|
for my $k (@array) { |
100
|
136
|
|
|
|
|
105
|
$hash{$k} = $count; |
101
|
136
|
|
|
|
|
79
|
$count++; |
102
|
|
|
|
|
|
|
} |
103
|
6
|
|
|
|
|
49
|
return %hash; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub romanize |
107
|
|
|
|
|
|
|
{ |
108
|
16
|
|
|
16
|
0
|
18
|
my ($char) = @_; |
109
|
16
|
|
|
|
|
16
|
my $han = ord ($char) - 0xAC00; |
110
|
16
|
|
|
|
|
20
|
my $init = int ($han / (21 * 28)); |
111
|
16
|
|
|
|
|
12
|
my $peak = int ($han / 28) % 21; |
112
|
16
|
|
|
|
|
47
|
my $final = $han % 28; |
113
|
16
|
|
|
|
|
25
|
my $roman = join '', $initial[$init], $peak[$peak], $final[$final]; |
114
|
16
|
|
|
|
|
38
|
return $roman; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub hangul2roman |
118
|
|
|
|
|
|
|
{ |
119
|
5
|
|
|
5
|
1
|
820
|
my ($hangul) = @_; |
120
|
2
|
|
|
2
|
|
484
|
$hangul =~ s/(\p{Hangul})/romanize ($1)/ge; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
19
|
|
|
16
|
|
|
|
|
15
|
|
121
|
5
|
|
|
|
|
16
|
$hangul =~ s/-//g; |
122
|
5
|
|
|
|
|
10
|
return $hangul; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |