1 ;;; sisheng.el --- sisheng input method for Chinese pinyin transliteration
3 ;; Copyright (C) 2004 Free Software Foundation, Inc.
5 ;; Author: Werner LEMBERG <wl@gnu.org>
7 ;; Keywords: multilingual, input method, Chinese, pinyin, sisheng
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 (defconst sisheng-regexp
32 ;; First element is the key,
33 ;; second element is the vowel used for the input sequence,
34 ;; last four elements are the resulting tones.
36 (defconst sisheng-vowel-table
37 '(("ā" "a" "ā" "á" "ǎ" "à")
38 ("ē" "e" "ē" "é" "ě" "è")
39 ("ī" "i" "ī" "í" "ǐ" "ì")
40 ("ō" "o" "ō" "ó" "ǒ" "ò")
41 ("ū" "u" "ū" "ú" "ǔ" "ù")
42 ("ǖ" "v" "ǖ" "ǘ" "ǚ" "ǜ")
43 ("üē" "ve" "üē" "üé" "üě" "üè")))
46 ;; All possible syllables in Mandarin Chinese, presented in the first
47 ;; tone. Note that make-sisheng-rules always constructs rules for all
48 ;; four tones even if some of those tones aren't used in Mandarin.
50 (defconst sisheng-syllable-table
51 '("ā" "āi" "ān" "āng" "āo"
53 "bā" "bāi" "bān" "bāng" "bāo"
55 "bī" "biān" "biāo" "biē" "bīn" "bīng"
59 "cā" "cāi" "cān" "cāng" "cāo"
63 "cū" "cuān" "cuī" "cūn" "cuō"
65 "chā" "chāi" "chān" "chāng" "chāo"
69 "chū" "chuā" "chuāi" "chuān" "chuāng" "chuī" "chūn" "chuō"
71 "dā" "dāi" "dān" "dāng" "dāo"
72 "dē" "dēi" "dēn" "dēng"
73 "dī" "diān" "diāo" "diē" "dīng" "diū"
75 "dū" "duān" "duī" "dūn" "duō"
77 "ē" "ēi" "ēn" "ēng" "ēr"
85 "gā" "gāi" "gān" "gāng" "gāo"
86 "gē" "gēi" "gēn" "gēng"
88 "gū" "guā" "guāi" "guān" "guāng" "guī" "gūn" "guō"
90 "hā" "hāi" "hān" "hāng" "hāo"
91 "hē" "hēi" "hēn" "hēng"
93 "hū" "huā" "huāi" "huān" "huāng" "huī" "hūn" "huō"
95 "jī" "jiā" "jiān" "jiāng" "jiāo" "jiē" "jīn" "jīng" "jiōng" "jiū"
96 "jū" "juān" "juē" "jūn"
98 "kā" "kāi" "kān" "kāng" "kāo"
99 "kē" "kēi" "kēn" "kēng"
101 "kū" "kuā" "kuāi" "kuān" "kuāng" "kuī" "kūn" "kuō"
103 "lā" "lāi" "lān" "lāng" "lāo"
105 "lī" "liā" "liān" "liāng" "liāo" "liē" "līn" "līng" "liū"
107 "lū" "luān" "lūn" "luō"
110 "mā" "māi" "mān" "māng" "māo"
111 "mē" "mēi" "mēn" "mēng"
112 "mī" "miān" "miāo" "miē" "mīn" "mīng" "miū"
116 "nā" "nāi" "nān" "nāng" "nāo"
117 "nē" "nēi" "nēn" "nēng"
118 "nī" "niān" "niāng" "niāo" "niē" "nīn" "nīng" "niū"
125 "pā" "pāi" "pān" "pāng" "pāo"
127 "pī" "piān" "piāo" "piē" "pīn" "pīng"
131 "qī" "qiā" "qiān" "qiāng" "qiāo" "qiē" "qīn" "qīng" "qiōng" "qiū"
132 "qū" "quān" "quē" "qūn"
138 "rū" "ruā" "ruān" "ruī" "rūn" "ruō"
140 "sā" "sāi" "sān" "sāng" "sāo"
144 "sū" "suān" "suī" "sūn" "suō"
146 "shā" "shāi" "shān" "shāng" "shāo"
147 "shē" "shēi" "shēn" "shēng"
150 "shū" "shuā" "shuāi" "shuān" "shuāng" "shuī" "shūn" "shuō"
152 "tā" "tāi" "tān" "tāng" "tāo"
154 "tī" "tiān" "tiāo" "tiē" "tīng"
156 "tū" "tuān" "tuī" "tūn" "tuō"
158 "wā" "wāi" "wān" "wāng"
163 "xī" "xiā" "xiān" "xiāng" "xiāo" "xiē" "xīn" "xīng" "xiōng" "xiū"
164 "xū" "xuān" "xuē" "xūn"
166 "yā" "yān" "yāng" "yāo"
170 "yū" "yuān" "yuē" "yūn"
172 "zā" "zāi" "zān" "zāng" "zāo"
173 "zē" "zēi" "zēn" "zēng"
176 "zū" "zuān" "zuī" "zūn" "zuō"
178 "zhā" "zhāi" "zhān" "zhāng" "zhāo"
179 "zhē" "zhēi" "zhēn" "zhēng"
182 "zhū" "zhuā" "zhuāi" "zhuān" "zhuāng" "zhuī" "zhūn" "zhuō"))
184 ;; This function converts e.g.
190 ;; (("zhuo4" ["zhuò"])
191 ;; ("zhuo3" ["zhuǒ"])
192 ;; ("zhuo2" ["zhuó"])
193 ;; ("zhuo1" ["zhuō"]))
195 (defun quail-make-sisheng-rules (syllable)
196 (let ((case-fold-search t
)
205 (string-match sisheng-regexp syllable
)
206 (setq vowel-match
(downcase (match-string 0 syllable
)))
208 (cdr (assoc-string vowel-match sisheng-vowel-table
)))
209 (setq input-vowel
(car vowel-list
))
210 (setq base-key
(replace-match input-vowel nil nil syllable
))
212 (setq key
(concat base-key
(number-to-string i
)))
213 (setq value
(vector (replace-match (nth i vowel-list
) nil nil syllable
)))
214 (push (list key value
) key-value-list
)
218 ;; Set up sisheng input method.
220 (quail-define-package
221 "chinese-sisheng" ; name
225 "Sìshēng input method for pīnyīn transliteration of Chinese.
227 Examples: shuang1 -> shuāng
231 Use the fifth (unstressed) tone for syllables containing `ü'
236 nil
; translation-keys
237 t
; forget-last-selection
241 nil
; create-decode-map
242 nil
; maximum-shortest
244 nil
; update-translation-function
245 nil
; conversion-keys
249 ;; Call quail-make-sisheng-rules for all syllables in sisheng-syllable-table.
251 (let ((case-table-save (current-case-table))
253 (set-case-table (standard-case-table))
254 (dolist (syllable sisheng-syllable-table
)
256 (append (quail-make-sisheng-rules syllable
)
259 (dolist (syllable sisheng-syllable-table
)
261 (append (quail-make-sisheng-rules (upcase-initials syllable
))
264 (dolist (syllable sisheng-syllable-table
)
266 (append (quail-make-sisheng-rules (upcase syllable
))
269 (eval `(quail-define-rules
286 (set-case-table case-table-save
))
292 ;;; arch-tag: 1fa6ba5f-6747-44bc-bf12-30628ad3e8ad