Skip to content

Commit 3ce582e

Browse files
committed
feat: corrector.lua 错音错字提示
1 parent 1c1c005 commit 3ce582e

9 files changed

+139
-27
lines changed

cn_dicts/others.dict.yaml

+32-23
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
#
99
---
1010
name: others
11-
version: "2023-06-13"
11+
version: "2023-08-06"
1212
sort: by_weight
1313
...
1414
##### 容错词
15-
# 「血xue、xie」「谁shui、shei」「露lu、lou」「熟shu、shou」「密钥yao、yue」已在 base 中实现
16-
# ---
15+
# 与 corrector.lua 配合,上面的是正确的,下面是错误的
1716
# 「馄饨」,正确是 tun,北方口语是 dun
1817
馄饨 hun tun
1918
馄饨 hun dun
@@ -29,31 +28,13 @@ sort: by_weight
2928
比萨饼 pi sa bing
3029
吃比萨 chi bi sa
3130
吃比萨 chi pi sa
32-
超级至尊比萨 chao ji zhi zun bi sa
33-
超级至尊比萨 chao ji zhi zun pi sa
34-
至尊比萨 zhi zun bi sa
35-
至尊比萨 zhi zun pi sa
36-
大西洋珍鲑比萨 da xi yang zhen gui bi sa
37-
大西洋珍鲑比萨 da xi yang zhen gui pi sa
38-
海鲜比萨 hai xian bi sa
39-
海鲜比萨 hai xian pi sa
40-
蔬菜比萨 shu cai bi sa
41-
蔬菜比萨 shu cai pi sa
42-
做比萨 zuo bi sa
43-
做比萨 zuo pi sa
44-
可口的比萨 ke kou de bi sa
45-
可口的比萨 ke kou de pi sa
46-
烤比萨 kao bi sa
47-
烤比萨 kao pi sa
48-
美味的比萨 mei wei de bi sa
49-
美味的比萨 mei wei de pi sa
5031
# 「扑街」,正确是 jie,口语是 gai
5132
扑街 pu jie
5233
扑街 pu gai
53-
街溜子 jie liu zi
54-
街溜子 gai liu zi
5534
扑街仔 pu jie zai
5635
扑街仔 pu gai zai
36+
街溜子 jie liu zi
37+
街溜子 gai liu zi
5738
# 「说服」,正确是 shuo,但「游说」「说客」仍然保留着 shui 的读音
5839
说服 shuo fu
5940
说服 shui fu
@@ -80,6 +61,8 @@ sort: by_weight
8061
一模一样 yi mo yi yang
8162
装模作样 zhuang mu zuo yang
8263
装模作样 zhuang mo zuo yang
64+
人模狗样 ren mu gou yang
65+
人模狗样 ren mo gou yang
8366
# 「阿房宫」的注音争议比较大
8467
阿房宫 e pang gong
8568
阿房宫 a pang gong
@@ -99,6 +82,32 @@ sort: by_weight
9982
南无阿弥陀佛 na mo a mi tuo fo
10083
南无阿弥陀佛 nan wu e mi tuo fo
10184
南无阿弥陀佛 nan wu a mi tuo fo
85+
# 其他
86+
给予 ji yu
87+
给予 gei yu
88+
槟榔 bing lang
89+
槟榔 bin lang
90+
张柏芝 zhang bo zhi
91+
张柏芝 zhang bai zhi
92+
藤蔓 teng wan
93+
藤蔓 teng man
94+
弄堂 long tang
95+
弄堂 nong tang
96+
心宽体胖 xin kuan ti pan
97+
心宽体胖 xin kuan ti pang
98+
埋怨 man yuan
99+
埋怨 mai yuan
100+
虚与委蛇 xu yu wei yi
101+
虚与委蛇 xu yu wei she
102+
木讷 mu ne
103+
木讷 mu na
104+
# 错字
105+
曾经 ceng jing
106+
曾今 ceng jin
107+
按捺 an na
108+
按耐 an nai
109+
按捺不住 an na bu zhu
110+
按耐不住 an nai bu zhu
102111

103112

104113
##### 叠字

double_pinyin.schema.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ engine:
7777
- lua_translator@unicode # Unicode
7878
- lua_translator@number_translator # 数字、金额大写
7979
filters:
80+
- lua_filter@corrector # 错音错字提示
8081
- simplifier@emoji # Emoji
8182
- simplifier@traditionalize # 简繁切换
8283
- lua_filter@autocap_filter # 英文自动大写
@@ -114,6 +115,8 @@ reduce_english_filter:
114115
translator:
115116
dictionary: rime_ice # 挂载词库 rime_ice.dict.yaml
116117
prism: double_pinyin # 多方案共用一个词库时,为避免冲突,需要用 prism 指定一个名字。
118+
spelling_hints: 8 # corrector.lua :为了让错音错字提示的 Lua 同时适配全拼双拼,将拼音显示在 comment 中
119+
always_show_comments: true # corrector.lua :Rime 默认在 preedit 等于 comment 时取消显示 comment,这里强制一直显示,供 corrector.lua 做判断用。
117120
initial_quality: 1.2 # 拼音的权重应该比英文大
118121
preedit_format: # preedit_format 影响到输入框的显示和“Shift+回车”上屏的字符
119122
- xform/([bpmnljqxy])n/$1in/

double_pinyin_abc.schema.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ engine:
7676
- lua_translator@unicode # Unicode
7777
- lua_translator@number_translator # 数字、金额大写
7878
filters:
79+
- lua_filter@corrector # 错音错字提示
7980
- simplifier@emoji # Emoji
8081
- simplifier@traditionalize # 简繁切换
8182
- lua_filter@autocap_filter # 英文自动大写
@@ -113,6 +114,8 @@ reduce_english_filter:
113114
translator:
114115
dictionary: rime_ice # 挂载词库 rime_ice.dict.yaml
115116
prism: double_pinyin_abc # 多方案共用一个词库时,为避免冲突,需要用 prism 指定一个名字。
117+
spelling_hints: 8 # corrector.lua :为了让错音错字提示的 Lua 同时适配全拼双拼,将拼音显示在 comment 中
118+
always_show_comments: true # corrector.lua :Rime 默认在 preedit 等于 comment 时取消显示 comment,这里强制一直显示,供 corrector.lua 做判断用。
116119
initial_quality: 1.2 # 拼音的权重应该比英文大
117120
preedit_format: # preedit_format 影响到输入框的显示和“Shift+回车”上屏的字符
118121
- xform/o(\w)/0$1/

double_pinyin_flypy.schema.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ engine:
7777
- lua_translator@unicode # Unicode
7878
- lua_translator@number_translator # 数字、金额大写
7979
filters:
80+
- lua_filter@corrector # 错音错字提示
8081
- simplifier@emoji # Emoji
8182
- simplifier@traditionalize # 简繁切换
8283
- lua_filter@autocap_filter # 英文自动大写
@@ -114,6 +115,8 @@ reduce_english_filter:
114115
translator:
115116
dictionary: rime_ice # 挂载词库 rime_ice.dict.yaml
116117
prism: double_pinyin_flypy # 多方案共用一个词库时,为避免冲突,需要用 prism 指定一个名字。
118+
spelling_hints: 8 # corrector.lua :为了让错音错字提示的 Lua 同时适配全拼双拼,将拼音显示在 comment 中
119+
always_show_comments: true # corrector.lua :Rime 默认在 preedit 等于 comment 时取消显示 comment,这里强制一直显示,供 corrector.lua 做判断用。
117120
initial_quality: 1.2 # 拼音的权重应该比英文大
118121
preedit_format: # preedit_format 影响到输入框的显示和“Shift+回车”上屏的字符
119122
- xform/([bpmfdtnljqx])n/$1iao/

double_pinyin_mspy.schema.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ engine:
7777
- lua_translator@unicode # Unicode
7878
- lua_translator@number_translator # 数字、金额大写
7979
filters:
80+
- lua_filter@corrector # 错音错字提示
8081
- simplifier@emoji # Emoji
8182
- simplifier@traditionalize # 简繁切换
8283
- lua_filter@autocap_filter # 英文自动大写
@@ -114,6 +115,8 @@ reduce_english_filter:
114115
translator:
115116
dictionary: rime_ice # 挂载词库 rime_ice.dict.yaml
116117
prism: double_pinyin_mspy # 多方案共用一个词库时,为避免冲突,需要用 prism 指定一个名字。
118+
spelling_hints: 8 # corrector.lua :为了让错音错字提示的 Lua 同时适配全拼双拼,将拼音显示在 comment 中
119+
always_show_comments: true # corrector.lua :Rime 默认在 preedit 等于 comment 时取消显示 comment,这里强制一直显示,供 corrector.lua 做判断用。
117120
initial_quality: 1.2 # 拼音的权重应该比英文大
118121
preedit_format: # preedit_format 影响到输入框的显示和“Shift+回车”上屏的字符
119122
- xform/([aoe])(\w)/0$2/

double_pinyin_ziguang.schema.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ engine:
7777
- lua_translator@unicode # Unicode
7878
- lua_translator@number_translator # 数字、金额大写
7979
filters:
80+
- lua_filter@corrector # 错音错字提示
8081
- simplifier@emoji # Emoji
8182
- simplifier@traditionalize # 简繁切换
8283
- lua_filter@autocap_filter # 英文自动大写
@@ -114,6 +115,8 @@ reduce_english_filter:
114115
translator:
115116
dictionary: rime_ice # 挂载词库 rime_ice.dict.yaml
116117
prism: double_pinyin_ziguang # 多方案共用一个词库时,为避免冲突,需要用 prism 指定一个名字。
118+
spelling_hints: 8 # corrector.lua :为了让错音错字提示的 Lua 同时适配全拼双拼,将拼音显示在 comment 中
119+
always_show_comments: true # corrector.lua :Rime 默认在 preedit 等于 comment 时取消显示 comment,这里强制一直显示,供 corrector.lua 做判断用。
117120
initial_quality: 1.2 # 拼音的权重应该比英文大
118121
preedit_format: # preedit_format 影响到输入框的显示和“Shift+回车”上屏的字符
119122
- xform/o(\w)/0$1/ # 零聲母先改爲0,以方便後面的轉換

lua/corrector.lua

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

rime.lua

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
-- Rime Lua 扩展 https://github.com/hchunhui/librime-lua
22
-- 文档 https://github.com/hchunhui/librime-lua/wiki/Scripting
33

4-
-- v 模式 symbols 优先(全拼)
5-
v_filter = require("v_filter")
4+
5+
6+
-- processors:
67

78
-- 以词定字,可在 default.yaml key_binder 下配置快捷键,默认为左右中括号 [ ]
89
select_character = require("select_character")
910

11+
12+
13+
-- translators:
14+
1015
-- 日期时间,可在方案中配置触发关键字。
1116
date_translator = require("date_translator")
1217

@@ -16,18 +21,30 @@ unicode = require("unicode")
1621
-- 数字、人民币大写,R 开头
1722
number_translator = require("number_translator")
1823

24+
25+
26+
-- filters:
27+
28+
-- 错音错字提示
29+
corrector = require("corrector")
30+
31+
-- v 模式 symbols 优先(全拼)
32+
v_filter = require("v_filter")
33+
1934
-- 自动大写英文词汇
2035
autocap_filter = require("autocap_filter")
2136

2237
-- 降低部分英语单词在候选项的位置,可在方案中配置要降低的单词
2338
reduce_english_filter = require("reduce_english_filter")
2439

2540

41+
42+
2643
-- 默认未启用:
2744

2845
-- 长词优先(全拼)
2946
-- 在 engine/filters 增加 - lua_filter@long_word_filter
30-
-- 在方案里写配置项:
47+
-- 在方案里写配置项:
3148
-- 提升 count 个词语,插入到第 idx 个位置。
3249
-- 示例:将 2 个词插入到第 4、5 个候选项,输入 jie 得到「1接 2解 3姐 4饥饿 5极恶」
3350
-- long_word_filter:
@@ -43,7 +60,7 @@ cn_en_spacer = require("cn_en_spacer")
4360
-- 在 engine/filters 增加 - lua_filter@t9_preedit
4461
t9_preedit = require("t9_preedit")
4562

46-
-- 根据是否在用户词典,在结尾加上一个星号 *
63+
-- 根据是否在用户词典,在 comment 上加上一个星号 *
4764
-- 在 engine/filters 增加 - lua_filter@is_in_user_dict
4865
-- 在方案里写配置项:
4966
-- is_in_user_dict: true 为输入过的内容加星号

rime_ice.schema.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ engine:
6767
- lua_translator@unicode # Unicode
6868
- lua_translator@number_translator # 数字、金额大写
6969
filters:
70+
- lua_filter@corrector # 错音错字提示
7071
- simplifier@emoji # Emoji
7172
- simplifier@traditionalize # 简繁切换
7273
- lua_filter@v_filter # v 模式 symbols 优先(否则是英文优先)
@@ -103,6 +104,8 @@ reduce_english_filter:
103104
# 主翻译器,拼音
104105
translator:
105106
dictionary: rime_ice # 挂载词库 rime_ice.dict.yaml
107+
spelling_hints: 8 # corrector.lua :为了让错音错字提示的 Lua 同时适配全拼双拼,将拼音显示在 comment 中
108+
always_show_comments: true # corrector.lua :Rime 默认在 preedit 等于 comment 时取消显示 comment,这里强制一直显示,供 corrector.lua 做判断用。
106109
initial_quality: 1.2 # 拼音的权重应该比英文大
107110
preedit_format: # preedit_format 影响到输入框的显示和“Shift+回车”上屏的字符
108111
- xform/([jqxy])v/$1u/ # 显示为 ju qu xu yu

0 commit comments

Comments
 (0)