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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,7 +9,13 @@
cn_dicts/others.dict.yaml issue cn_dicts/others.dict.yaml issue
--]] --]]
local corrections = { local M = {}
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" }, ["hun dun"] = { text = "馄饨", comment = "hún tun" },
["zhu jiao"] = { text = "主角", comment = "zhǔ jué" }, ["zhu jiao"] = { text = "主角", comment = "zhǔ jué" },
@ -93,13 +99,14 @@ local corrections = {
["ci ya lie zui"] = { text = "龇牙咧嘴", comment = "龇(zī)牙咧嘴" }, ["ci ya lie zui"] = { text = "龇牙咧嘴", comment = "龇(zī)牙咧嘴" },
["cou huo"] = { text = "凑活", comment = "凑合(he)" }, ["cou huo"] = { text = "凑活", comment = "凑合(he)" },
} }
end
local function corrector(input) function M.func(input)
for cand in input:iter() do for cand in input:iter() do
-- cand.comment 是目前输入的词汇的完整拼音 -- cand.comment 是目前输入的词汇的完整拼音
local c = corrections[cand.comment] local c = M.corrections[cand.comment]
if c and cand.text == c.text then 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 elseif cand.type == "user_phrase" or cand.type == "phrase" or cand.type == "sentence" then
cand:get_genuine().comment = "" cand:get_genuine().comment = ""
end end
@ -107,4 +114,4 @@ local function corrector(input)
end end
end end
return corrector return M

View File

@ -86,8 +86,14 @@ date_translator:
timestamp: ts # 时间戳: 1669716794 timestamp: ts # 时间戳: 1669716794
# Lua 配置:农历 # Lua 配置:农历的触发关键字
lunar: nl # 癸卯年(兔)冬月廿一 二〇二四年冬月廿一 lunar: nl # 癸卯年(兔)冬月廿一 二〇二四年冬月廿一
# Lua 配置:为 corrector 格式化 comment占位符为 {comment}
# 默认 "{comment}" 输入 hun dun 时会在「馄饨」旁边生成 hún tun 的 comment
# 例如左右加个括号 "({comment})" 就会变成 (hún tun)
corrector: "{comment}"
# Lua 配置: 降低部分英语单词在候选项的位置。 # Lua 配置: 降低部分英语单词在候选项的位置。
@ -158,7 +164,7 @@ liangfen:
# 自定义短语custom_phrase.txt # 自定义短语custom_phrase.txt
custom_phrase: custom_phrase:
dictionary: "" dictionary: ""
user_dict: custom_phrase user_dict: custom_phrase # 可以修改这里,改成自己的 txt 文件
db_class: stabledb db_class: stabledb
enable_completion: false # 补全提示 enable_completion: false # 补全提示
enable_sentence: false # 禁止造句 enable_sentence: false # 禁止造句