summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-06-06 10:38:08 +0800
committerPeng Wu <alexepico@gmail.com>2012-06-06 10:38:08 +0800
commit949bfb012c97a71435e627ed48b4f2205a6a7d39 (patch)
treeb59c76522da8b94057ed4de37392d12844e871a0 /scripts
parent4d8398255acc7556bb45c34cd2cb77dbe6d2ae3e (diff)
clean scripts
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bopomofo.py517
-rw-r--r--scripts/double.py40
-rw-r--r--scripts/genbopomofokeyboard.py100
-rw-r--r--scripts/genpytable.py439
4 files changed, 0 insertions, 1096 deletions
diff --git a/scripts/bopomofo.py b/scripts/bopomofo.py
deleted file mode 100644
index 05f1327..0000000
--- a/scripts/bopomofo.py
+++ /dev/null
@@ -1,517 +0,0 @@
-# vim:set et sts=4:
-# -*- coding: utf-8 -*-
-
-'''
-const static gunichar bopomofo_char[] = {
- L'\0',L'ㄅ',L'ㄆ',L'ㄇ',L'ㄈ',L'ㄉ',L'ㄊ',L'ㄋ',L'ㄌ',L'ㄍ',L'ㄎ',
- L'ㄏ',L'ㄐ',L'ㄑ',L'ㄒ',L'ㄓ',L'ㄔ',L'ㄕ',L'ㄖ',L'ㄗ',L'ㄘ',L'ㄙ',
-
- L'ㄧ',L'ㄨ',L'ㄩ',L'ㄚ',L'ㄛ',L'ㄜ',L'ㄝ',L'ㄞ',L'ㄟ',L'ㄠ',L'ㄡ',
- L'ㄢ',L'ㄣ',L'ㄤ',L'ㄥ',L'ㄦ',
-
- L'ˊ',L'ˇ',L'ˋ',L'˙',
-};
-'''
-
-bopomofo_pinyin_map = {
- "ㄅ" : "b",
- "ㄅㄚ" : "ba",
- "ㄅㄛ" : "bo",
- "ㄅㄞ" : "bai",
- "ㄅㄟ" : "bei",
- "ㄅㄠ" : "bao",
- "ㄅㄢ" : "ban",
- "ㄅㄣ" : "ben",
- "ㄅㄤ" : "bang",
- "ㄅㄥ" : "beng",
- "ㄅㄧ" : "bi",
- "ㄅㄧㄝ" : "bie",
- "ㄅㄧㄠ" : "biao",
- "ㄅㄧㄢ" : "bian",
- "ㄅㄧㄣ" : "bin",
- "ㄅㄧㄥ" : "bing",
- "ㄅㄨ" : "bu",
- "ㄆ" : "p",
- "ㄆㄚ" : "pa",
- "ㄆㄛ" : "po",
- "ㄆㄞ" : "pai",
- "ㄆㄟ" : "pei",
- "ㄆㄠ" : "pao",
- "ㄆㄡ" : "pou",
- "ㄆㄢ" : "pan",
- "ㄆㄣ" : "pen",
- "ㄆㄤ" : "pang",
- "ㄆㄥ" : "peng",
- "ㄆㄧ" : "pi",
- "ㄆㄧㄝ" : "pie",
- "ㄆㄧㄠ" : "piao",
- "ㄆㄧㄢ" : "pian",
- "ㄆㄧㄣ" : "pin",
- "ㄆㄧㄥ" : "ping",
- "ㄆㄨ" : "pu",
- "ㄇ" : "m",
- "ㄇㄚ" : "ma",
- "ㄇㄛ" : "mo",
- "ㄇㄜ" : "me",
- "ㄇㄞ" : "mai",
- "ㄇㄟ" : "mei",
- "ㄇㄠ" : "mao",
- "ㄇㄡ" : "mou",
- "ㄇㄢ" : "man",
- "ㄇㄣ" : "men",
- "ㄇㄤ" : "mang",
- "ㄇㄥ" : "meng",
- "ㄇㄧ" : "mi",
- "ㄇㄧㄝ" : "mie",
- "ㄇㄧㄠ" : "miao",
- "ㄇㄧㄡ" : "miu",
- "ㄇㄧㄢ" : "mian",
- "ㄇㄧㄣ" : "min",
- "ㄇㄧㄥ" : "ming",
- "ㄇㄨ" : "mu",
- "ㄈ" : "f",
- "ㄈㄚ" : "fa",
- "ㄈㄛ" : "fo",
- "ㄈㄜ" : "fe",
- "ㄈㄟ" : "fei",
- "ㄈㄡ" : "fou",
- "ㄈㄢ" : "fan",
- "ㄈㄣ" : "fen",
- "ㄈㄤ" : "fang",
- "ㄈㄥ" : "feng",
- "ㄈㄨ" : "fu",
- "ㄉ" : "d",
- "ㄉㄚ" : "da",
- "ㄉㄜ" : "de",
- "ㄉㄞ" : "dai",
- "ㄉㄟ" : "dei",
- "ㄉㄠ" : "dao",
- "ㄉㄡ" : "dou",
- "ㄉㄢ" : "dan",
- "ㄉㄣ" : "den",
- "ㄉㄤ" : "dang",
- "ㄉㄥ" : "deng",
- "ㄉㄧ" : "di",
- "ㄉㄧㄚ" : "dia",
- "ㄉㄧㄝ" : "die",
- "ㄉㄧㄠ" : "diao",
- "ㄉㄧㄡ" : "diu",
- "ㄉㄧㄢ" : "dian",
- "ㄉㄧㄣ" : "din",
- "ㄉㄧㄥ" : "ding",
- "ㄉㄨ" : "du",
- "ㄉㄨㄛ" : "duo",
- "ㄉㄨㄟ" : "dui",
- "ㄉㄨㄢ" : "duan",
- "ㄉㄨㄣ" : "dun",
- "ㄉㄨㄥ" : "dong",
- "ㄊ" : "t",
- "ㄊㄚ" : "ta",
- "ㄊㄜ" : "te",
- "ㄊㄞ" : "tai",
- "ㄊㄠ" : "tao",
- "ㄊㄡ" : "tou",
- "ㄊㄢ" : "tan",
- "ㄊㄤ" : "tang",
- "ㄊㄥ" : "teng",
- "ㄊㄧ" : "ti",
- "ㄊㄧㄝ" : "tie",
- "ㄊㄧㄠ" : "tiao",
- "ㄊㄧㄢ" : "tian",
- "ㄊㄧㄥ" : "ting",
- "ㄊㄨ" : "tu",
- "ㄊㄨㄛ" : "tuo",
- "ㄊㄨㄟ" : "tui",
- "ㄊㄨㄢ" : "tuan",
- "ㄊㄨㄣ" : "tun",
- "ㄊㄨㄥ" : "tong",
- "ㄋ" : "n",
- "ㄋㄚ" : "na",
- "ㄋㄜ" : "ne",
- "ㄋㄞ" : "nai",
- "ㄋㄟ" : "nei",
- "ㄋㄠ" : "nao",
- "ㄋㄡ" : "nou",
- "ㄋㄢ" : "nan",
- "ㄋㄣ" : "nen",
- "ㄋㄤ" : "nang",
- "ㄋㄥ" : "neng",
- "ㄋㄧ" : "ni",
- "ㄋㄧㄚ" : "nia",
- "ㄋㄧㄝ" : "nie",
- "ㄋㄧㄠ" : "niao",
- "ㄋㄧㄡ" : "niu",
- "ㄋㄧㄢ" : "nian",
- "ㄋㄧㄣ" : "nin",
- "ㄋㄧㄤ" : "niang",
- "ㄋㄧㄥ" : "ning",
- "ㄋㄨ" : "nu",
- "ㄋㄨㄛ" : "nuo",
- "ㄋㄨㄢ" : "nuan",
- "ㄋㄨㄣ" : "nun",
- "ㄋㄨㄥ" : "nong",
- "ㄋㄩ" : "nv",
- "ㄋㄩㄝ" : "nve",
- "ㄌ" : "l",
- "ㄌㄚ" : "la",
- "ㄌㄛ" : "lo",
- "ㄌㄜ" : "le",
- "ㄌㄞ" : "lai",
- "ㄌㄟ" : "lei",
- "ㄌㄠ" : "lao",
- "ㄌㄡ" : "lou",
- "ㄌㄢ" : "lan",
- "ㄌㄣ" : "len",
- "ㄌㄤ" : "lang",
- "ㄌㄥ" : "leng",
- "ㄌㄧ" : "li",
- "ㄌㄧㄚ" : "lia",
- "ㄌㄧㄝ" : "lie",
- "ㄌㄧㄠ" : "liao",
- "ㄌㄧㄡ" : "liu",
- "ㄌㄧㄢ" : "lian",
- "ㄌㄧㄣ" : "lin",
- "ㄌㄧㄤ" : "liang",
- "ㄌㄧㄥ" : "ling",
- "ㄌㄨ" : "lu",
- "ㄌㄨㄛ" : "luo",
- "ㄌㄨㄢ" : "luan",
- "ㄌㄨㄣ" : "lun",
- "ㄌㄨㄥ" : "long",
- "ㄌㄩ" : "lv",
- "ㄌㄩㄝ" : "lve",
- "ㄍ" : "g",
- "ㄍㄚ" : "ga",
- "ㄍㄜ" : "ge",
- "ㄍㄞ" : "gai",
- "ㄍㄟ" : "gei",
- "ㄍㄠ" : "gao",
- "ㄍㄡ" : "gou",
- "ㄍㄢ" : "gan",
- "ㄍㄣ" : "gen",
- "ㄍㄤ" : "gang",
- "ㄍㄥ" : "geng",
- "ㄍㄨ" : "gu",
- "ㄍㄨㄚ" : "gua",
- "ㄍㄨㄛ" : "guo",
- "ㄍㄨㄞ" : "guai",
- "ㄍㄨㄟ" : "gui",
- "ㄍㄨㄢ" : "guan",
- "ㄍㄨㄣ" : "gun",
- "ㄍㄨㄤ" : "guang",
- "ㄍㄨㄥ" : "gong",
- "ㄎ" : "k",
- "ㄎㄚ" : "ka",
- "ㄎㄜ" : "ke",
- "ㄎㄞ" : "kai",
- "ㄎㄟ" : "kei",
- "ㄎㄠ" : "kao",
- "ㄎㄡ" : "kou",
- "ㄎㄢ" : "kan",
- "ㄎㄣ" : "ken",
- "ㄎㄤ" : "kang",
- "ㄎㄥ" : "keng",
- "ㄎㄨ" : "ku",
- "ㄎㄨㄚ" : "kua",
- "ㄎㄨㄛ" : "kuo",
- "ㄎㄨㄞ" : "kuai",
- "ㄎㄨㄟ" : "kui",
- "ㄎㄨㄢ" : "kuan",
- "ㄎㄨㄣ" : "kun",
- "ㄎㄨㄤ" : "kuang",
- "ㄎㄨㄥ" : "kong",
- "ㄏ" : "h",
- "ㄏㄚ" : "ha",
- "ㄏㄜ" : "he",
- "ㄏㄞ" : "hai",
- "ㄏㄟ" : "hei",
- "ㄏㄠ" : "hao",
- "ㄏㄡ" : "hou",
- "ㄏㄢ" : "han",
- "ㄏㄣ" : "hen",
- "ㄏㄤ" : "hang",
- "ㄏㄥ" : "heng",
- "ㄏㄨ" : "hu",
- "ㄏㄨㄚ" : "hua",
- "ㄏㄨㄛ" : "huo",
- "ㄏㄨㄞ" : "huai",
- "ㄏㄨㄟ" : "hui",
- "ㄏㄨㄢ" : "huan",
- "ㄏㄨㄣ" : "hun",
- "ㄏㄨㄤ" : "huang",
- "ㄏㄨㄥ" : "hong",
- "ㄐ" : "j",
- "ㄐㄧ" : "ji",
- "ㄐㄧㄚ" : "jia",
- "ㄐㄧㄝ" : "jie",
- "ㄐㄧㄠ" : "jiao",
- "ㄐㄧㄡ" : "jiu",
- "ㄐㄧㄢ" : "jian",
- "ㄐㄧㄣ" : "jin",
- "ㄐㄧㄤ" : "jiang",
- "ㄐㄧㄥ" : "jing",
- "ㄐㄩ" : "ju",
- "ㄐㄩㄝ" : "jue",
- "ㄐㄩㄢ" : "juan",
- "ㄐㄩㄣ" : "jun",
- "ㄐㄩㄥ" : "jiong",
- "ㄑ" : "q",
- "ㄑㄧ" : "qi",
- "ㄑㄧㄚ" : "qia",
- "ㄑㄧㄝ" : "qie",
- "ㄑㄧㄠ" : "qiao",
- "ㄑㄧㄡ" : "qiu",
- "ㄑㄧㄢ" : "qian",
- "ㄑㄧㄣ" : "qin",
- "ㄑㄧㄤ" : "qiang",
- "ㄑㄧㄥ" : "qing",
- "ㄑㄩ" : "qu",
- "ㄑㄩㄝ" : "que",
- "ㄑㄩㄢ" : "quan",
- "ㄑㄩㄣ" : "qun",
- "ㄑㄩㄥ" : "qiong",
- "ㄒ" : "x",
- "ㄒㄧ" : "xi",
- "ㄒㄧㄚ" : "xia",
- "ㄒㄧㄝ" : "xie",
- "ㄒㄧㄠ" : "xiao",
- "ㄒㄧㄡ" : "xiu",
- "ㄒㄧㄢ" : "xian",
- "ㄒㄧㄣ" : "xin",
- "ㄒㄧㄤ" : "xiang",
- "ㄒㄧㄥ" : "xing",
- "ㄒㄩ" : "xu",
- "ㄒㄩㄝ" : "xue",
- "ㄒㄩㄢ" : "xuan",
- "ㄒㄩㄣ" : "xun",
- "ㄒㄩㄥ" : "xiong",
- "ㄓ" : "zhi",
- "ㄓㄚ" : "zha",
- "ㄓㄜ" : "zhe",
- "ㄓㄞ" : "zhai",
- "ㄓㄟ" : "zhei",
- "ㄓㄠ" : "zhao",
- "ㄓㄡ" : "zhou",
- "ㄓㄢ" : "zhan",
- "ㄓㄣ" : "zhen",
- "ㄓㄤ" : "zhang",
- "ㄓㄥ" : "zheng",
- "ㄓㄨ" : "zhu",
- "ㄓㄨㄚ" : "zhua",
- "ㄓㄨㄛ" : "zhuo",
- "ㄓㄨㄞ" : "zhuai",
- "ㄓㄨㄟ" : "zhui",
- "ㄓㄨㄢ" : "zhuan",
- "ㄓㄨㄣ" : "zhun",
- "ㄓㄨㄤ" : "zhuang",
- "ㄓㄨㄥ" : "zhong",
- "ㄔ" : "chi",
- "ㄔㄚ" : "cha",
- "ㄔㄜ" : "che",
- "ㄔㄞ" : "chai",
- "ㄔㄠ" : "chao",
- "ㄔㄡ" : "chou",
- "ㄔㄢ" : "chan",
- "ㄔㄣ" : "chen",
- "ㄔㄤ" : "chang",
- "ㄔㄥ" : "cheng",
- "ㄔㄨ" : "chu",
- "ㄔㄨㄚ" : "chua",
- "ㄔㄨㄛ" : "chuo",
- "ㄔㄨㄞ" : "chuai",
- "ㄔㄨㄟ" : "chui",
- "ㄔㄨㄢ" : "chuan",
- "ㄔㄨㄣ" : "chun",
- "ㄔㄨㄤ" : "chuang",
- "ㄔㄨㄥ" : "chong",
- "ㄕ" : "shi",
- "ㄕㄚ" : "sha",
- "ㄕㄜ" : "she",
- "ㄕㄞ" : "shai",
- "ㄕㄟ" : "shei",
- "ㄕㄠ" : "shao",
- "ㄕㄡ" : "shou",
- "ㄕㄢ" : "shan",
- "ㄕㄣ" : "shen",
- "ㄕㄤ" : "shang",
- "ㄕㄥ" : "sheng",
- "ㄕㄨ" : "shu",
- "ㄕㄨㄚ" : "shua",
- "ㄕㄨㄛ" : "shuo",
- "ㄕㄨㄞ" : "shuai",
- "ㄕㄨㄟ" : "shui",
- "ㄕㄨㄢ" : "shuan",
- "ㄕㄨㄣ" : "shun",
- "ㄕㄨㄤ" : "shuang",
- "ㄖ" : "ri",
- "ㄖㄜ" : "re",
- "ㄖㄠ" : "rao",
- "ㄖㄡ" : "rou",
- "ㄖㄢ" : "ran",
- "ㄖㄣ" : "ren",
- "ㄖㄤ" : "rang",
- "ㄖㄥ" : "reng",
- "ㄖㄨ" : "ru",
- "ㄖㄨㄚ" : "rua",
- "ㄖㄨㄛ" : "ruo",
- "ㄖㄨㄟ" : "rui",
- "ㄖㄨㄢ" : "ruan",
- "ㄖㄨㄣ" : "run",
- "ㄖㄨㄥ" : "rong",
- "ㄗ" : "zi",
- "ㄗㄚ" : "za",
- "ㄗㄜ" : "ze",
- "ㄗㄞ" : "zai",
- "ㄗㄟ" : "zei",
- "ㄗㄠ" : "zao",
- "ㄗㄡ" : "zou",
- "ㄗㄢ" : "zan",
- "ㄗㄣ" : "zen",
- "ㄗㄤ" : "zang",
- "ㄗㄥ" : "zeng",
- "ㄗㄨ" : "zu",
- "ㄗㄨㄛ" : "zuo",
- "ㄗㄨㄟ" : "zui",
- "ㄗㄨㄢ" : "zuan",
- "ㄗㄨㄣ" : "zun",
- "ㄗㄨㄥ" : "zong",
- "ㄘ" : "ci",
- "ㄘㄚ" : "ca",
- "ㄘㄜ" : "ce",
- "ㄘㄞ" : "cai",
- "ㄘㄠ" : "cao",
- "ㄘㄡ" : "cou",
- "ㄘㄢ" : "can",
- "ㄘㄣ" : "cen",
- "ㄘㄤ" : "cang",
- "ㄘㄥ" : "ceng",
- "ㄘㄨ" : "cu",
- "ㄘㄨㄛ" : "cuo",
- "ㄘㄨㄟ" : "cui",
- "ㄘㄨㄢ" : "cuan",
- "ㄘㄨㄣ" : "cun",
- "ㄘㄨㄥ" : "cong",
- "ㄙ" : "si",
- "ㄙㄚ" : "sa",
- "ㄙㄜ" : "se",
- "ㄙㄞ" : "sai",
- "ㄙㄠ" : "sao",
- "ㄙㄡ" : "sou",
- "ㄙㄢ" : "san",
- "ㄙㄣ" : "sen",
- "ㄙㄤ" : "sang",
- "ㄙㄥ" : "seng",
- "ㄙㄨ" : "su",
- "ㄙㄨㄛ" : "suo",
- "ㄙㄨㄟ" : "sui",
- "ㄙㄨㄢ" : "suan",
- "ㄙㄨㄣ" : "sun",
- "ㄙㄨㄥ" : "song",
- "ㄚ" : "a",
- "ㄛ" : "o",
- "ㄜ" : "e",
- "ㄞ" : "ai",
- "ㄟ" : "ei",
- "ㄠ" : "ao",
- "ㄡ" : "ou",
- "ㄢ" : "an",
- "ㄣ" : "en",
- "ㄤ" : "ang",
- "ㄥ" : "eng",
- "ㄦ" : "er",
- "ㄧ" : "yi",
- "ㄧㄚ" : "ya",
- "ㄧㄛ" : "yo",
- "ㄧㄝ" : "ye",
- "ㄧㄞ" : "yai",
- "ㄧㄠ" : "yao",
- "ㄧㄡ" : "you",
- "ㄧㄢ" : "yan",
- "ㄧㄣ" : "yin",
- "ㄧㄤ" : "yang",
- "ㄧㄥ" : "ying",
- "ㄨ" : "wu",
- "ㄨㄚ" : "wa",
- "ㄨㄛ" : "wo",
- "ㄨㄞ" : "wai",
- "ㄨㄟ" : "wei",
- "ㄨㄢ" : "wan",
- "ㄨㄣ" : "wen",
- "ㄨㄤ" : "wang",
- "ㄨㄥ" : "weng",
- "ㄩ" : "yu",
- "ㄩㄝ" : "yue",
- "ㄩㄢ" : "yuan",
- "ㄩㄣ" : "yun",
- "ㄩㄥ" : "yong",
-}
-
-pinyin_bopomofo_map = dict([(v, k) for k, v in bopomofo_pinyin_map.items()])
-
-sheng_yun_bopomofo_map = {
- "b" : "ㄅ",
- "p" : "ㄆ",
- "m" : "ㄇ",
- "f" : "ㄈ",
- "d" : "ㄉ",
- "t" : "ㄊ",
- "n" : "ㄋ",
- "l" : "ㄌ",
- "g" : "ㄍ",
- "k" : "ㄎ",
- "h" : "ㄏ",
- "j" : "ㄐ",
- "q" : "ㄑ",
- "x" : "ㄒ",
- "zh" : "ㄓ",
- "ch" : "ㄔ",
- "sh" : "ㄕ",
- "r" : "ㄖ",
- "z" : "ㄗ",
- "c" : "ㄘ",
- "s" : "ㄙ",
-
- # 韻母為u,ue,un,uan,ong時ㄧ省略
- "y" : ("ㄧ", (("u", "ue", "un", "uan", "ong"), "")),
- "w" : "ㄨ",
- "a" : "ㄚ",
- "o" : "ㄛ",
- "e" : ("ㄜ", ("y", "ㄝ")), # y後面為ㄝ
-
- # zh ch sh r z c s y後面為空
- "i" : ("ㄧ", (("zh", "ch", "sh", "r", "z", "c", "s", "y"), "")),
-
- # jqxy後面為ㄩ w後面為空
- "u" : ("ㄨ", ("jqxy", "ㄩ")),
- "v" : "ㄩ",
- "ai" : "ㄞ",
- "ei" : "ㄟ",
- "ao" : "ㄠ",
- "ou" : "ㄡ",
- "an" : "ㄢ",
- "en" : "ㄣ",
- "ang" : "ㄤ",
- "eng" : "ㄥ",
- "er" : "ㄦ",
- "ia" : "ㄧㄚ",
- "ie" : "ㄧㄝ",
- "iai" : "ㄧㄞ",
- "iao" : "ㄧㄠ",
- "iu" : "ㄧㄡ",
- "ian" : "ㄧㄢ",
- "in" : ("ㄧㄣ", ("y", "ㄣ")), #y後面為ㄣ
- "iang" : "ㄧㄤ",
- "ing" : ("ㄧㄥ", ("y", "ㄥ")), #y後面為ㄥ
- "ua" : "ㄨㄚ",
- "uo" : "ㄨㄛ",
- "ue" : "ㄩㄝ",
- # TODO: "ve" is OK?
- "ve" : "ㄩㄝ",
- "uai" : "ㄨㄞ",
- "ui" : "ㄨㄟ",
- "uan" : ("ㄨㄢ", ("jqxy", "ㄩㄢ")), # jqxy後面是ㄩㄢ
- "un" : ("ㄨㄣ", ("jqxy", "ㄩㄣ")), # jqxy後面是ㄩㄣ
- "uang" : ("ㄨㄤ", ("jqxy", "ㄩㄤ")), # jqxy後面是ㄩㄤ
- "ong" : ("ㄨㄥ", ("jqxy", "ㄩㄥ")), # y後面為ㄩㄥ
- "iong" : "ㄩㄥ",
-}
diff --git a/scripts/double.py b/scripts/double.py
deleted file mode 100644
index 58ad664..0000000
--- a/scripts/double.py
+++ /dev/null
@@ -1,40 +0,0 @@
-import pydict
-
-for name, (sheng, yun) in pydict.SHUANGPIN_SCHEMAS:
- print "static const gint8 double_pinyin_%s_sheng[] = {" % name.lower()
- for c in "abcdefghijklmnopqrstuvwxyz;":
- s = sheng.get(c, "VOID")
- if s == "'":
- s = "ZERO"
- else:
- s = s.upper()
- if s == "VOID" and c in ("a", "e", "o"):
- s = "AEO"
- print " PINYIN_ID_%s // %s" % ((s + ",").ljust(5), c.upper())
- print "};"
-
- print "static const gint8 double_pinyin_%s_yun[][2] = {" % name.lower()
- for c in "abcdefghijklmnopqrstuvwxyz;":
- s = yun.get(c, ("VOID", "VOID"))
- if len(s) == 1:
- s1 = s[0]
- s2 = "VOID"
- else:
- s1, s2 = s
- if s1 == "'":
- s1 = "ZERO"
- if s2 == "'":
- s2 = "ZERO"
- s1 = s1.upper()
- s2 = s2.upper()
- print " { PINYIN_ID_%s PINYIN_ID_%s }, // %s" % ((s1 + ",").ljust(5), s2.ljust(4), c.upper())
- print "};"
-
-print '''
-static const struct {
- const gint8 (&sheng)[27];
- const gint8 (&yun)[27][2];
-} double_pinyin_map [] = {'''
-for name, (sheng, yun) in pydict.SHUANGPIN_SCHEMAS:
- print " { double_pinyin_%s_sheng, double_pinyin_%s_yun}," % (name.lower(), name.lower())
-print "};"
diff --git a/scripts/genbopomofokeyboard.py b/scripts/genbopomofokeyboard.py
deleted file mode 100644
index 5ad0676..0000000
--- a/scripts/genbopomofokeyboard.py
+++ /dev/null
@@ -1,100 +0,0 @@
-# vim:set et sts=4:
-# -*- coding: utf-8 -*-
-
-bopomofo = [
-"BOPOMOFO_ZERO",
-"BOPOMOFO_B",
-"BOPOMOFO_P",
-"BOPOMOFO_M",
-"BOPOMOFO_F",
-"BOPOMOFO_D",
-"BOPOMOFO_T",
-"BOPOMOFO_N",
-"BOPOMOFO_L",
-"BOPOMOFO_G",
-"BOPOMOFO_K",
-"BOPOMOFO_H",
-"BOPOMOFO_J",
-"BOPOMOFO_Q",
-"BOPOMOFO_X",
-"BOPOMOFO_ZH",
-"BOPOMOFO_CH",
-"BOPOMOFO_SH",
-"BOPOMOFO_R",
-"BOPOMOFO_Z",
-"BOPOMOFO_C",
-"BOPOMOFO_S",
-"BOPOMOFO_I",
-"BOPOMOFO_U",
-"BOPOMOFO_V",
-"BOPOMOFO_A",
-"BOPOMOFO_O",
-"BOPOMOFO_E",
-"BOPOMOFO_E2",
-"BOPOMOFO_AI",
-"BOPOMOFO_EI",
-"BOPOMOFO_AO",
-"BOPOMOFO_OU",
-"BOPOMOFO_AN",
-"BOPOMOFO_EN",
-"BOPOMOFO_ANG",
-"BOPOMOFO_ENG",
-"BOPOMOFO_ER",
-"BOPOMOFO_TONE_2",
-"BOPOMOFO_TONE_3",
-"BOPOMOFO_TONE_4",
-"BOPOMOFO_TONE_5",
-]
-
-bopomofo_keyboard = (
- #標準注音鍵盤
- (
- "1","q","a","z","2","w","s","x","e","d","c","r","f","v","5","t","g","b","y","h","n",
- "u","j","m","8","i","k",",","9","o","l",".","0","p",";","/","-",
- "6","3","4","7",
- ),
- #精業注音鍵盤
- (
- "2","w","s","x","3","e","d","c","r","f","v","t","g","b","6","y","h","n","u","j","m",
- "-","[","'","8","i","k",",","9","o","l",".","0","p",";","/","=",
- "q","a","z","1",
- ),
- #倚天注音鍵盤
- (
- "b","p","m","f","d","t","n","l","v","k","h","g","7","c",",",".","/","j",";","'","s",
- "e","x","u","a","o","r","w","i","q","z","y","8","9","0","-","=",
- "2","3","4","1",
- ),
- #IBM注音鍵盤
- (
- "1","2","3","4","5","6","7","8","9","0","-","q","w","e","r","t","y","u","i","o","p",
- "a","s","d","f","g","h","j","k","l",";","z","x","c","v","b","n",
- "m",",",".","/",
- ),
-)
-
-def tochar(ch):
- if ch == "'" or ch == "\\":
- ch = "\\" + ch;
- return "'" + ch + "'"
-
-def gen_table():
- i = 0
- print 'static const guint8'
- print 'bopomofo_keyboard[][41][2] = {'
- for keyboard in bopomofo_keyboard:
- print ' {'
- items = []
- i=1
- for v in keyboard:
- items.append ((v,bopomofo[i]));
- i += 1
- items.sort()
- for k,v in items:
- print ' { %-4s, %-15s },' % (tochar(k),v)
- print ' },'
- print '};'
- print
-
-if __name__ == "__main__":
- gen_table()
diff --git a/scripts/genpytable.py b/scripts/genpytable.py
deleted file mode 100644
index 5dfe2d0..0000000
--- a/scripts/genpytable.py
+++ /dev/null
@@ -1,439 +0,0 @@
-# vim:set et sts=4:
-# -*- coding: utf-8 -*-
-
-from pydict import *
-from bopomofo import *
-
-def str_cmp(a, b):
- if len(a) == len(b):
- return cmp(a, b)
- else:
- return len(a) - len(b)
-
-pinyin_list = PINYIN_DICT.keys()
-pinyin_list.sort()
-
-shengmu_list = SHENGMU_DICT.keys()
-shengmu_list.remove("")
-shengmu_list.sort()
-
-auto_correct = [
- # "correct", "wrong"
- ("ng", "gn"),
- ("ng", "mg"),
- ("iu", "iou"),
- ("ui", "uei"),
- ("un", "uen"),
-# ("ue", "ve"),
- ("ve", "ue"),
- ("ong", "on"),
-]
-
-auto_correct_ext = [
- # "correct", "wrong", flag
- ("ju", "jv", "PINYIN_CORRECT_V_TO_U"),
- ("qu", "qv", "PINYIN_CORRECT_V_TO_U"),
- ("xu", "xv", "PINYIN_CORRECT_V_TO_U"),
- ("yu", "yv", "PINYIN_CORRECT_V_TO_U"),
-
- ("jue", "jve", "PINYIN_CORRECT_V_TO_U"),
- ("que", "qve", "PINYIN_CORRECT_V_TO_U"),
- ("xue", "xve", "PINYIN_CORRECT_V_TO_U"),
- ("yue", "yve", "PINYIN_CORRECT_V_TO_U"),
-
- ("juan", "jvan", "PINYIN_CORRECT_V_TO_U"),
- ("quan", "qvan", "PINYIN_CORRECT_V_TO_U"),
- ("xuan", "xvan", "PINYIN_CORRECT_V_TO_U"),
- ("yuan", "yvan", "PINYIN_CORRECT_V_TO_U"),
-
- ("jun", "jvn", "PINYIN_CORRECT_V_TO_U"),
- ("qun", "qvn", "PINYIN_CORRECT_V_TO_U"),
- ("xun", "xvn", "PINYIN_CORRECT_V_TO_U"),
- ("yun", "yvn", "PINYIN_CORRECT_V_TO_U"),
-
- ("juang", "jvang", "PINYIN_FUZZY_UANG_UAN | PINYIN_CORRECT_V_TO_U"),
- ("quang", "qvang", "PINYIN_FUZZY_UANG_UAN | PINYIN_CORRECT_V_TO_U"),
- ("xuang", "xvang", "PINYIN_FUZZY_UANG_UAN | PINYIN_CORRECT_V_TO_U"),
- ("yuang", "yvang", "PINYIN_FUZZY_UANG_UAN | PINYIN_CORRECT_V_TO_U"),
-
- ("jun", "jven", "PINYIN_CORRECT_UEN_TO_UN | PINYIN_CORRECT_V_TO_U"),
- ("qun", "qven", "PINYIN_CORRECT_UEN_TO_UN | PINYIN_CORRECT_V_TO_U"),
- ("xun", "xven", "PINYIN_CORRECT_UEN_TO_UN | PINYIN_CORRECT_V_TO_U"),
- ("yun", "yven", "PINYIN_CORRECT_UEN_TO_UN | PINYIN_CORRECT_V_TO_U"),
-]
-
-fuzzy_shengmu = [
- ("c", "ch"),
- ("ch", "c"),
- ("z", "zh"),
- ("zh", "z"),
- ("s", "sh"),
- ("sh", "s"),
- ("l", "n"),
- ("n", "l"),
- ("f", "h"),
- ("h", "f"),
- ("l", "r"),
- ("r", "l"),
- ("k", "g"),
- ("g", "k"),
-]
-
-fuzzy_yunmu = [
- ("an", "ang"),
- ("ang", "an"),
- ("en", "eng"),
- ("eng", "en"),
- ("in", "ing"),
- ("ing", "in"),
- ("ian", "iang"),
- ("iang", "ian"),
- ("uan", "uang"),
- ("uang", "uan"),
-]
-
-def get_sheng_yun(pinyin):
- if pinyin == None:
- return None, None
- if pinyin == "ng":
- return "", "ng"
- for i in range(2, 0, -1):
- s = pinyin[:i]
- if s in shengmu_list:
- return s, pinyin[i:]
- return "", pinyin
-
-yunmu_list = set([])
-for p in pinyin_list:
- s, y = get_sheng_yun(p)
- yunmu_list |= set([y])
-yunmu_list = list(yunmu_list)
-yunmu_list.sort()
-
-shengmu_yunmu_list = shengmu_list + yunmu_list
-id_dict = {}
-for i, y in enumerate(shengmu_yunmu_list):
- id_dict[y] = i + 1
-
-fuzzy_shengmu_dict = {}
-for s1, s2 in fuzzy_shengmu:
- if s1 not in fuzzy_shengmu_dict:
- fuzzy_shengmu_dict[s1] = []
- fuzzy_shengmu_dict[s1].append(s2)
-
-fuzzy_yunmu_dict = {}
-for y1, y2 in fuzzy_yunmu:
- if y1 not in fuzzy_yunmu_dict:
- fuzzy_yunmu_dict[y1] = []
- fuzzy_yunmu_dict[y1].append(y2)
-
-def encode_pinyin(pinyin):
- if pinyin == None or pinyin == "":
- return 0
- return id_dict[pinyin]
-
- e = 0
- for c in pinyin:
- e = (e << 5) + (ord(c) - ord('a') + 1)
- return e
-
-def get_pinyin():
- for p in pinyin_list:
- s, y = get_sheng_yun(p)
- yield p, s, y, len(p), []
-
- for s in shengmu_list:
- yield s, s, "", len(s), ["PINYIN_INCOMPLETE_PINYIN"]
-
- for c, w in auto_correct:
- flag = "PINYIN_CORRECT_%s_TO_%s" % (w.upper(), c.upper())
- for p in pinyin_list:
- if p.endswith(c) and p != c:
- wp = p.replace(c, w)
- s, y = get_sheng_yun(p)
- yield wp, s, y, len(wp), [flag]
-
- for c, w, flag in auto_correct_ext:
- s, y = get_sheng_yun(c)
- yield w, s, y, len(w), [flag]
-
- for s1, s2 in fuzzy_shengmu:
- flag = "PINYIN_FUZZY_%s_%s" % (s1.upper(), s2.upper())
- for y in yunmu_list:
- if s1 + y not in pinyin_list and s2 + y in pinyin_list:
- yield s1 + y, s1, y, len(s1) + len(y), [flag]
- for c, w in auto_correct:
- if s1 + w not in pinyin_list and \
- s1 + c not in pinyin_list and \
- s2 + w not in pinyin_list and \
- s2 + c in pinyin_list:
- flag_correct = "PINYIN_CORRECT_%s_TO_%s" % (w.upper(), c.upper())
- yield s1 + w, s1, c, len(s2) + len(w), ["%s | %s" % (flag, flag_correct)]
-
- # if s2 + y not in pinyin_list and s1 + y in pinyin_list:
- # yield s2 + y, s2, y, len (s2) + len(y), [flag]
-
- for y1, y2 in fuzzy_yunmu:
- flag = "PINYIN_FUZZY_%s_%s" % (y1.upper(), y2.upper())
- for s in shengmu_list:
- if s + y1 not in pinyin_list and s + y2 in pinyin_list:
- yield s + y1, s, y1, len(s) + len(y1), [flag]
- # if s + y2 not in pinyin_list and s + y1 in pinyin_list:
- # yield s + y2, s, y2, len(s) + len(y2), [flag]
-
-
-def get_pinyin_with_fuzzy():
- for text, s, y, l, flags in get_pinyin():
- fss = fuzzy_shengmu_dict.get(s, ["", ""])
- fys = fuzzy_yunmu_dict.get(y, ["", ""])
-
- try:
- fs1, fs2 = fss
- except:
- fs1, fs2 = fss[0], ""
-
- try:
- fy1, fy2 = fys
- except:
- fy1, fy2 = fys[0], ""
-
- if fs1 and \
- (fs1 + y not in pinyin_list) and \
- (fy1 and fs1 + fy1 not in pinyin_list) and \
- (fy2 and fs1 + fy2 not in pinyin_list):
- fs1 = ""
-
- if fs2 and \
- (fs2 + y not in pinyin_list) and \
- (fy1 and fs2 + fy1 not in pinyin_list) and \
- (fy2 and fs2 + fy2 not in pinyin_list):
- fs2 = ""
-
- if fy1 and \
- (s + fy1 not in pinyin_list) and \
- (fs1 and fs1 + fy1 not in pinyin_list) and \
- (fs2 and fs2 + fy1 not in pinyin_list):
- fy1 = ""
-
- if fy2 and \
- (s + fy2 not in pinyin_list) and \
- (fs1 and fs1 + fy2 not in pinyin_list) and \
- (fs2 and fs2 + fy2 not in pinyin_list):
- fy2 = ""
-
- bopomofo = pinyin_bopomofo_map.get(text, "")
-
- if bopomofo == "":
- if all([f.startswith("PINYIN_FUZZY_") for f in flags[0].split(" | ")]):
- #if it is fuzzy pinyin or normal pinyin
- if s in sheng_yun_bopomofo_map and y in sheng_yun_bopomofo_map:
- if isinstance(sheng_yun_bopomofo_map[s], str):
- bopomofo = sheng_yun_bopomofo_map[s]
- else:
- if y in sheng_yun_bopomofo_map[s][1][0]:
- bopomofo += sheng_yun_bopomofo_map[s][1][1]
- else:
- bopomofo += sheng_yun_bopomofo_map[s][0]
-
- if isinstance(sheng_yun_bopomofo_map[y], str):
- bopomofo += sheng_yun_bopomofo_map[y]
- else:
- if s in sheng_yun_bopomofo_map[y][1][0]:
- bopomofo += sheng_yun_bopomofo_map[y][1][1]
- else:
- bopomofo += sheng_yun_bopomofo_map[y][0]
- else:
- print text
-
- yield text, bopomofo, s, y, fs1, fy1, fs2, fy2, l, flags
-
-
-def gen_header():
- print '''/* Please do not modify this file. It is generated by script */
-#include "Types.h"
-
-namespace PY {
-'''
-
-def gen_macros():
- print '#define PINYIN_ID_VOID (-1)'
- print '#define PINYIN_ID_ZERO (0)'
- for y in shengmu_list:
- print '#define PINYIN_ID_%s (%d)' % (y.upper(), encode_pinyin(y))
-
- for y in yunmu_list:
- print '#define PINYIN_ID_%s (%d)' % (y.upper(), encode_pinyin(y))
- print
- print
- print
-
-def gen_option_check(name, fuzzy):
- print '''static gboolean
-%s (guint option, gint id, gint fid)
-{
- switch ((id << 16) | fid) {''' % name
- for y1, y2 in fuzzy:
- flag = "PINYIN_FUZZY_%s_%s" % (y1.upper(), y2.upper())
- args = tuple(["PINYIN_ID_%s" % y.upper() for y in [y1, y2]]) + (flag, )
- print ''' case (%s << 16) | %s:
- return (option & %s);''' % args
-
- print ' default: return FALSE;'
- print ' }'
- print '}'
-
-def union_dups(a):
- n = {}
- for r in a:
- if r[:-1] in n:
- n[r[:-1]] += r[-1]
- else:
- n[r[:-1]] = r[-1]
- na = []
- for k, flags in n.items():
- na.append (tuple(list(k) + [" | ".join(flags) if flags else "0"]))
- na.sort()
- return na
-
-def gen_table():
-
- pinyins = list(get_pinyin_with_fuzzy())
- pinyins = union_dups(pinyins)
-
- print 'static const Pinyin pinyin_table[] = {'
- for i, (text, bopomofo, s, y, fs1, fy1, fs2, fy2, l, flags) in enumerate(pinyins):
- s_id = "PINYIN_ID_%s" % s.upper() if s else "PINYIN_ID_ZERO"
- y_id = "PINYIN_ID_%s" % y.upper() if y else "PINYIN_ID_ZERO"
- fs1_id = "PINYIN_ID_%s" % fs1.upper() if fs1 else "PINYIN_ID_ZERO"
- fy1_id = "PINYIN_ID_%s" % fy1.upper() if fy1 else "PINYIN_ID_ZERO"
- fs2_id = "PINYIN_ID_%s" % fs2.upper() if fs2 else "PINYIN_ID_ZERO"
- fy2_id = "PINYIN_ID_%s" % fy2.upper() if fy2 else "PINYIN_ID_ZERO"
-
- # args = (i, ) + tuple(['"%s"' % s for s in p[:3]]) + tuple(["PINYIN_ID_%s" % s.upper() if s else "PINYIN_ID_ZERO" for s in p[3:9]]) + p[9:-1] + (str(p[-1]), )
- print ''' { /* %d */
- text : "%s",
- bopomofo : L"%s",
- sheng : "%s",
- yun : "%s",
- pinyin_id : {{ %s, %s }, { %s, %s }, { %s, %s }},
- len : %d,
- flags : %s
- },''' % (i, text, bopomofo, s, y.replace("v", "ü"), s_id, y_id, fs1_id, fy1_id, fs2_id, fy2_id, l, flags)
-
- print '};'
- print
-
- return pinyins
-
-def gen_bopomofo_table(pinyins):
- bopomofo_table = [ (i, p) for i, p in enumerate(pinyins)]
- bopomofo_table.sort(lambda a, b: cmp(a[1][1], b[1][1]))
- print 'static const Pinyin *bopomofo_table[] = {'
- for i, p in bopomofo_table:
- if p[1]:
- print ' %-20s %s' % ('&pinyin_table[%d],' % i, '// "%s" => "%s"' % (p[1], p[0]))
- print '};'
- print
-
-def get_all_special(pinyins):
- for p in pinyins:
- if p[-1] in ["n", "g", "r"]:
- for yun in yunmu_list:
- if yun not in pinyin_list:
- continue
- new_pinyin = p[-1] + yun
- # if new_pinyin in pinyin_list:
- yield p, yun, p[:-1], new_pinyin
- elif p[-1] in ["e"]:
- yield p, "r", p[:-1], "er"
-
-def get_max_freq_2(db, p1, p2):
- s1, y1 = get_sheng_yun(p1)
- s2, y2 = get_sheng_yun(p2)
-
- sql = "select max(freq), phrase from py_phrase_1 where s0 = %d and y0 = %d and s1 = %d and y1 = %d"
-
- c = db.execute(sql % (encode_pinyin(s1), encode_pinyin(y1), encode_pinyin(s2), encode_pinyin(y2)))
- for r in c:
- return r[0]
- return 0
-
-def get_max_freq_1(db, p1):
- s1, y1 = get_sheng_yun(p1)
-
- sql = "select max(freq), phrase from py_phrase_0 where s0 = %d and y0 = %d"
-
- c = db.execute(sql % (encode_pinyin(s1), encode_pinyin(y1)))
- for r in c:
- return r[0] if r[0] else 0
- return 0
-
-def compaired_special(pinyins):
- import sqlite3
- db = sqlite3.connect("open-phrase.db")
- # db = sqlite3.connect("main.db")
-
- for p1, p2, p3, p4 in get_all_special(pinyins):
- if p3 not in pinyin_list or p4 not in pinyin_list:
- continue
- if p1 not in pinyin_list or p2 not in pinyin_list:
- yield p1, p2, p3, p4
- continue
-
- if p3 not in pinyin_list or p4 not in pinyin_list:
- continue
-
- a1 = get_max_freq_2(db, p1, p2)
- a2 = get_max_freq_2(db, p3, p4)
- if a1 == a2:
- a1 = get_max_freq_1(db, p1) + get_max_freq_1(db, p2)
- a2 = get_max_freq_1(db, p3) + get_max_freq_1(db, p4)
- if a1 < a2:
- yield p1, p2, p3, p4
-
-def gen_full_pinyin_table(pinyins):
- _dict = {}
- for i in xrange(0, len(pinyins)):
- _dict[pinyins[i]] = i
- full_pinyin = []
- for i in xrange(0, len(pinyins)):
- if pinyins[i][0] in pinyin_list:
- full_pinyin.append (pinyins[i])
- full_pinyin.sort(lambda a, b: (cmp(a[1], b[1]) << 16) + cmp(a[2],b[4]))
- print 'static const Pinyin *full_pinyin_table[] = {'
- for p in full_pinyin:
- print " &pinyin_table[%d], // %s" % (_dict[p], p[0])
- print '};'
- print
-
-
-def gen_special_table(pinyins):
- _dict = {}
- for i in xrange(0, len(pinyins)):
- _dict[pinyins[i][0]] = i
-
- l = list(compaired_special(_dict.keys()))
- l.sort()
- print 'static const Pinyin *special_table[][4] = {'
- for r in l:
- ids = [("&pinyin_table[%d]," % _dict[py]).ljust(20) for py in r]
-
- print ' { %s %s %s %s },' % tuple(ids), "/* %s %s => %s %s */" % r
- print '};'
- print
-
-
-def main():
- # gen_header()
- # gen_macros()
- pinyins = gen_table()
- # gen_full_pinyin_table (pinyins)
- gen_bopomofo_table(pinyins)
- gen_special_table(pinyins)
- # gen_option_check("pinyin_option_check_sheng", fuzzy_shengmu)
- # gen_option_check("pinyin_option_check_yun", fuzzy_yunmu)
-
-
-if __name__ == "__main__":
- main()
-