Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 272 lines (192 sloc) 9.033 kb
89d0bcf init import
Cornelius authored
1 package Lingua::Sinica::PerlYuYan;
2
230da6d @audreyt * Update manifest; restore \n \t \x20 to its literal, not quoted, forms.
authored
3 use 5.008;
c4c6b9e ci
Cornelius authored
4 use utf8;
5678995 @audreyt * This be 0.10, Unicode release.
authored
5 use strict;
6 use Filter::Simple::Compile;
7 use Encode ();
8
e45675d @audreyt * Link context to the current version.
authored
9 our $VERSION = 1257700140.47574; # 2009年11月 9日 周一 01時09分11秒 CST
89d0bcf init import
Cornelius authored
10
276a2fe @daxim display characters as UTF-8 on search.cpan.org and Github
daxim authored
11 =encoding utf8
12
89d0bcf init import
Cornelius authored
13 =head1 NAME
14
686767b * 正置中大. :-)
Au Tang authored
15 Lingua::Sinica::PerlYuYan - 中書珨 - Perl in Classical Chinese in Perl
89d0bcf init import
Cornelius authored
16
e3f8e85 * Add VERSION. Next would be building a .shipit template...
Au Tang authored
17 =head1 VERSION
18
e45675d @audreyt * Link context to the current version.
authored
19 our $VERSION = 1257700140.47574; # 2009年11月 9日 周一 01時09分11秒 CST
e3f8e85 * Add VERSION. Next would be building a .shipit template...
Au Tang authored
20
89d0bcf init import
Cornelius authored
21 =head1 SYNOPSIS
22
c4c6b9e ci
Cornelius authored
23 # The Sieve of Eratosthenes - 埃拉托斯芬篩法
89d0bcf init import
Cornelius authored
24 use Lingua::Sinica::PerlYuYan;
25
01170e0 * Restore SYNOPSIS text so it works under modern Perl again.
Au Tang authored
26 用籌兮用嚴。井涸兮無礙
27 。印曰最高矣 又道數然哉。
28 。截起吾純風 賦小入大合。
29 。習予吾陣地 並二至純風。
30 。當起段賦取 加陣地合始。
31 。陣地賦篩始 繫繫此雜段。
32 。終陣地兮印 正道次標哉。
33 。輸空接段點 列終註泰來。
89d0bcf init import
Cornelius authored
34
35 =head1 DESCRIPTION
36
d84a768 * Fix grammatical errors; add "patches welcome" notice for POD transl…
Au Tang authored
37 This module makes it possible to write Perl programs in Classical Chinese poetry in Perl.
89d0bcf init import
Cornelius authored
38
d84a768 * Fix grammatical errors; add "patches welcome" notice for POD transl…
Au Tang authored
39 說此經者,能以珨文言文珨。
c59a4fa * Got a pretty good roundtrip translation of Lingua::Sinica::PerlYuYa…
Au Tang authored
40
513eef3 * VERSIONING CHANGE: This module is now using the Unix timestamp
Au Tang authored
41 (If one I<has> to ask "Why?", please refer to L<Lingua::Romana::Perligata> for
5678995 @audreyt * This be 0.10, Unicode release.
authored
42 related information.)
89d0bcf init import
Cornelius authored
43
d84a768 * Fix grammatical errors; add "patches welcome" notice for POD transl…
Au Tang authored
44 (闕譯,以待來者。)
45
5678995 @audreyt * This be 0.10, Unicode release.
authored
46 This module uses the single-character property of Chinese to disambiguate
513eef3 * VERSIONING CHANGE: This module is now using the Unix timestamp
Au Tang authored
47 between keywords, so one may elide whitespaces much like in real Chinese writings.
89d0bcf init import
Cornelius authored
48
d84a768 * Fix grammatical errors; add "patches welcome" notice for POD transl…
Au Tang authored
49 The vocabulary is in the 文言 (literary text) mode, not the common 白話
513eef3 * VERSIONING CHANGE: This module is now using the Unix timestamp
Au Tang authored
50 (spoken text) mode with multisyllabic words.
89d0bcf init import
Cornelius authored
51
513eef3 * VERSIONING CHANGE: This module is now using the Unix timestamp
Au Tang authored
52 C<Lingua::Sinica::PerlYuYan::translate()> (or simply as C<譯()>) translates a
53 string containing English programs into Chinese.
89d0bcf init import
Cornelius authored
54
55 =cut
5678995 @audreyt * This be 0.10, Unicode release.
authored
56
89d0bcf init import
Cornelius authored
57 our %Tab;
58 while (<DATA>) {
5678995 @audreyt * This be 0.10, Unicode release.
authored
59 $_ = Encode::is_utf8($_) ? $_ : Encode::decode_utf8($_);
60
89d0bcf init import
Cornelius authored
61 next if /^\s*$/;
8c8964c @daxim fix parser
daxim authored
62 my @eng = split ' ';
63 my @chi = map {/\A [!-~]+ \z/msx ? $_ : split //, $_}
64 # clusters of ASCII are untranslated keywords; keep them
65 split ' ', <DATA>;
66 for (my $i = 0; $i <= $#eng; $i++) {
67 next if $chi[$i] eq $eng[$i]; # filter untranslated
68 $Tab{$chi[$i]} = # append space if keyword, but not single letter
69 $eng[$i] =~ /\A [a-z]{2,} \z/msx ? $eng[$i] . ' ' : $eng[$i];
70 }
89d0bcf init import
Cornelius authored
71 }
72
5678995 @audreyt * This be 0.10, Unicode release.
authored
73 @Tab{qw{ 資曰 亂曰 檔曰 列曰 套曰 }}
74 = qw{ __DATA__ __END__ __FILE__ __LINE__ __PACKAGE__ };
89d0bcf init import
Cornelius authored
75
76 FILTER {
5678995 @audreyt * This be 0.10, Unicode release.
authored
77 $_ = Encode::is_utf8($_) ? $_ : Encode::decode_utf8($_);
78
c4c6b9e ci
Cornelius authored
79 foreach my $key ( sort { length $b <=> length $a } keys %Tab ) {
80 s/$key/$Tab{$key}/g;
89d0bcf init import
Cornelius authored
81 }
5678995 @audreyt * This be 0.10, Unicode release.
authored
82
83 return($_ = Encode::encode_utf8($_));
89d0bcf init import
Cornelius authored
84 };
85
5678995 @audreyt * This be 0.10, Unicode release.
authored
86 no warnings 'redefine';
89d0bcf init import
Cornelius authored
87 sub translate {
88 my $code = shift;
89
5678995 @audreyt * This be 0.10, Unicode release.
authored
90 for my $key (sort {length $Tab{$b} cmp length $Tab{$a}} keys %Tab) {
8dd06a6 * This be 0.11 with 迪拉斯's changes.
Au Tang authored
91 $code =~ s/\Q$Tab{$key}\E/$key/g;
89d0bcf init import
Cornelius authored
92 }
93
94 return $code;
95 }
96
97 1;
98
99 =head1 SEE ALSO
100
5678995 @audreyt * This be 0.10, Unicode release.
authored
101 L<Filter::Simple::Compile>, L<Lingua::Romana::Perligata>
89d0bcf init import
Cornelius authored
102
513eef3 * VERSIONING CHANGE: This module is now using the Unix timestamp
Au Tang authored
103 =head1 CC0 1.0 Universal
89d0bcf init import
Cornelius authored
104
513eef3 * VERSIONING CHANGE: This module is now using the Unix timestamp
Au Tang authored
105 To the extent possible under law, 唐鳳 has waived all copyright and related
106 or neighboring rights to Lingua-Sinica-PerlYuYan.
89d0bcf init import
Cornelius authored
107
513eef3 * VERSIONING CHANGE: This module is now using the Unix timestamp
Au Tang authored
108 This work is published from Taiwan.
89d0bcf init import
Cornelius authored
109
513eef3 * VERSIONING CHANGE: This module is now using the Unix timestamp
Au Tang authored
110 L<http://creativecommons.org/publicdomain/zero/1.0>
5678995 @audreyt * This be 0.10, Unicode release.
authored
111
513eef3 * VERSIONING CHANGE: This module is now using the Unix timestamp
Au Tang authored
112 =begin html
5678995 @audreyt * This be 0.10, Unicode release.
authored
113
513eef3 * VERSIONING CHANGE: This module is now using the Unix timestamp
Au Tang authored
114 <p xmlns:dct="http://purl.org/dc/terms/" xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#">
115 <a rel="license" href="http://creativecommons.org/publicdomain/zero/1.0/" style="text-decoration:none;">
116 <img src="http://i.creativecommons.org/l/zero/1.0/88x31.png" border="0" alt="CC0" />
117 </a>
118 <br />
119 To the extent possible under law, <a href="http://www.audreyt.org/" rel="dct:publisher"><span property="dct:title">唐鳳</span></a>
120 has waived all copyright and related or neighboring rights to
121 <span property="dct:title">Lingua-Sinica-PerlYuYan</span>.
122 This work is published from
123 <span about="http://www.audreyt.org/" property="vcard:Country" datatype="dct:ISO3166" content="TW">Taiwan</span>.
124 </p>
5678995 @audreyt * This be 0.10, Unicode release.
authored
125
513eef3 * VERSIONING CHANGE: This module is now using the Unix timestamp
Au Tang authored
126 =end html
89d0bcf init import
Cornelius authored
127
128 =cut
129
130 __DATA__
131 a b c d e f g h i j k l m n o p q r s t u v w x y z
c4c6b9e ci
Cornelius authored
132 甲乙丙丁戊己庚辛壬癸子丑寅卯辰巳午未申酉戌亥地水火風
89d0bcf init import
Cornelius authored
133 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
c4c6b9e ci
Cornelius authored
134 青心赤肝黃脾白肺黑腎鼠牛虎兔龍蛇馬羊猴雞狗豬春夏秋冬
89d0bcf init import
Cornelius authored
135
136 0 1 2 3 4 5 6 7 8 9 10 100 1000 10000 10000_0000
c4c6b9e ci
Cornelius authored
137 零一二三四五六七八九十 百 千 萬 億
89d0bcf init import
Cornelius authored
138 0 1 2 3 4 5 6 7 8 9 10 100 1000 20 30
c4c6b9e ci
Cornelius authored
139 零壹貳毿肆伍陸柒捌玖拾 佰 仟 廿 卅
89d0bcf init import
Cornelius authored
140 0 1 2 3 4 5 6 7 8 9
c4c6b9e ci
Cornelius authored
141 0123456789
89d0bcf init import
Cornelius authored
142
733cdde @daxim kill whitespace at EOL
daxim authored
143 ! @ # # $ % % ^ & * ( ) - = _ + + [ ] { } \ | ; : :
c4c6b9e ci
Cornelius authored
144 非陣井註純雜模析和乘起合減賦底加正內外始終參聯兮然標
89d0bcf init import
Cornelius authored
145 ' ' " " , , => < . . > / / ? ` ` ~
c4c6b9e ci
Cornelius authored
146 曰矣道哉又並與 小點接大除分歟行者繫
89d0bcf init import
Cornelius authored
147 ! @ # $ % ^ & * ( ) - = _ + [ ] { } \ | ; ; : ' " , , < . > / ? ` ~
5678995 @audreyt * This be 0.10, Unicode release.
authored
148 !@#$%︿&*()-=_+〔〕{}╲|;。:’”,、<.>╱?‵~
89d0bcf init import
Cornelius authored
149
150 .. ... ** ++ -- -> ::
c4c6b9e ci
Cornelius authored
151 至 乃 冪 增 扣 之 宗
89d0bcf init import
Cornelius authored
152
153 && == || and or lt gt cmp eq not
c4c6b9e ci
Cornelius authored
154 及 等 許 且 或 前 後 較 同 否
89d0bcf init import
Cornelius authored
155
f12e310 @audreyt Some more translations.
authored
156 =~ !~ x <=> ~~ //
157 =~ !~ x <=> ~~ //
ffd77e6 @daxim add some more keywords and operators
daxim authored
158
159 << >> <= >= le ge != ne xor
f12e310 @audreyt Some more translations.
authored
160 << >> <= >= le ge != ne 抑
ffd77e6 @daxim add some more keywords and operators
daxim authored
161
162 **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= //= x=
163 **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= //= x=
164
01170e0 * Restore SYNOPSIS text so it works under modern Perl again.
Au Tang authored
165 $/ $_ @_ "\x20" "\t" "\n" main
c4c6b9e ci
Cornelius authored
166 段 此 諸 空 格 列 主
89d0bcf init import
Cornelius authored
167
168 STDIN STDOUT STDERR DATA BEGIN END INIT CHECK DESTROY
c4c6b9e ci
Cornelius authored
169 入 出 誤 料 創 末 育 察 滅
89d0bcf init import
Cornelius authored
170
171 chomp chop chr crypt hex index lc lcfirst length oct ord pack q/ qq/ reverse
733cdde @daxim kill whitespace at EOL
daxim authored
172 截 斬 文 密 爻 索 纖 細 長 卦 序 包 引 雙 逆
89d0bcf init import
Cornelius authored
173 rindex sprintf substr tr/ uc ucfirst y/
733cdde @daxim kill whitespace at EOL
daxim authored
174 檢 編 部 轉 壯 厚 換
89d0bcf init import
Cornelius authored
175
176 m/ pos quotemeta s/ split study qr/
c4c6b9e ci
Cornelius authored
177 符 位 逸 代 切 習 規
89d0bcf init import
Cornelius authored
178
179 abs atan2 cos exp hex int log oct rand sin sqrt srand
733cdde @daxim kill whitespace at EOL
daxim authored
180 絕 角 餘 階 爻 整 對 卦 亂 弦 根 騷
89d0bcf init import
Cornelius authored
181
182 pop push shift splice unshift
733cdde @daxim kill whitespace at EOL
daxim authored
183 彈 推 取 抽 予
89d0bcf init import
Cornelius authored
184
185 grep join map qw/ reverse sort unpack
733cdde @daxim kill whitespace at EOL
daxim authored
186 篩 併 映 篇 逆 排 啟
89d0bcf init import
Cornelius authored
187
188 delete each exists keys values
733cdde @daxim kill whitespace at EOL
daxim authored
189 刪 每 存 鍵 值
89d0bcf init import
Cornelius authored
190
191 binmode close closedir dbmclose dbmopen die eof fileno flock format getc
c4c6b9e ci
Cornelius authored
192 法 閉 關 閤 揭 死 結 號 鎖 排 擷
89d0bcf init import
Cornelius authored
193 print printf read readdir rewinddir seek seekdir select syscall
5678995 @audreyt * This be 0.10, Unicode release.
authored
194 印 輸 讀 覽 迴 搜 尋 擇 召
89d0bcf init import
Cornelius authored
195 sysread sysseek syswrite tell telldir truncate warn write
5678995 @audreyt * This be 0.10, Unicode release.
authored
196 鑑 狩 敕 告 訴 縮 訊 寫
89d0bcf init import
Cornelius authored
197
5678995 @audreyt * This be 0.10, Unicode release.
authored
198 pack read unpack vec
733cdde @daxim kill whitespace at EOL
daxim authored
199 包 讀 啟 向
89d0bcf init import
Cornelius authored
200
201 chdir chmod chown chroot fcntl glob ioctl link lstat mkdir open opendir
5678995 @audreyt * This be 0.10, Unicode release.
authored
202 目 權 擁 遷 控 全 制 鏈 況 造 開 展
89d0bcf init import
Cornelius authored
203 readlink rename rmdir stat symlink umask unlink utime
f12e310 @audreyt Some more translations.
authored
204 循 更 毀 態 徵 蒙 鬆 刻
89d0bcf init import
Cornelius authored
205
f12e310 @audreyt Some more translations.
authored
206 say if else elsif until while foreach given when default break
08b4d82 @audreyt A few more characters prompted by @CindyLinz
authored
207 說 倘 匪 乃 迄 當 逐 設 若 預 折
ffd77e6 @daxim add some more keywords and operators
daxim authored
208
89d0bcf init import
Cornelius authored
209 caller continue die do dump eval exit goto last next redo return sub wantarray
027d2c1 @audreyt * "for" duplicates with "redo"; adjust "redo" to 再.
authored
210 喚 續 死 為 傾 執 離 躍 尾 次 再 回 副 欲
89d0bcf init import
Cornelius authored
211
212 caller import local my our package use
733cdde @daxim kill whitespace at EOL
daxim authored
213 喚 導 域 吾 咱 套 用
89d0bcf init import
Cornelius authored
214
215 defined dump eval formline local my our reset scalar undef wantarray
f12e310 @audreyt Some more translations.
authored
216 定 傾 執 劃 域 吾 咱 抹 量 消 欲
89d0bcf init import
Cornelius authored
217
218 alarm exec fork getpgrp getppid getpriority kill
733cdde @daxim kill whitespace at EOL
daxim authored
219 鈴 生 殖 getpgrp getppid getpriority 殺
c4c6b9e ci
Cornelius authored
220
221 for
222
89d0bcf init import
Cornelius authored
223
224 pipe qx/ setpgrp setpriority sleep system times wait waitpid
733cdde @daxim kill whitespace at EOL
daxim authored
225 管 qx/ setpgrp setpriority 眠 作 計 候 waitpid
89d0bcf init import
Cornelius authored
226
227 do no package require use
733cdde @daxim kill whitespace at EOL
daxim authored
228 為 無 套 必 用
89d0bcf init import
Cornelius authored
229
230 bless dbmclose dbmopen package ref tie tied untie
c4c6b9e ci
Cornelius authored
231 祝 dbmclose dbmopen 套 照 纏 縛 解
89d0bcf init import
Cornelius authored
232
233 accept bind connect getpeername getsockname getsockopt listen recv send
230da6d @audreyt * Update manifest; restore \n \t \x20 to its literal, not quoted, forms.
authored
234 受 束 連 getpeername getsockname getsockopt 聆 收 送
89d0bcf init import
Cornelius authored
235
733cdde @daxim kill whitespace at EOL
daxim authored
236 setsockopt shutdown sockatmark socket socketpair
f12e310 @audreyt Some more translations.
authored
237 setsockopt shutdown sockatmark 槽 槏
89d0bcf init import
Cornelius authored
238
239 msgctl msgget msgrcv msgsnd semctl semget semop shmctl shmget shmread shmwrite
240 msgctl msgget msgrcv msgsnd semctl semget semop shmctl shmget shmread shmwrite
241
242 endgrent endhostent endnetent endpwent getgrent getgrgid getgrnam
243 endgrent endhostent endnetent endpwent getgrent getgrgid getgrnam
244
733cdde @daxim kill whitespace at EOL
daxim authored
245 getlogin getpwent getpwnam getpwuid setgrent setpwent
246 getlogin getpwent getpwnam getpwuid setgrent setpwent
89d0bcf init import
Cornelius authored
247
248 endprotoent endservent gethostbyaddr gethostbyname
733cdde @daxim kill whitespace at EOL
daxim authored
249 endprotoent endservent gethostbyaddr gethostbyname
89d0bcf init import
Cornelius authored
250
251 gethostent getnetbyaddr getnetbyname getnetent
733cdde @daxim kill whitespace at EOL
daxim authored
252 gethostent getnetbyaddr getnetbyname getnetent
89d0bcf init import
Cornelius authored
253
254 getprotobyname getprotobynumber getprotoent
733cdde @daxim kill whitespace at EOL
daxim authored
255 getprotobyname getprotobynumber getprotoent
89d0bcf init import
Cornelius authored
256
257 getservbyname getservbyport getservent sethostent
733cdde @daxim kill whitespace at EOL
daxim authored
258 getservbyname getservbyport getservent sethostent
89d0bcf init import
Cornelius authored
259
260 setnetent setprotoent setservent
733cdde @daxim kill whitespace at EOL
daxim authored
261 setnetent setprotoent setservent
89d0bcf init import
Cornelius authored
262
263 gmtime localtime time
c4c6b9e ci
Cornelius authored
264 準 區 時
89d0bcf init import
Cornelius authored
265
266 attributes autouse base blib bytes charnames constant diagnostics encoding fields
c4c6b9e ci
Cornelius authored
267 性 活 基 括 字 名 常 診 碼 欄
89d0bcf init import
Cornelius authored
268 filetest integer less locale overload sigtrap strict subs utf8 vars vmsish warnings
c4c6b9e ci
Cornelius authored
269 試 籌 少 國 載 號 嚴 式 通 變 倭 警
89d0bcf init import
Cornelius authored
270 Lingua::Sinica::PerlYuYan::translate Lingua::Sinica::PerlYuYan::Tab
c4c6b9e ci
Cornelius authored
271 譯 表
Something went wrong with that request. Please try again.