|
| 1 | +--[[ |
| 2 | + 错音错字提示。 |
| 3 | + 示例:「给予」的正确读音是 ji yu,当用户输入 gei yu 时,在候选项的 comment 显示正确读音 |
| 4 | + 示例:「按耐」的正确写法是「按捺」,当用户输入「按耐」时,在候选项的 comment 显示正确写法 |
| 5 | +
|
| 6 | + 为了让这个 Lua 同时适配全拼与双拼,使用 `spelling_hints` 生成的 comment(全拼拼音)作为通用的判断条件。 |
| 7 | +--]] |
| 8 | + |
| 9 | +-- 容错词在 cn_dicts/others.dict.yaml |
| 10 | +local corrections = { |
| 11 | + -- 错音 |
| 12 | + ["hun dun"] = { text = "馄饨", comment = "hun tun" }, |
| 13 | + ["zhu jiao"] = { text = "主角", comment = "zhu jue" }, |
| 14 | + ["jiao se"] = { text = "角色", comment = "jue se" }, |
| 15 | + ["pi sa"] = { text = "比萨", comment = "bi sa" }, |
| 16 | + ["chi pi sa"] = { text = "吃比萨", comment = "chi bi sa" }, |
| 17 | + ["pi sa bing"] = { text = "比萨饼", comment = "bi sa bing" }, |
| 18 | + ["pu gai"] = { text = "扑街", comment = "pu jie" }, |
| 19 | + ["pu gai zai"] = { text = "扑街仔", comment = "pu jie zai" }, |
| 20 | + ["gai liu zi"] = { text = "街溜子", comment = "jie liu zi" }, |
| 21 | + ["shui fu"] = { text = "说服", comment = "shuo fu" }, |
| 22 | + ["zuo ji"] = { text = "坐骑", comment = "zuo qi" }, |
| 23 | + ["yi ji jue chen"] = { text = "一骑绝尘", comment = "yi qi jue chen" }, |
| 24 | + ["yi ji hong chen fei zi xiao"] = { text = "一骑红尘妃子笑", comment = "yi qi hong chen fei zi xiao" }, |
| 25 | + ["qian li zou dan ji"] = { text = "千里走单骑", comment = "qian li zou dan qi" }, |
| 26 | + ["yi ji dang qian"] = { text = "一骑当千", comment = "yi qi dang qian" }, |
| 27 | + ["dao hang"] = { text = "道行", comment = "dao heng" }, |
| 28 | + ["mo yang"] = { text = "模样", comment = "mu yang" }, |
| 29 | + ["you mo you yang"] = { text = "有模有样", comment = "you mu you yang" }, |
| 30 | + ["yi mo yi yang"] = { text = "一模一样", comment = "yi mu yi yang" }, |
| 31 | + ["zhuang mo zuo yang"] = { text = "装模作样", comment = "zhuang mu zuo yang" }, |
| 32 | + ["ren mo gou yang"] = { text = "人模狗样", comment = "ren mu gou yang" }, |
| 33 | + ["a mi tuo fo"] = { text = "阿弥陀佛", comment = "e mi tuo fo" }, |
| 34 | + ["na mo a mi tuo fo"] = { text = "南无阿弥陀佛", comment = "na mo e mi tuo fo" }, |
| 35 | + ["nan wu a mi tuo fo"] = { text = "南无阿弥陀佛", comment = "na mo e mi tuo fo" }, |
| 36 | + ["nan wu e mi tuo fo"] = { text = "南无阿弥陀佛", comment = "na mo e mi tuo fo" }, |
| 37 | + ["gei yu"] = { text = "给予", comment = "ji yu" }, |
| 38 | + ["bin lang"] = { text = "槟榔", comment = "bing lang" }, |
| 39 | + ["zhang bai zhi"] = { text = "张柏芝", comment = "zhang bo zhi" }, |
| 40 | + ["teng man"] = { text = "藤蔓", comment = "teng wan" }, |
| 41 | + ["nong tang"] = { text = "弄堂", comment = "long tang" }, |
| 42 | + ["xin kuan ti pang"] = { text = "心宽体胖", comment = "xin kuan ti pan" }, |
| 43 | + ["mai yuan"] = { text = "埋怨", comment = "man yuan" }, |
| 44 | + ["xu yu wei she"] = { text = "虚与委蛇", comment = "xu yu wei yi" }, |
| 45 | + ["mu na"] = { text = "木讷", comment = "mu ne" }, |
| 46 | + -- 错字 |
| 47 | + ["ceng jin"] = { text = "曾今", comment = "曾经" }, |
| 48 | + ["an nai"] = { text = "按耐", comment = "按捺(na)" }, |
| 49 | + ["an nai bu zhu"] = { text = "按耐不住", comment = "按捺(na)不住" }, |
| 50 | + ["sheng di ya ge"] = { text = "圣地亚哥", comment = "圣迭戈" }, |
| 51 | + ["bie jie"] = { text = "别介", comment = "别价" }, |
| 52 | + ["beng jie"] = { text = "甭介", comment = "甭价" }, |
| 53 | +} |
| 54 | + |
| 55 | +local function corrector(input) |
| 56 | + for cand in input:iter() do |
| 57 | + -- cand.comment 是目前输入的词汇的完整拼音 |
| 58 | + local c = corrections[cand.comment] |
| 59 | + if c and cand.text == c.text then |
| 60 | + cand:get_genuine().comment = c.comment |
| 61 | + else |
| 62 | + cand:get_genuine().comment = "" |
| 63 | + end |
| 64 | + yield(cand) |
| 65 | + end |
| 66 | +end |
| 67 | + |
| 68 | +return corrector |
0 commit comments