line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::JA::Yomi; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
4224
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use File::Slurp qw/slurp/; |
5
|
|
|
|
|
|
|
use utf8; |
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has debug => ( |
9
|
|
|
|
|
|
|
is => 'rw', |
10
|
|
|
|
|
|
|
isa => 'Int', |
11
|
|
|
|
|
|
|
default => 0, |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
has dic_file => ( |
14
|
|
|
|
|
|
|
is => 'rw', |
15
|
|
|
|
|
|
|
isa => 'Str', |
16
|
|
|
|
|
|
|
default => sub { |
17
|
|
|
|
|
|
|
my $self = shift; |
18
|
|
|
|
|
|
|
my $file = __FILE__; |
19
|
|
|
|
|
|
|
$file =~ s{/[^/]+\.pm$}{/bep-eng.dic}; |
20
|
|
|
|
|
|
|
$file; |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
has dic => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
isa => 'HashRef', |
26
|
|
|
|
|
|
|
lazy => 1, |
27
|
|
|
|
|
|
|
default => sub { |
28
|
|
|
|
|
|
|
my $self = shift; |
29
|
|
|
|
|
|
|
open (my $fh, "<:encoding(utf8)", $self->dic_file) or die "$!"; |
30
|
|
|
|
|
|
|
my @lines = <$fh>; # utf8 flagged |
31
|
|
|
|
|
|
|
close $fh; |
32
|
|
|
|
|
|
|
# '#' started rows are comments |
33
|
|
|
|
|
|
|
my %kana_of = map { |
34
|
|
|
|
|
|
|
chomp; |
35
|
|
|
|
|
|
|
my @pair = split(/ /, $_); |
36
|
|
|
|
|
|
|
$pair[0] => $pair[1]; |
37
|
|
|
|
|
|
|
} grep { |
38
|
|
|
|
|
|
|
substr($_,0,1) ne '#'; |
39
|
|
|
|
|
|
|
} @lines; |
40
|
|
|
|
|
|
|
return \%kana_of; |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# pass in utf8 flagged string |
45
|
|
|
|
|
|
|
sub convert { |
46
|
|
|
|
|
|
|
my ($self, $roman, $remainder) = @_; |
47
|
|
|
|
|
|
|
$remainder ||= ''; |
48
|
|
|
|
|
|
|
print "[convert]roman: $roman remainder: $remainder\n" if $self->debug; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return if ! $roman; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$roman = uc $roman; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
if ( $roman =~ /^([^A-Z]+)(.*)/ ) { |
55
|
|
|
|
|
|
|
# preserve symbols |
56
|
|
|
|
|
|
|
return $2 ? ( $1 . $self->convert($2) ) : $1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif ( exists $self->dic->{$roman} ) { |
59
|
|
|
|
|
|
|
print "[convert]found: $roman, ".Encode::encode('utf8',$self->dic->{$roman})."\n" if $self->debug; |
60
|
|
|
|
|
|
|
if ( ! $remainder ) { |
61
|
|
|
|
|
|
|
return $self->dic->{$roman}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
|
|
|
|
|
|
return $self->dic->{$roman} . $self->convert( $remainder ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
|
|
|
|
|
|
my $last_of_roman = chop( $roman ); |
69
|
|
|
|
|
|
|
return $self->convert( $roman, $last_of_roman . ($remainder || '') ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 NAME |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Lingua::JA::Yomi - convert English into Japanese katakana |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SYNOPSIS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
use utf8; |
84
|
|
|
|
|
|
|
use Lingua::JA::Yomi; |
85
|
|
|
|
|
|
|
my $converter = Lingua::JA::Yomi->new; |
86
|
|
|
|
|
|
|
$converter->convert('aerosmith'); |
87
|
|
|
|
|
|
|
# ã¨ã¢ãã¦ã¹ãã¹ |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 DESCRIPTION |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Lingua::JA::Yomi uses a dictionary to convert. |
92
|
|
|
|
|
|
|
The dictionary defaults to partly modified Bilingual Emacspeak Project dictionary |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 METHODS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item $japanese = $converter->convert('aerosmith'); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
converts English argument into Japanese. |
99
|
|
|
|
|
|
|
Pass in utf8 flagged string, and get utf8 flagged string. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 AUTHOR |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Masakazu Ohtsuka (mash) E<lt>o.masakazu@gmail.comE<gt> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SEE ALSO |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Bilingual Emacspeak Project L<http://www.argv.org/bep/> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
112
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
113
|
|
|
|
|
|
|
The default dictionary is GPL. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |