feat: corrector.lua 支持 comment 格式化配置 close #598

This commit is contained in:
Dvel 2024-01-03 23:27:55 +08:00
parent c1a8a814e3
commit bccc7809ea
8 changed files with 153 additions and 104 deletions

View File

@ -99,6 +99,12 @@ date_translator:
lunar: lunar # 癸卯年(兔)冬月廿一 二〇二四年冬月廿一
# Lua 配置:为 corrector 格式化 comment占位符为 {comment}
# 默认 "{comment}" 输入 hun dun 时会在「馄饨」旁边生成 hún tun 的 comment
# 例如左右加个括号 "({comment})" 就会变成 (hún tun)
corrector: "{comment}"
# Lua 配置: 降低部分英语单词在候选项的位置。
# 详细介绍 https://dvel.me/posts/make-rime-en-better/#短单词置顶的问题
# 正常情况: 输入 rug 得到 「1.rug 2.如果 …… 」

View File

@ -98,6 +98,12 @@ date_translator:
lunar: lunar # 癸卯年(兔)冬月廿一 二〇二四年冬月廿一
# Lua 配置:为 corrector 格式化 comment占位符为 {comment}
# 默认 "{comment}" 输入 hun dun 时会在「馄饨」旁边生成 hún tun 的 comment
# 例如左右加个括号 "({comment})" 就会变成 (hún tun)
corrector: "{comment}"
# Lua 配置: 降低部分英语单词在候选项的位置。
# 详细介绍 https://dvel.me/posts/make-rime-en-better/#短单词置顶的问题
# 正常情况: 输入 rug 得到 「1.rug 2.如果 …… 」

View File

@ -99,6 +99,12 @@ date_translator:
lunar: lunar # 癸卯年(兔)冬月廿一 二〇二四年冬月廿一
# Lua 配置:为 corrector 格式化 comment占位符为 {comment}
# 默认 "{comment}" 输入 hun dun 时会在「馄饨」旁边生成 hún tun 的 comment
# 例如左右加个括号 "({comment})" 就会变成 (hún tun)
corrector: "{comment}"
# Lua 配置: 降低部分英语单词在候选项的位置。
# 详细介绍 https://dvel.me/posts/make-rime-en-better/#短单词置顶的问题
# 正常情况: 输入 rug 得到 「1.rug 2.如果 …… 」

View File

@ -99,6 +99,12 @@ date_translator:
lunar: lunar # 癸卯年(兔)冬月廿一 二〇二四年冬月廿一
# Lua 配置:为 corrector 格式化 comment占位符为 {comment}
# 默认 "{comment}" 输入 hun dun 时会在「馄饨」旁边生成 hún tun 的 comment
# 例如左右加个括号 "({comment})" 就会变成 (hún tun)
corrector: "{comment}"
# Lua 配置: 降低部分英语单词在候选项的位置。
# 详细介绍 https://dvel.me/posts/make-rime-en-better/#短单词置顶的问题
# 正常情况: 输入 rug 得到 「1.rug 2.如果 …… 」

View File

@ -99,6 +99,12 @@ date_translator:
lunar: lunar # 癸卯年(兔)冬月廿一 二〇二四年冬月廿一
# Lua 配置:为 corrector 格式化 comment占位符为 {comment}
# 默认 "{comment}" 输入 hun dun 时会在「馄饨」旁边生成 hún tun 的 comment
# 例如左右加个括号 "({comment})" 就会变成 (hún tun)
corrector: "{comment}"
# Lua 配置: 降低部分英语单词在候选项的位置。
# 详细介绍 https://dvel.me/posts/make-rime-en-better/#短单词置顶的问题
# 正常情况: 输入 rug 得到 「1.rug 2.如果 …… 」

View File

@ -99,6 +99,12 @@ date_translator:
lunar: lunar # 癸卯年(兔)冬月廿一 二〇二四年冬月廿一
# Lua 配置:为 corrector 格式化 comment占位符为 {comment}
# 默认 "{comment}" 输入 hun dun 时会在「馄饨」旁边生成 hún tun 的 comment
# 例如左右加个括号 "({comment})" 就会变成 (hún tun)
corrector: "{comment}"
# Lua 配置: 降低部分英语单词在候选项的位置。
# 详细介绍 https://dvel.me/posts/make-rime-en-better/#短单词置顶的问题
# 正常情况: 输入 rug 得到 「1.rug 2.如果 …… 」

View File

@ -9,97 +9,104 @@
cn_dicts/others.dict.yaml issue
--]]
local corrections = {
-- 错音
["hun dun"] = { text = "馄饨", comment = "hún tun" },
["zhu jiao"] = { text = "主角", comment = "zhǔ jué" },
["jiao se"] = { text = "角色", comment = "júe sè" },
["pi sa"] = { text = "比萨", comment = "bǐ sà" },
["chi pi sa"] = { text = "吃比萨", comment = "chī bǐ sà" },
["pi sa bing"] = { text = "比萨饼", comment = "bǐ sà bǐng" },
["shui fu"] = { text = "说服", comment = "shuō fú" },
["dao hang"] = { text = "道行", comment = "dào héng" },
["mo yang"] = { text = "模样", comment = "mú yàng" },
["you mo you yang"] = { text = "有模有样", comment = "yǒu mú yǒu yàng" },
["yi mo yi yang"] = { text = "一模一样", comment = "yī mú yī yàng" },
["zhuang mo zuo yang"] = { text = "装模作样", comment = "zhuāng mú zuò yàng" },
["ren mo gou yang"] = { text = "人模狗样", comment = "rén mú góu yàng" },
["mo ban"] = { text = "模板", comment = "mú bǎn" },
["a mi tuo fo"] = { text = "阿弥陀佛", comment = "ē mí tuó fó" },
["na mo a mi tuo fo"] = { text = "南无阿弥陀佛", comment = "nā mó ē mí tuó fó" },
["nan wu a mi tuo fo"] = { text = "南无阿弥陀佛", comment = "nā mó ē mí tuó fó" },
["nan wu e mi tuo fo"] = { text = "南无阿弥陀佛", comment = "nā mó ē mí tuó fó" },
["gei yu"] = { text = "给予", comment = "jǐ yǔ" },
["bin lang"] = { text = "槟榔", comment = "bīng láng" },
["zhang bai zhi"] = { text = "张柏芝", comment = "zhāng bó zhī" },
["teng man"] = { text = "藤蔓", comment = "téng wàn" },
["nong tang"] = { text = "弄堂", comment = "lòng táng" },
["xin kuan ti pang"] = { text = "心宽体胖", comment = "xīn kūan tǐ pán" },
["mai yuan"] = { text = "埋怨", comment = "mán yuàn" },
["xu yu wei she"] = { text = "虚与委蛇", comment = "xū yǔ wēi yí" },
["mu na"] = { text = "木讷", comment = "mù nè" },
["du le le"] = { text = "独乐乐", comment = "dú yuè lè" },
["zhong le le"] = { text = "众乐乐", comment = "zhòng yuè lè" },
["xun ma"] = { text = "荨麻", comment = "qián má" },
["qian ma zhen"] = { text = "荨麻疹", comment = "xún má zhěn" },
["mo ju"] = { text = "模具", comment = "mú jù" },
["cao zhi"] = { text = "草薙", comment = "cǎo tì" },
["cao zhi jing"] = { text = "草薙京", comment = "cǎo tì jīng" },
["cao zhi jian"] = { text = "草薙剑", comment = "cǎo tì jiàn" },
["jia ping ao"] = { text = "贾平凹", comment = "jià píng wā" },
["xue fo lan"] = { text = "雪佛兰", comment = "xuě fú lán" },
["qiang jin"] = { text = "强劲", comment = "qiáng jìng" },
["tong ti"] = { text = "胴体", comment = "dòng tǐ" },
["li neng kang ding"] = { text = "力能扛鼎", comment = "lì néng gāng dǐng" },
["ya lv jiang"] = { text = "鸭绿江", comment = "yā lù jiāng" },
["da fu bian bian"] = { text = "大腹便便", comment = "dà fù pián pián" },
["ka bo zi"] = { text = "卡脖子", comment = "qiǎ bó zi" },
["zhi sheng"] = { text = "吱声", comment = "zī shēng" },
["chan he"] = { text = "掺和", comment = "chān huo" },
["chan huo"] = { text = "掺和", comment = "chān huo" },
["can he"] = { text = "掺和", comment = "chān huo" },
["cheng zhi"] = { text = "称职", comment = "chèn zhí" },
["luo shi fen"] = { text = "螺蛳粉", comment = "luó sī fěn" },
["tiao huan"] = { text = "调换", comment = "diào huàn" },
["tai xing shan"] = { text = "太行山", comment = "tài háng shān" },
["jie si di li"] = { text = "歇斯底里", comment = "xiē sī dǐ lǐ" },
["nuan he"] = { text = "暖和", comment = "nuǎn huo" },
["mo ling liang ke"] = { text = "模棱两可", comment = "mó léng liǎng kě" },
["pan yang hu"] = { text = "鄱阳湖", comment = "pó yáng hú" },
["bo jing"] = { text = "脖颈", comment = "bó gěng" },
["bo jing er"] = { text = "脖颈儿", comment = "bó gěng er" },
["jie zha"] = { text = "结扎", comment = "jié zā" },
["hai shen wei"] = { text = "海参崴", comment = "hǎi shēn wǎi" },
["hou pu"] = { text = "厚朴", comment = "hòu pò" },
["da wan ma"] = { text = "大宛马", comment = "dà yuān mǎ" },
-- 错字
["pu jie"] = { text = "扑街", comment = "仆街" },
["pu gai"] = { text = "扑街", comment = "仆街" },
["pu jie zai"] = { text = "扑街仔", comment = "仆街仔" },
["pu gai zai"] = { text = "扑街仔", comment = "仆街仔" },
["ceng jin"] = { text = "曾今", comment = "曾经" },
["an nai"] = { text = "按耐", comment = "按捺(nà)" },
["an nai bu zhu"] = { text = "按耐不住", comment = "按捺(nà)不住" },
["bie jie"] = { text = "别介", comment = "别价(jie)" },
["beng jie"] = { text = "甭介", comment = "甭价(jie)" },
["xue mai pen zhang"] = { text = "血脉喷张", comment = "血脉贲(bēn)张 | 血脉偾(fèn)张" },
["qi ke fu"] = { text = "契科夫", comment = "契诃(hē)夫" },
["zhao cha"] = { text = "找茬", comment = "找碴" },
["zhao cha er"] = { text = "找茬儿", comment = "找碴儿" },
["da jia lai zhao cha"] = { text = "大家来找茬", comment = "大家来找碴" },
["da jia lai zhao cha er"] = { text = "大家来找茬儿", comment = "大家来找碴儿" },
["ci ya"] = { text = "龇牙", comment = "龇(zī)牙" },
["ci zhe ya"] = { text = "龇着牙", comment = "龇(zī)着牙" },
["ci ya lie zui"] = { text = "龇牙咧嘴", comment = "龇(zī)牙咧嘴" },
["cou huo"] = { text = "凑活", comment = "凑合(he)" },
}
local M = {}
local function corrector(input)
function M.init(env)
local config = env.engine.schema.config
env.name_space = env.name_space:gsub('^*', '')
M.style = config:get_string(env.name_space) or '{comment}'
M.corrections = {
-- 错音
["hun dun"] = { text = "馄饨", comment = "hún tun" },
["zhu jiao"] = { text = "主角", comment = "zhǔ jué" },
["jiao se"] = { text = "角色", comment = "júe sè" },
["pi sa"] = { text = "比萨", comment = "bǐ sà" },
["chi pi sa"] = { text = "吃比萨", comment = "chī bǐ sà" },
["pi sa bing"] = { text = "比萨饼", comment = "bǐ sà bǐng" },
["shui fu"] = { text = "说服", comment = "shuō fú" },
["dao hang"] = { text = "道行", comment = "dào héng" },
["mo yang"] = { text = "模样", comment = "mú yàng" },
["you mo you yang"] = { text = "有模有样", comment = "yǒu mú yǒu yàng" },
["yi mo yi yang"] = { text = "一模一样", comment = "yī mú yī yàng" },
["zhuang mo zuo yang"] = { text = "装模作样", comment = "zhuāng mú zuò yàng" },
["ren mo gou yang"] = { text = "人模狗样", comment = "rén mú góu yàng" },
["mo ban"] = { text = "模板", comment = "mú bǎn" },
["a mi tuo fo"] = { text = "阿弥陀佛", comment = "ē mí tuó fó" },
["na mo a mi tuo fo"] = { text = "南无阿弥陀佛", comment = "nā mó ē mí tuó fó" },
["nan wu a mi tuo fo"] = { text = "南无阿弥陀佛", comment = "nā mó ē mí tuó fó" },
["nan wu e mi tuo fo"] = { text = "南无阿弥陀佛", comment = "nā mó ē mí tuó fó" },
["gei yu"] = { text = "给予", comment = "jǐ yǔ" },
["bin lang"] = { text = "槟榔", comment = "bīng láng" },
["zhang bai zhi"] = { text = "张柏芝", comment = "zhāng bó zhī" },
["teng man"] = { text = "藤蔓", comment = "téng wàn" },
["nong tang"] = { text = "弄堂", comment = "lòng táng" },
["xin kuan ti pang"] = { text = "心宽体胖", comment = "xīn kūan tǐ pán" },
["mai yuan"] = { text = "埋怨", comment = "mán yuàn" },
["xu yu wei she"] = { text = "虚与委蛇", comment = "xū yǔ wēi yí" },
["mu na"] = { text = "木讷", comment = "mù nè" },
["du le le"] = { text = "独乐乐", comment = "dú yuè lè" },
["zhong le le"] = { text = "众乐乐", comment = "zhòng yuè lè" },
["xun ma"] = { text = "荨麻", comment = "qián má" },
["qian ma zhen"] = { text = "荨麻疹", comment = "xún má zhěn" },
["mo ju"] = { text = "模具", comment = "mú jù" },
["cao zhi"] = { text = "草薙", comment = "cǎo tì" },
["cao zhi jing"] = { text = "草薙京", comment = "cǎo tì jīng" },
["cao zhi jian"] = { text = "草薙剑", comment = "cǎo tì jiàn" },
["jia ping ao"] = { text = "贾平凹", comment = "jià píng wā" },
["xue fo lan"] = { text = "雪佛兰", comment = "xuě fú lán" },
["qiang jin"] = { text = "强劲", comment = "qiáng jìng" },
["tong ti"] = { text = "胴体", comment = "dòng tǐ" },
["li neng kang ding"] = { text = "力能扛鼎", comment = "lì néng gāng dǐng" },
["ya lv jiang"] = { text = "鸭绿江", comment = "yā lù jiāng" },
["da fu bian bian"] = { text = "大腹便便", comment = "dà fù pián pián" },
["ka bo zi"] = { text = "卡脖子", comment = "qiǎ bó zi" },
["zhi sheng"] = { text = "吱声", comment = "zī shēng" },
["chan he"] = { text = "掺和", comment = "chān huo" },
["chan huo"] = { text = "掺和", comment = "chān huo" },
["can he"] = { text = "掺和", comment = "chān huo" },
["cheng zhi"] = { text = "称职", comment = "chèn zhí" },
["luo shi fen"] = { text = "螺蛳粉", comment = "luó sī fěn" },
["tiao huan"] = { text = "调换", comment = "diào huàn" },
["tai xing shan"] = { text = "太行山", comment = "tài háng shān" },
["jie si di li"] = { text = "歇斯底里", comment = "xiē sī dǐ lǐ" },
["nuan he"] = { text = "暖和", comment = "nuǎn huo" },
["mo ling liang ke"] = { text = "模棱两可", comment = "mó léng liǎng kě" },
["pan yang hu"] = { text = "鄱阳湖", comment = "pó yáng hú" },
["bo jing"] = { text = "脖颈", comment = "bó gěng" },
["bo jing er"] = { text = "脖颈儿", comment = "bó gěng er" },
["jie zha"] = { text = "结扎", comment = "jié zā" },
["hai shen wei"] = { text = "海参崴", comment = "hǎi shēn wǎi" },
["hou pu"] = { text = "厚朴", comment = "hòu pò" },
["da wan ma"] = { text = "大宛马", comment = "dà yuān mǎ" },
-- 错字
["pu jie"] = { text = "扑街", comment = "仆街" },
["pu gai"] = { text = "扑街", comment = "仆街" },
["pu jie zai"] = { text = "扑街仔", comment = "仆街仔" },
["pu gai zai"] = { text = "扑街仔", comment = "仆街仔" },
["ceng jin"] = { text = "曾今", comment = "曾经" },
["an nai"] = { text = "按耐", comment = "按捺(nà)" },
["an nai bu zhu"] = { text = "按耐不住", comment = "按捺(nà)不住" },
["bie jie"] = { text = "别介", comment = "别价(jie)" },
["beng jie"] = { text = "甭介", comment = "甭价(jie)" },
["xue mai pen zhang"] = { text = "血脉喷张", comment = "血脉贲(bēn)张 | 血脉偾(fèn)张" },
["qi ke fu"] = { text = "契科夫", comment = "契诃(hē)夫" },
["zhao cha"] = { text = "找茬", comment = "找碴" },
["zhao cha er"] = { text = "找茬儿", comment = "找碴儿" },
["da jia lai zhao cha"] = { text = "大家来找茬", comment = "大家来找碴" },
["da jia lai zhao cha er"] = { text = "大家来找茬儿", comment = "大家来找碴儿" },
["ci ya"] = { text = "龇牙", comment = "龇(zī)牙" },
["ci zhe ya"] = { text = "龇着牙", comment = "龇(zī)着牙" },
["ci ya lie zui"] = { text = "龇牙咧嘴", comment = "龇(zī)牙咧嘴" },
["cou huo"] = { text = "凑活", comment = "凑合(he)" },
}
end
function M.func(input)
for cand in input:iter() do
-- cand.comment 是目前输入的词汇的完整拼音
local c = corrections[cand.comment]
local c = M.corrections[cand.comment]
if c and cand.text == c.text then
cand:get_genuine().comment = c.comment
cand:get_genuine().comment = string.gsub(M.style, "{comment}", c.comment)
elseif cand.type == "user_phrase" or cand.type == "phrase" or cand.type == "sentence" then
cand:get_genuine().comment = ""
end
@ -107,4 +114,4 @@ local function corrector(input)
end
end
return corrector
return M

View File

@ -86,8 +86,14 @@ date_translator:
timestamp: ts # 时间戳: 1669716794
# Lua 配置:农历
lunar: nl # 癸卯年(兔)冬月廿一 二〇二四年冬月廿一
# Lua 配置:农历的触发关键字
lunar: nl # 癸卯年(兔)冬月廿一 二〇二四年冬月廿一
# Lua 配置:为 corrector 格式化 comment占位符为 {comment}
# 默认 "{comment}" 输入 hun dun 时会在「馄饨」旁边生成 hún tun 的 comment
# 例如左右加个括号 "({comment})" 就会变成 (hún tun)
corrector: "{comment}"
# Lua 配置: 降低部分英语单词在候选项的位置。
@ -125,16 +131,16 @@ reduce_english_filter:
# 主翻译器,拼音
translator:
dictionary: rime_ice # 挂载词库 rime_ice.dict.yaml
spelling_hints: 8 # corrector.lua :为了让错音错字提示的 Lua 同时适配全拼双拼,将拼音显示在 comment 中
always_show_comments: true # corrector.lua Rime 默认在 preedit 等于 comment 时取消显示 comment这里强制一直显示供 corrector.lua 做判断用。
initial_quality: 1.2 # 拼音的权重应该比英文大
preedit_format: # preedit_format 影响到输入框的显示和“Shift+回车”上屏的字符
- xform/([jqxy])v/$1u/ # 显示为 ju qu xu yu
# - xform/([nl])v/$1ü/ # 显示为 nü lü
# - xform/([nl])ue/$1üe/ # 显示为 nüe lüe
- xform/([nl])v/$1v/ # 显示为 nv lv
- xform/([nl])ue/$1ve/ # 显示为 nve lve
dictionary: rime_ice # 挂载词库 rime_ice.dict.yaml
spelling_hints: 8 # corrector.lua :为了让错音错字提示的 Lua 同时适配全拼双拼,将拼音显示在 comment 中
always_show_comments: true # corrector.lua Rime 默认在 preedit 等于 comment 时取消显示 comment这里强制一直显示供 corrector.lua 做判断用。
initial_quality: 1.2 # 拼音的权重应该比英文大
preedit_format: # preedit_format 影响到输入框的显示和“Shift+回车”上屏的字符
- xform/([jqxy])v/$1u/ # 显示为 ju qu xu yu
# - xform/([nl])v/$1ü/ # 显示为 nü lü
# - xform/([nl])ue/$1üe/ # 显示为 nüe lüe
- xform/([nl])v/$1v/ # 显示为 nv lv
- xform/([nl])ue/$1ve/ # 显示为 nve lve
# 次翻译器,英文
@ -158,11 +164,11 @@ liangfen:
# 自定义短语custom_phrase.txt
custom_phrase:
dictionary: ""
user_dict: custom_phrase
user_dict: custom_phrase # 可以修改这里,改成自己的 txt 文件
db_class: stabledb
enable_completion: false # 补全提示
enable_sentence: false # 禁止造句
initial_quality: 99 # custom_phrase 的权重应该比 pinyin 和 melt_eng 大
enable_completion: false # 补全提示
enable_sentence: false # 禁止造句
initial_quality: 99 # custom_phrase 的权重应该比 pinyin 和 melt_eng 大
# Emoji