Skip to content

Commit bf7a4e3

Browse files
committed
feat: 同步 自动纠错 Lua
同步 雾凇拼音 自动纠错 Lua
1 parent 93ecf16 commit bf7a4e3

4 files changed

+150
-94
lines changed

double_pinyin_flypy.schema.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,21 @@ reduce_english_filter:
176176
# 中国农历配置
177177
chineseLunarCalendar_translator: lunar
178178

179+
# Lua 配置:为 corrector 格式化 comment,占位符为 {comment}
180+
# 默认 "{comment}" 输入 hun dun 时会在「馄饨」旁边生成 hún tun 的 comment
181+
# 例如左右加个括号 "({comment})" 就会变成 (hún tun)
182+
corrector: "{comment}"
183+
179184

180185
translator:
181186
# 字典文件
182187
dictionary: rime_mint # 使用的字典文件
183188
prism: double_pinyin_flypy # 多方案共用一个词库时,为避免冲突,需要用 prism 指定一个名字。
184189
spelling_hints: 8 # corrector.lua :为了让错音错字提示的 Lua 同时适配全拼双拼,将拼音显示在 comment 中
185190
always_show_comments: true # corrector.lua :Rime 默认在 preedit 等于 comment 时取消显示 comment,这里强制一直显示,供 corrector.lua 做判断用。
191+
comment_format: # 标记拼音注释,供 corrector.lua 做判断用
192+
- xform/^/[/
193+
- xform/$/]/
186194
preedit_format:
187195
- xform/([bpmfdtnljqx])n/$1iao/
188196
- xform/(\w)g/$1eng/

lua/corrector_filter.lua

+126-94
Original file line numberDiff line numberDiff line change
@@ -6,102 +6,134 @@
66
为了让这个 Lua 同时适配全拼与双拼,使用 `spelling_hints` 生成的 comment(全拼拼音)作为通用的判断条件。
77
感谢大佬@[Shewer Lu](https://github.com/shewer)提供的思路。
88
9-
容错词在 cn_dicts/others.dict.yaml 中,有新增建议可以提个 issue
9+
容错词在 dicts/rime_ice.others.dict.yaml 中,定期同步 雾凇拼音 ,有新增建议可以在 雾凇拼音 地址提个 issue(嘿嘿)
1010
--]]
1111

12-
local corrections = {
13-
-- 错音
14-
["hun dun"] = { text = "馄饨", comment = "hun tun" },
15-
["zhu jiao"] = { text = "主角", comment = "zhu jue" },
16-
["jiao se"] = { text = "角色", comment = "jue se" },
17-
["pi sa"] = { text = "比萨", comment = "bi sa" },
18-
["chi pi sa"] = { text = "吃比萨", comment = "chi bi sa" },
19-
["pi sa bing"] = { text = "比萨饼", comment = "bi sa bing" },
20-
["shui fu"] = { text = "说服", comment = "shuo fu" },
21-
["dao hang"] = { text = "道行", comment = "dao heng" },
22-
["mo yang"] = { text = "模样", comment = "mu yang" },
23-
["you mo you yang"] = { text = "有模有样", comment = "you mu you yang" },
24-
["yi mo yi yang"] = { text = "一模一样", comment = "yi mu yi yang" },
25-
["zhuang mo zuo yang"] = { text = "装模作样", comment = "zhuang mu zuo yang" },
26-
["ren mo gou yang"] = { text = "人模狗样", comment = "ren mu gou yang" },
27-
["mo ban"] = { text = "模板", comment = "mu ban" },
28-
["a mi tuo fo"] = { text = "阿弥陀佛", comment = "e mi tuo fo" },
29-
["na mo a mi tuo fo"] = { text = "南无阿弥陀佛", comment = "na mo e mi tuo fo" },
30-
["nan wu a mi tuo fo"] = { text = "南无阿弥陀佛", comment = "na mo e mi tuo fo" },
31-
["nan wu e mi tuo fo"] = { text = "南无阿弥陀佛", comment = "na mo e mi tuo fo" },
32-
["gei yu"] = { text = "给予", comment = "ji yu" },
33-
["bin lang"] = { text = "槟榔", comment = "bing lang" },
34-
["zhang bai zhi"] = { text = "张柏芝", comment = "zhang bo zhi" },
35-
["teng man"] = { text = "藤蔓", comment = "teng wan" },
36-
["nong tang"] = { text = "弄堂", comment = "long tang" },
37-
["xin kuan ti pang"] = { text = "心宽体胖", comment = "xin kuan ti pan" },
38-
["mai yuan"] = { text = "埋怨", comment = "man yuan" },
39-
["xu yu wei she"] = { text = "虚与委蛇", comment = "xu yu wei yi" },
40-
["mu na"] = { text = "木讷", comment = "mu ne" },
41-
["du le le"] = { text = "独乐乐", comment = "du yue le" },
42-
["zhong le le"] = { text = "众乐乐", comment = "zhong yue le" },
43-
["xun ma"] = { text = "荨麻", comment = "qian ma" },
44-
["qian ma zhen"] = { text = "荨麻疹", comment = "xun ma zhen" },
45-
["mo ju"] = { text = "模具", comment = "mu ju" },
46-
["cao zhi"] = { text = "草薙", comment = "cao ti" },
47-
["cao zhi jing"] = { text = "草薙京", comment = "cao ti jing" },
48-
["cao zhi jian"] = { text = "草薙剑", comment = "cao ti jian" },
49-
["jia ping ao"] = { text = "贾平凹", comment = "jia ping wa" },
50-
["xue fo lan"] = { text = "雪佛兰", comment = "xue fu lan" },
51-
["qiang jin"] = { text = "强劲", comment = "qiang jing" },
52-
["tong ti"] = { text = "胴体", comment = "dong ti" },
53-
["li neng kang ding"] = { text = "力能扛鼎", comment = "li neng gang ding" },
54-
["ya lv jiang"] = { text = "鸭绿江", comment = "ya lu jiang" },
55-
["da fu bian bian"] = { text = "大腹便便", comment = "da fu pian pian" },
56-
["ka bo zi"] = { text = "卡脖子", comment = "qia bo zi" },
57-
["zhi sheng"] = { text = "吱声", comment = "zi sheng" },
58-
["chan he"] = { text = "掺和", comment = "chan huo" },
59-
["chan huo"] = { text = "掺和", comment = "chan huo" },
60-
["can he"] = { text = "掺和", comment = "chan huo" },
61-
["cheng zhi"] = { text = "称职", comment = "chen zhi" },
62-
["luo shi fen"] = { text = "螺蛳粉", comment = "luo si fen" },
63-
["tiao huan"] = { text = "调换", comment = "diao huan" },
64-
["tai xing shan"] = { text = "太行山", comment = "tai hang shan" },
65-
["jie si di li"] = { text = "歇斯底里", comment = "xie si di li" },
66-
["nuan he"] = { text = "暖和", comment = "nuan huo" },
67-
["mo ling liang ke"] = { text = "模棱两可", comment = "mo leng liang ke" },
68-
["pan yang hu"] = { text = "鄱阳湖", comment = "po yang hu" },
69-
["bo jing"] = { text = "脖颈", comment = "bo geng" },
70-
["bo jing er"] = { text = "脖颈儿", comment = "bo geng er" },
71-
["jie zha"] = { text = "结扎", comment = "jie za" },
72-
-- 错字
73-
["pu jie"] = { text = "扑街", comment = "仆街" },
74-
["pu gai"] = { text = "扑街", comment = "仆街" },
75-
["pu jie zai"] = { text = "扑街仔", comment = "仆街仔" },
76-
["pu gai zai"] = { text = "扑街仔", comment = "仆街仔" },
77-
["ceng jin"] = { text = "曾今", comment = "曾经" },
78-
["an nai"] = { text = "按耐", comment = "按捺(na)" },
79-
["an nai bu zhu"] = { text = "按耐不住", comment = "按捺(na)不住" },
80-
["bie jie"] = { text = "别介", comment = "别价(jie)" },
81-
["beng jie"] = { text = "甭介", comment = "甭价(jie)" },
82-
["xue mai pen zhang"] = { text = "血脉喷张", comment = "血脉贲(ben)张 | 血脉偾(fen)张" },
83-
["qi ke fu"] = { text = "契科夫", comment = "契诃(he)夫" },
84-
["zhao cha"] = { text = "找茬", comment = "找碴" },
85-
["zhao cha er"] = { text = "找茬儿", comment = "找碴儿" },
86-
["da jia lai zhao cha"] = { text = "大家来找茬", comment = "大家来找碴" },
87-
["da jia lai zhao cha er"] = { text = "大家来找茬儿", comment = "大家来找碴儿" },
88-
["ci ya"] = { text = "龇牙", comment = "龇(zi)牙" },
89-
["ci zhe ya"] = { text = "龇着牙", comment = "龇(zi)着牙" },
90-
["ci ya lie zui"] = { text = "龇牙咧嘴", comment = "龇(zi)牙咧嘴" },
91-
["cou huo"] = { text = "凑活", comment = "凑合(he)" },
92-
}
12+
local M = {}
9313

94-
local function corrector(input)
95-
for cand in input:iter() do
96-
-- cand.comment 是目前输入的词汇的完整拼音
97-
local c = corrections[cand.comment]
98-
if c and cand.text == c.text then
99-
cand:get_genuine().comment = c.comment
100-
elseif cand.type == "user_phrase" or cand.type == "phrase" or cand.type == "sentence" then
101-
cand:get_genuine().comment = ""
102-
end
103-
yield(cand)
104-
end
14+
function M.init(env)
15+
local config = env.engine.schema.config
16+
local delimiter = config:get_string('speller/delimiter')
17+
if delimiter and #delimiter > 0 and delimiter:sub(1,1) ~= ' ' then
18+
env.delimiter = delimiter:sub(1,1)
19+
end
20+
env.name_space = env.name_space:gsub('^*', '')
21+
M.style = config:get_string(env.name_space) or '{comment}'
22+
M.corrections = {
23+
-- 错音
24+
["hun dun"] = { text = "馄饨", comment = "hún tun" },
25+
["zhu jiao"] = { text = "主角", comment = "zhǔ jué" },
26+
["jiao se"] = { text = "角色", comment = "júe sè" },
27+
["pi sa"] = { text = "比萨", comment = "bǐ sà" },
28+
["chi pi sa"] = { text = "吃比萨", comment = "chī bǐ sà" },
29+
["pi sa bing"] = { text = "比萨饼", comment = "bǐ sà bǐng" },
30+
["shui fu"] = { text = "说服", comment = "shuō fú" },
31+
["dao hang"] = { text = "道行", comment = "dào héng" },
32+
["mo yang"] = { text = "模样", comment = "mú yàng" },
33+
["you mo you yang"] = { text = "有模有样", comment = "yǒu mú yǒu yàng" },
34+
["yi mo yi yang"] = { text = "一模一样", comment = "yī mú yī yàng" },
35+
["zhuang mo zuo yang"] = { text = "装模作样", comment = "zhuāng mú zuò yàng" },
36+
["ren mo gou yang"] = { text = "人模狗样", comment = "rén mú góu yàng" },
37+
["mo ban"] = { text = "模板", comment = "mú bǎn" },
38+
["a mi tuo fo"] = { text = "阿弥陀佛", comment = "ē mí tuó fó" },
39+
["na mo a mi tuo fo"] = { text = "南无阿弥陀佛", comment = "nā mó ē mí tuó fó" },
40+
["nan wu a mi tuo fo"] = { text = "南无阿弥陀佛", comment = "nā mó ē mí tuó fó" },
41+
["nan wu e mi tuo fo"] = { text = "南无阿弥陀佛", comment = "nā mó ē mí tuó fó" },
42+
["gei yu"] = { text = "给予", comment = "jǐ yǔ" },
43+
["bin lang"] = { text = "槟榔", comment = "bīng láng" },
44+
["zhang bai zhi"] = { text = "张柏芝", comment = "zhāng bó zhī" },
45+
["teng man"] = { text = "藤蔓", comment = "téng wàn" },
46+
["nong tang"] = { text = "弄堂", comment = "lòng táng" },
47+
["xin kuan ti pang"] = { text = "心宽体胖", comment = "xīn kūan tǐ pán" },
48+
["mai yuan"] = { text = "埋怨", comment = "mán yuàn" },
49+
["xu yu wei she"] = { text = "虚与委蛇", comment = "xū yǔ wēi yí" },
50+
["mu na"] = { text = "木讷", comment = "mù nè" },
51+
["du le le"] = { text = "独乐乐", comment = "dú yuè lè" },
52+
["zhong le le"] = { text = "众乐乐", comment = "zhòng yuè lè" },
53+
["xun ma"] = { text = "荨麻", comment = "qián má" },
54+
["qian ma zhen"] = { text = "荨麻疹", comment = "xún má zhěn" },
55+
["mo ju"] = { text = "模具", comment = "mú jù" },
56+
["cao zhi"] = { text = "草薙", comment = "cǎo tì" },
57+
["cao zhi jing"] = { text = "草薙京", comment = "cǎo tì jīng" },
58+
["cao zhi jian"] = { text = "草薙剑", comment = "cǎo tì jiàn" },
59+
["jia ping ao"] = { text = "贾平凹", comment = "jià píng wā" },
60+
["xue fo lan"] = { text = "雪佛兰", comment = "xuě fú lán" },
61+
["qiang jin"] = { text = "强劲", comment = "qiáng jìng" },
62+
["tong ti"] = { text = "胴体", comment = "dòng tǐ" },
63+
["li neng kang ding"] = { text = "力能扛鼎", comment = "lì néng gāng dǐng" },
64+
["ya lv jiang"] = { text = "鸭绿江", comment = "yā lù jiāng" },
65+
["da fu bian bian"] = { text = "大腹便便", comment = "dà fù pián pián" },
66+
["ka bo zi"] = { text = "卡脖子", comment = "qiǎ bó zi" },
67+
["zhi sheng"] = { text = "吱声", comment = "zī shēng" },
68+
["chan he"] = { text = "掺和", comment = "chān huo" },
69+
["can huo"] = { text = "掺和", comment = "chān huo" },
70+
["can he"] = { text = "掺和", comment = "chān huo" },
71+
["cheng zhi"] = { text = "称职", comment = "chèn zhí" },
72+
["luo shi fen"] = { text = "螺蛳粉", comment = "luó sī fěn" },
73+
["tiao huan"] = { text = "调换", comment = "diào huàn" },
74+
["tai xing shan"] = { text = "太行山", comment = "tài háng shān" },
75+
["jie si di li"] = { text = "歇斯底里", comment = "xiē sī dǐ lǐ" },
76+
["nuan he"] = { text = "暖和", comment = "nuǎn huo" },
77+
["mo ling liang ke"] = { text = "模棱两可", comment = "mó léng liǎng kě" },
78+
["pan yang hu"] = { text = "鄱阳湖", comment = "pó yáng hú" },
79+
["bo jing"] = { text = "脖颈", comment = "bó gěng" },
80+
["bo jing er"] = { text = "脖颈儿", comment = "bó gěng er" },
81+
["jie zha"] = { text = "结扎", comment = "jié zā" },
82+
["hai shen wei"] = { text = "海参崴", comment = "hǎi shēn wǎi" },
83+
["hou pu"] = { text = "厚朴", comment = "hòu pò " },
84+
["da wan ma"] = { text = "大宛马", comment = "dà yuān mǎ" },
85+
["ci ya"] = { text = "龇牙", comment = "zī yá" },
86+
["ci zhe ya"] = { text = "龇着牙", comment = "zī zhe yá" },
87+
["ci ya lie zui"] = { text = "龇牙咧嘴", comment = "zī yá liě zuǐ" },
88+
["tou pi xue"] = { text = "头皮屑", comment = "tóu pi xiè" },
89+
["liu an shi"] = { text = "六安市", comment = "lù ān shì" },
90+
["liu an xian"] = { text = "六安县", comment = "lù ān xiàn" },
91+
["an hui sheng liu an shi"] = { text = "安徽省六安市", comment = "ān huī shěng lù ān shì" },
92+
["an hui liu an"] = { text = "安徽六安", comment = "ān huī lù ān" },
93+
["an hui liu an shi"] = { text = "安徽六安市", comment = "ān huī lù ān shì" },
94+
["nan jing liu he"] = { text = "南京六合", comment = "nán jīng lù hé" },
95+
["nan jing shi liu he"] = { text = "南京六合区", comment = "nán jīng lù hé qū" },
96+
["nan jing shi liu he qu"] = { text = "南京市六合区", comment = "nán jīng shì lù hé qū" },
97+
-- 错字
98+
["pu jie"] = { text = "扑街", comment = "仆街" },
99+
["pu gai"] = { text = "扑街", comment = "仆街" },
100+
["pu jie zai"] = { text = "扑街仔", comment = "仆街仔" },
101+
["pu gai zai"] = { text = "扑街仔", comment = "仆街仔" },
102+
["ceng jin"] = { text = "曾今", comment = "曾经" },
103+
["an nai"] = { text = "按耐", comment = "按捺(nà)" },
104+
["an nai bu zhu"] = { text = "按耐不住", comment = "按捺(nà)不住" },
105+
["bie jie"] = { text = "别介", comment = "别价(jie)" },
106+
["beng jie"] = { text = "甭介", comment = "甭价(jie)" },
107+
["xue mai pen zhang"] = { text = "血脉喷张", comment = "血脉贲(bēn)张 | 血脉偾(fèn)张" },
108+
["qi ke fu"] = { text = "契科夫", comment = "契诃(hē)夫" },
109+
["zhao cha"] = { text = "找茬", comment = "找碴" },
110+
["zhao cha er"] = { text = "找茬儿", comment = "找碴儿" },
111+
["da jia lai zhao cha"] = { text = "大家来找茬", comment = "大家来找碴" },
112+
["da jia lai zhao cha er"] = { text = "大家来找茬儿", comment = "大家来找碴儿" },
113+
["cou huo"] = { text = "凑活", comment = "凑合(he)" },
114+
["ju hui"] = { text = "钜惠", comment = "巨惠" },
115+
["mo xie zuo"] = { text = "魔蝎座", comment = "摩羯(jié)座" },
116+
["nuo da"] = { text = "诺大", comment = "偌(ruò)大" },
117+
}
105118
end
106119

107-
return corrector
120+
function M.func(input, env)
121+
for cand in input:iter() do
122+
-- cand.comment 是目前输入的词汇的完整拼音
123+
local pinyin = cand.comment:match("^[(.-)]$")
124+
if pinyin and #pinyin > 0 then
125+
if env.delimiter then
126+
pinyin = pinyin:gsub(env.delimiter,' ')
127+
end
128+
local c = M.corrections[pinyin]
129+
if c and cand.text == c.text then
130+
cand:get_genuine().comment = string.gsub(M.style, "{comment}", c.comment)
131+
else
132+
cand:get_genuine().comment = ""
133+
end
134+
end
135+
yield(cand)
136+
end
137+
end
138+
139+
return M

rime_mint.schema.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,20 @@ reduce_english_filter:
142142
# 中国农历配置
143143
chineseLunarCalendar_translator: lunar
144144

145+
# Lua 配置:为 corrector 格式化 comment,占位符为 {comment}
146+
# 默认 "{comment}" 输入 hun dun 时会在「馄饨」旁边生成 hún tun 的 comment
147+
# 例如左右加个括号 "({comment})" 就会变成 (hún tun)
148+
corrector: "{comment}"
149+
145150
translator:
146151
# enable_correction: true # Rime自带的按键纠错,适用于手机26键 参考: https://github.com/rime/librime/pull/228
147152
# 字典文件
148153
dictionary: rime_mint # 使用的字典文件
149154
spelling_hints: 8 # corrector.lua :为了让错音错字提示的 Lua 同时适配全拼双拼,将拼音显示在 comment 中
150155
always_show_comments: true # corrector.lua :Rime 默认在 preedit 等于 comment 时取消显示 comment,这里强制一直显示,供 corrector.lua 做判断用。
156+
comment_format: # 标记拼音注释,供 corrector.lua 做判断用
157+
- xform/^/[/
158+
- xform/$/]/
151159
preedit_format:
152160
- xform/([nl])v/$1ü/
153161
- xform/([nl])ue/$1üe/

rime_mint_flypy.schema.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,21 @@ reduce_english_filter:
142142
# 中国农历配置
143143
chineseLunarCalendar_translator: lunar
144144

145+
# Lua 配置:为 corrector 格式化 comment,占位符为 {comment}
146+
# 默认 "{comment}" 输入 hun dun 时会在「馄饨」旁边生成 hún tun 的 comment
147+
# 例如左右加个括号 "({comment})" 就会变成 (hún tun)
148+
corrector: "{comment}"
149+
145150
translator:
146151
# enable_correction: true # Rime自带的按键纠错,适用于手机26键 参考: https://github.com/rime/librime/pull/228
147152
# 字典文件
148153
dictionary: rime_mint # 使用的字典文件
149154
prism: rime_mint_flypy # 多方案共用一个词库时,为避免冲突,需要用 prism 指定一个名字。
150155
spelling_hints: 8 # corrector.lua :为了让错音错字提示的 Lua 同时适配全拼双拼,将拼音显示在 comment 中
151156
always_show_comments: true # corrector.lua :Rime 默认在 preedit 等于 comment 时取消显示 comment,这里强制一直显示,供 corrector.lua 做判断用。
157+
comment_format: # 标记拼音注释,供 corrector.lua 做判断用
158+
- xform/^/[/
159+
- xform/$/]/
152160
preedit_format:
153161
- xform/([nl])v/$1ü/
154162
- xform/([nl])ue/$1üe/

0 commit comments

Comments
 (0)