Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / lisp / leim / quail / sisheng.el
blob35a5f41f323a4495b0a7fb7961688180c7d2e455
1 ;;; sisheng.el --- sisheng input method for Chinese pinyin transliteration
3 ;; Copyright (C) 2004-2014 Free Software Foundation, Inc.
5 ;; Author: Werner LEMBERG <wl@gnu.org>
7 ;; Keywords: multilingual, input method, Chinese, pinyin, sisheng
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;;; Code:
28 (require 'quail)
30 (defconst sisheng-regexp
31 "[āēīōūǖ]\\|üē")
33 ;; First element is the key,
34 ;; second element is the vowel used for the input sequence,
35 ;; last four elements are the resulting tones.
37 (defconst sisheng-vowel-table
38 '(("ā" "a" "ā" "á" "ǎ" "à")
39 ("ē" "e" "ē" "é" "ě" "è")
40 ("ī" "i" "ī" "í" "ǐ" "ì")
41 ("ō" "o" "ō" "ó" "ǒ" "ò")
42 ("ū" "u" "ū" "ú" "ǔ" "ù")
43 ("ǖ" "v" "ǖ" "ǘ" "ǚ" "ǜ")
44 ("üē" "ve" "üē" "üé" "üě" "üè")))
47 ;; All possible syllables in Mandarin Chinese, presented in the first
48 ;; tone. Note that make-sisheng-rules always constructs rules for all
49 ;; four tones even if some of those tones aren't used in Mandarin.
51 (defconst sisheng-syllable-table
52 '("ā" "āi" "ān" "āng" "āo"
54 "bā" "bāi" "bān" "bāng" "bāo"
55 "bēi" "bēn" "bēng"
56 "bī" "biān" "biāo" "biē" "bīn" "bīng"
57 "bō"
58 "bū"
60 "cā" "cāi" "cān" "cāng" "cāo"
61 "cē" "cēn" "cēng"
62 "cī"
63 "cōng" "cōu"
64 "cū" "cuān" "cuī" "cūn" "cuō"
66 "chā" "chāi" "chān" "chāng" "chāo"
67 "chē" "chēn" "chēng"
68 "chī"
69 "chōng" "chōu"
70 "chū" "chuā" "chuāi" "chuān" "chuāng" "chuī" "chūn" "chuō"
72 "dā" "dāi" "dān" "dāng" "dāo"
73 "dē" "dēi" "dēn" "dēng"
74 "dī" "diān" "diāo" "diē" "dīng" "diū"
75 "dōng" "dōu"
76 "dū" "duān" "duī" "dūn" "duō"
78 "ē" "ēi" "ēn" "ēng" "ēr"
80 "fā" "fān" "fāng"
81 "fēi" "fēn" "fēng"
82 "fiāo"
83 "fō" "fōu"
84 "fū"
86 "gā" "gāi" "gān" "gāng" "gāo"
87 "gē" "gēi" "gēn" "gēng"
88 "gōng" "gōu"
89 "gū" "guā" "guāi" "guān" "guāng" "guī" "gūn" "guō"
91 "hā" "hāi" "hān" "hāng" "hāo"
92 "hē" "hēi" "hēn" "hēng"
93 "hōng" "hōu"
94 "hū" "huā" "huāi" "huān" "huāng" "huī" "hūn" "huō"
96 "jī" "jiā" "jiān" "jiāng" "jiāo" "jiē" "jīn" "jīng" "jiōng" "jiū"
97 "jū" "juān" "juē" "jūn"
99 "kā" "kāi" "kān" "kāng" "kāo"
100 "kē" "kēi" "kēn" "kēng"
101 "kōng" "kōu"
102 "kū" "kuā" "kuāi" "kuān" "kuāng" "kuī" "kūn" "kuō"
104 "lā" "lāi" "lān" "lāng" "lāo"
105 "lē" "lēi" "lēng"
106 "lī" "liā" "liān" "liāng" "liāo" "liē" "līn" "līng" "liū"
107 "lōng" "lōu"
108 "lū" "luān" "lūn" "luō"
109 "lǖ" "lüē"
111 "mā" "māi" "mān" "māng" "māo"
112 "mē" "mēi" "mēn" "mēng"
113 "mī" "miān" "miāo" "miē" "mīn" "mīng" "miū"
114 "mō" "mōu"
115 "mū"
117 "nā" "nāi" "nān" "nāng" "nāo"
118 "nē" "nēi" "nēn" "nēng"
119 "nī" "niān" "niāng" "niāo" "niē" "nīn" "nīng" "niū"
120 "nōng" "nōu"
121 "nū" "nuān" "nuō"
122 "nǖ" "nüē"
124 "ō" "ōu"
126 "pā" "pāi" "pān" "pāng" "pāo"
127 "pēi" "pēn" "pēng"
128 "pī" "piān" "piāo" "piē" "pīn" "pīng"
129 "pō" "pōu"
130 "pū"
132 "qī" "qiā" "qiān" "qiāng" "qiāo" "qiē" "qīn" "qīng" "qiōng" "qiū"
133 "qū" "quān" "quē" "qūn"
135 "rān" "rāng" "rāo"
136 "rē" "rēn" "rēng"
137 "rī"
138 "rōng" "rōu"
139 "rū" "ruā" "ruān" "ruī" "rūn" "ruō"
141 "sā" "sāi" "sān" "sāng" "sāo"
142 "sē" "sēn" "sēng"
143 "sī"
144 "sōng" "sōu"
145 "sū" "suān" "suī" "sūn" "suō"
147 "shā" "shāi" "shān" "shāng" "shāo"
148 "shē" "shēi" "shēn" "shēng"
149 "shī"
150 "shōu"
151 "shū" "shuā" "shuāi" "shuān" "shuāng" "shuī" "shūn" "shuō"
153 "tā" "tāi" "tān" "tāng" "tāo"
154 "tē" "tēi" "tēng"
155 "tī" "tiān" "tiāo" "tiē" "tīng"
156 "tōng" "tōu"
157 "tū" "tuān" "tuī" "tūn" "tuō"
159 "wā" "wāi" "wān" "wāng"
160 "wēi" "wēn" "wēng"
161 "wō"
162 "wū"
164 "xī" "xiā" "xiān" "xiāng" "xiāo" "xiē" "xīn" "xīng" "xiōng" "xiū"
165 "xū" "xuān" "xuē" "xūn"
167 "yā" "yān" "yāng" "yāo"
168 "yē"
169 "yī" "yīn" "yīng"
170 "yō" "yōng" "yōu"
171 "yū" "yuān" "yuē" "yūn"
173 "zā" "zāi" "zān" "zāng" "zāo"
174 "zē" "zēi" "zēn" "zēng"
175 "zī"
176 "zōng" "zōu"
177 "zū" "zuān" "zuī" "zūn" "zuō"
179 "zhā" "zhāi" "zhān" "zhāng" "zhāo"
180 "zhē" "zhēi" "zhēn" "zhēng"
181 "zhī"
182 "zhōng" "zhōu"
183 "zhū" "zhuā" "zhuāi" "zhuān" "zhuāng" "zhuī" "zhūn" "zhuō"))
185 ;; This function converts e.g.
187 ;; "zhuō"
189 ;; into
191 ;; (("zhuo4" ["zhuò"])
192 ;; ("zhuo3" ["zhuǒ"])
193 ;; ("zhuo2" ["zhuó"])
194 ;; ("zhuo1" ["zhuō"]))
196 (defun quail-make-sisheng-rules (syllable)
197 (let ((case-fold-search t)
198 vowel-match
199 vowel-list
200 input-vowel
201 base-key
203 value
204 key-value-list
205 (i 1))
206 (string-match sisheng-regexp syllable)
207 (setq vowel-match (downcase (match-string 0 syllable)))
208 (setq vowel-list
209 (cdr (assoc-string vowel-match sisheng-vowel-table)))
210 (setq input-vowel (car vowel-list))
211 (setq base-key (replace-match input-vowel nil nil syllable))
212 (while (<= i 4)
213 (setq key (concat base-key (number-to-string i)))
214 (setq value (vector (replace-match (nth i vowel-list) nil nil syllable)))
215 (push (list key value) key-value-list)
216 (setq i (1+ i)))
217 key-value-list))
219 ;; Set up sisheng input method.
221 (quail-define-package
222 "chinese-sisheng" ; name
223 "Chinese" ; language
224 "ǚ" ; title
225 t ; guidance
226 "Sìshēng input method for pīnyīn transliteration of Chinese.
228 Examples: shuang1 -> shuāng
229 Lv3 -> Lǚ
230 AN4 -> ÀN
232 Use the fifth (unstressed) tone for syllables containing `ü'
233 without a tone mark.
235 Example: nve5 -> nüe
236 " ; docstring
237 nil ; translation-keys
238 t ; forget-last-selection
239 nil ; deterministic
240 nil ; kbd-translate
241 nil ; show-layout
242 nil ; create-decode-map
243 nil ; maximum-shortest
244 nil ; overlay-plist
245 nil ; update-translation-function
246 nil ; conversion-keys
247 t ; simple
250 ;; Call quail-make-sisheng-rules for all syllables in sisheng-syllable-table.
252 (let ((case-table-save (current-case-table))
253 sisheng-list)
254 (set-case-table (standard-case-table))
255 (dolist (syllable sisheng-syllable-table)
256 (setq sisheng-list
257 (append (quail-make-sisheng-rules syllable)
258 sisheng-list)))
260 (dolist (syllable sisheng-syllable-table)
261 (setq sisheng-list
262 (append (quail-make-sisheng-rules (upcase-initials syllable))
263 sisheng-list)))
265 (dolist (syllable sisheng-syllable-table)
266 (setq sisheng-list
267 (append (quail-make-sisheng-rules (upcase syllable))
268 sisheng-list)))
270 (eval `(quail-define-rules
271 ,@sisheng-list
273 ("lv5" ["lü"])
274 ("lve5" ["lüe"])
275 ("nv5" ["nü"])
276 ("nve5" ["nüe"])
278 ("Lv5" ["Lü"])
279 ("Lve5" ["Lüe"])
280 ("Nv5" ["Nü"])
281 ("Nve5" ["Nüe"])
283 ("LV5" ["LÜ"])
284 ("LVE5" ["LÜE"])
285 ("NV5" ["NÜ"])
286 ("NVE5" ["NÜE"])))
287 (set-case-table case-table-save))
289 ;; Local Variables:
290 ;; coding: utf-8
291 ;; End:
293 ;;; sisheng.el ends here