line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::Koremutake; |
2
|
1
|
|
|
1
|
|
719
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
791
|
use Error; |
|
1
|
|
|
|
|
4112
|
|
|
1
|
|
|
|
|
8
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.30'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my @phonemes = map { lc } qw{BA BE BI BO BU BY DA DE DI DO DU DY FA FE FI |
8
|
|
|
|
|
|
|
FO FU FY GA GE GI GO GU GY HA HE HI HO HU HY JA JE JI JO JU JY KA KE |
9
|
|
|
|
|
|
|
KI KO KU KY LA LE LI LO LU LY MA ME MI MO MU MY NA NE NI NO NU NY PA |
10
|
|
|
|
|
|
|
PE PI PO PU PY RA RE RI RO RU RY SA SE SI SO SU SY TA TE TI TO TU TY |
11
|
|
|
|
|
|
|
VA VE VI VO VU VY BRA BRE BRI BRO BRU BRY DRA DRE DRI DRO DRU DRY FRA |
12
|
|
|
|
|
|
|
FRE FRI FRO FRU FRY GRA GRE GRI GRO GRU GRY PRA PRE PRI PRO PRU PRY |
13
|
|
|
|
|
|
|
STA STE STI STO STU STY TRA TRE}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %phoneme_to_number; |
16
|
|
|
|
|
|
|
my %number_to_phoneme; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $number = 0; |
19
|
|
|
|
|
|
|
foreach my $phoneme (@phonemes) { |
20
|
|
|
|
|
|
|
$phoneme_to_number{$phoneme} = $number; |
21
|
|
|
|
|
|
|
$number_to_phoneme{$number} = $phoneme; |
22
|
|
|
|
|
|
|
$number++; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
1
|
|
|
1
|
1
|
858
|
my $class = shift; |
27
|
1
|
|
|
|
|
2
|
my $self = {}; |
28
|
1
|
|
|
|
|
2
|
bless $self, $class; |
29
|
1
|
|
|
|
|
3
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _numbers_to_koremutake { |
33
|
15
|
|
|
15
|
|
116
|
my($self, $numbers) = @_; |
34
|
15
|
|
|
|
|
19
|
my $string; |
35
|
15
|
|
|
|
|
27
|
foreach my $n (@$numbers) { |
36
|
30
|
100
|
100
|
|
|
134
|
throw Error::Simple("0 <= $n <= 127") unless (0 <= $n) && ($n <= 127); |
37
|
28
|
|
|
|
|
70
|
$string .= $number_to_phoneme{$n}; |
38
|
|
|
|
|
|
|
} |
39
|
13
|
|
|
|
|
67
|
return $string; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _koremutake_to_numbers { |
43
|
14
|
|
|
14
|
|
82
|
my($self, $string) = @_; |
44
|
14
|
|
|
|
|
18
|
my @numbers; |
45
|
|
|
|
|
|
|
my $phoneme; |
46
|
14
|
|
|
|
|
54
|
my @chars = split //, $string; |
47
|
14
|
|
|
|
|
45
|
while (@chars) { |
48
|
61
|
|
|
|
|
81
|
$phoneme .= shift @chars; |
49
|
61
|
100
|
|
|
|
188
|
next unless $phoneme =~ /[aeiouy]/; |
50
|
29
|
|
|
|
|
51
|
my $number = $phoneme_to_number{$phoneme}; |
51
|
29
|
100
|
|
|
|
54
|
throw Error::Simple("Phoneme $phoneme not valid") unless defined $number; |
52
|
28
|
|
|
|
|
34
|
push @numbers, $number; |
53
|
28
|
|
|
|
|
63
|
$phoneme = ""; |
54
|
|
|
|
|
|
|
} |
55
|
13
|
|
|
|
|
41
|
return \@numbers; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub integer_to_koremutake { |
59
|
14
|
|
|
14
|
1
|
87
|
my($self, $integer) = @_; |
60
|
|
|
|
|
|
|
|
61
|
14
|
100
|
|
|
|
34
|
throw Error::Simple("No integer given") unless defined $integer; |
62
|
13
|
100
|
|
|
|
30
|
throw Error::Simple('Negative numbers not acceptable') if $integer < 0; |
63
|
|
|
|
|
|
|
|
64
|
12
|
|
|
|
|
13
|
my @numbers; |
65
|
|
|
|
|
|
|
|
66
|
12
|
100
|
|
|
|
24
|
@numbers = (0) if $integer == 0; |
67
|
|
|
|
|
|
|
|
68
|
12
|
|
|
|
|
26
|
while ($integer != 0) { |
69
|
22
|
|
|
|
|
63
|
push @numbers, $integer % 128; |
70
|
22
|
|
|
|
|
50
|
$integer = int($integer/128); |
71
|
|
|
|
|
|
|
} |
72
|
12
|
|
|
|
|
44
|
return $self->_numbers_to_koremutake([reverse @numbers]); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub koremutake_to_integer { |
76
|
13
|
|
|
13
|
1
|
62
|
my($self, $string) = @_; |
77
|
13
|
100
|
|
|
|
35
|
throw Error::Simple("No koremutake string given") unless defined $string; |
78
|
|
|
|
|
|
|
|
79
|
12
|
|
|
|
|
23
|
my $numbers = $self->_koremutake_to_numbers($string); |
80
|
12
|
|
|
|
|
13
|
my $integer = 0; |
81
|
12
|
|
|
|
|
24
|
while (@$numbers) { |
82
|
23
|
|
|
|
|
24
|
my $n = shift @$numbers; |
83
|
23
|
|
|
|
|
45
|
$integer = ($integer * 128) + $n; |
84
|
|
|
|
|
|
|
} |
85
|
12
|
|
|
|
|
50
|
return $integer; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |