| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Convert::Dayi; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
34756
|
use utf8; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
7
|
|
|
4
|
1
|
|
|
1
|
|
37
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
32
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
55
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=encoding utf8 |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Convert::Dayi - Dayi Convention Module |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.05 |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
|
20
|
1
|
|
|
1
|
|
5
|
use Exporter; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
912
|
|
|
21
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
22
|
|
|
|
|
|
|
our @EXPORT_OK = qw(as_ascii as_dayi from_ascii); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use utf8; # you will need this |
|
27
|
|
|
|
|
|
|
use Convert::Dayi qw(as_ascii as_dayi from_ascii); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
print as_ascii("大易中文") # v db/ o1 kx |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
print as_dayi("大易中文") # 禾 日馬竹 口言 立水 |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
for from_ascii function , you need to provide index (start from 1) |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
print from_ascii('v1 db/1') # 大易 |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
print from_ascii('v db/') # 大易 (if the word is not defined , select index 1 by default) |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
to translate chinese from STDIN: |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
#!/usr/bin/env perl |
|
42
|
|
|
|
|
|
|
use utf8; |
|
43
|
|
|
|
|
|
|
use Convert::Dayi qw(as_ascii); |
|
44
|
|
|
|
|
|
|
use Encode; |
|
45
|
|
|
|
|
|
|
while( ) { |
|
46
|
|
|
|
|
|
|
my $word = Encode::decode_utf8( $_ ); |
|
47
|
|
|
|
|
|
|
print as_ascii( $word ); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
L module provides a way to convert chinese words to ascii code by Input Method Keys. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
You can also convert the keycode to chinese back. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 EXPORT |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
our %KEYS = (); |
|
63
|
|
|
|
|
|
|
our %KEYS_REV = (); |
|
64
|
|
|
|
|
|
|
our %WORDS = (); |
|
65
|
|
|
|
|
|
|
our %WORDS_REV = (); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
INIT { |
|
68
|
1
|
|
|
1
|
|
5
|
init(); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub init { |
|
72
|
1
|
|
|
1
|
0
|
3
|
init_keys(); |
|
73
|
1
|
|
|
|
|
3
|
init_words(); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub init_keys { |
|
77
|
1
|
|
|
1
|
0
|
8
|
while( ) { |
|
78
|
86
|
100
|
|
|
|
247
|
if( /^KEYPROMPT\((.)\):\s+(.)/ ) { |
|
|
|
100
|
|
|
|
|
|
|
79
|
46
|
|
|
|
|
615
|
$KEYS{ $1 } = $2; |
|
80
|
46
|
|
|
|
|
229
|
$KEYS_REV{ $2 } = $1; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
elsif( /BEGINDICTIONARY/ ) { |
|
83
|
1
|
|
|
|
|
3
|
last; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub init_words { |
|
90
|
1
|
|
|
1
|
0
|
5
|
while( ) { |
|
91
|
13414
|
100
|
|
|
|
22859
|
if( $_ !~ m/^#/ ) { |
|
92
|
13413
|
|
|
|
|
42604
|
my ($key,$word) = split /\s/; |
|
93
|
13413
|
|
|
|
|
30506
|
$WORDS{ $word } = $key; |
|
94
|
13413
|
|
|
|
|
11110
|
my $key_index = 0; |
|
95
|
13413
|
|
|
|
|
38806
|
while( defined( $WORDS_REV{ $key . ++$key_index } ) ) { } |
|
96
|
13413
|
|
|
|
|
48871
|
$WORDS_REV{ $key . $key_index } = $word; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# must provide index |
|
102
|
|
|
|
|
|
|
=head2 from_ascii |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub from_ascii { |
|
107
|
1
|
|
|
1
|
0
|
2
|
my $string = shift; |
|
108
|
1
|
|
|
|
|
2
|
my $out = ''; |
|
109
|
1
|
|
|
|
|
7
|
for( split /\s/,$string ) { |
|
110
|
3
|
100
|
|
|
|
10
|
if( defined $WORDS_REV{$_} ) { |
|
|
|
50
|
|
|
|
|
|
|
111
|
2
|
|
|
|
|
5
|
$out .= $WORDS_REV{$_}; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
elsif( defined $WORDS_REV{$_ . '1' } ) { |
|
114
|
0
|
|
|
|
|
0
|
$out .= $WORDS_REV{$_ . '1'}; # try index 1 |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
else { |
|
117
|
1
|
|
|
|
|
3
|
$out .= $_; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
} |
|
120
|
1
|
|
|
|
|
4
|
return $out; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 as_dayi |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub as_dayi { |
|
128
|
1
|
|
|
1
|
1
|
2
|
my $string = shift; |
|
129
|
1
|
|
|
|
|
2
|
my $out = ''; |
|
130
|
1
|
|
|
|
|
6
|
while( $string =~ /(.)/g ) { |
|
131
|
7
|
|
|
|
|
10
|
my $word = $1; |
|
132
|
|
|
|
|
|
|
|
|
133
|
7
|
100
|
|
|
|
65
|
if( defined $WORDS{$word} ) { |
|
134
|
4
|
|
|
|
|
6
|
my $keys = $WORDS{ $word } ; |
|
135
|
4
|
|
|
|
|
10
|
for ( split //,$keys ) { |
|
136
|
8
|
|
|
|
|
26
|
$out .= $KEYS{ $_ }; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
4
|
|
|
|
|
17
|
$out .= ' '; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
else { |
|
141
|
3
|
|
|
|
|
8
|
$out .= $word; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
} |
|
144
|
1
|
|
|
|
|
6
|
return $out; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 as_ascii |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub as_ascii { |
|
152
|
1
|
|
|
1
|
1
|
196
|
my $string = shift; |
|
153
|
1
|
|
|
|
|
2
|
my $out = ''; |
|
154
|
1
|
|
|
|
|
5
|
while( $string =~ /(.)/g ) { |
|
155
|
9
|
|
|
|
|
17
|
my $word = $1; |
|
156
|
9
|
100
|
|
|
|
24
|
if( defined $WORDS{$word} ) { |
|
157
|
4
|
|
|
|
|
16
|
$out .= $WORDS{$word} . " "; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
else { |
|
160
|
5
|
|
|
|
|
15
|
$out .= $word; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
} |
|
163
|
1
|
|
|
|
|
6
|
return $out; |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 AUTHOR |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Cornelius, C<< >> |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 BUGS |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
174
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
175
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 SUPPORT |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
perldoc Convert::Dayi |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
You can also look for information at: |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=over 4 |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
L |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
L |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
L |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item * Search CPAN |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
L |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=back |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Copyright 2009 Cornelius, all rights reserved. |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
218
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=cut |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
1; # End of Convert::Dayi |
|
224
|
|
|
|
|
|
|
__DATA__ |