From a42fa3dadad1dbd5a4597190dfd8ab25b6720c95 Mon Sep 17 00:00:00 2001 From: amzxyz Date: Sat, 10 Jan 2026 09:16:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=87=AA=E5=8A=A8=E9=80=A0=E8=AF=8D?= =?UTF-8?q?=E7=9A=84=E9=9D=9E=E7=A1=AE=E5=AE=9A=E6=80=A7=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dicts/en.dict.yaml | 6 +----- lua/auto_phrase.lua | 42 +++++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/dicts/en.dict.yaml b/dicts/en.dict.yaml index d3b5aaa..a73ed56 100644 --- a/dicts/en.dict.yaml +++ b/dicts/en.dict.yaml @@ -7,10 +7,6 @@ name: wanxiang_english version: "LTS" sort: original ... - -a a -a. a. -a. 灵巧的, 熟练的 a. 灵巧的, 熟练的 AA AA aaa aaa aaliyah aaliyah @@ -45543,7 +45539,7 @@ pandemic pandemic pandemonium pandemonium pander pander pandit pandit -pandoc pandoc +Pandoc pandoc Pandora Pandora pandowdy pandowdy pane pane diff --git a/lua/auto_phrase.lua b/lua/auto_phrase.lua index d1cef4c..7974712 100644 --- a/lua/auto_phrase.lua +++ b/lua/auto_phrase.lua @@ -102,16 +102,16 @@ function AP.fini(env) end end -function AP.save_comment_cache(cand) - local comment = cand.comment - local comment_text = cand.text +function AP.save_comment_cache(cand, genuine) + local text = cand.text + local comment = genuine.comment - if comment_text and comment_text ~= "" and comment and comment ~= "" then - comment_cache[comment_text] = comment + if text and text ~= "" and comment and comment ~= "" then + comment_cache[text] = comment end end --- 入口(lua_filter) +-- 入口 function AP.func(input, env) local config = env.engine.schema.config local context = env.engine.context @@ -124,14 +124,14 @@ function AP.func(input, env) local initial_comment = genuine_cand.comment if use_comment_cache then - AP.save_comment_cache(cand) + AP.save_comment_cache(cand, genuine_cand) end yield(cand) end end --- 造词(原逻辑 + 新增 '\' 英文造词 + 大小写双重存入) +-- 造词 function AP.commit_handler(ctx, env) if not ctx or not ctx.composition then comment_cache = {} @@ -168,12 +168,10 @@ function AP.commit_handler(ctx, env) if lower_code ~= code_body then save_entry(lower_code) end - - -- log.info(string.format("[auto_phrase] EN 造词:[%s], 原码=[%s], 小写码=[%s]", commit_text, code_body, lower_code)) end comment_cache = {} - return + return -- 英文造词后直接退出,杜绝干扰中文 end --------------------------------------------------- @@ -206,18 +204,24 @@ function AP.commit_handler(ctx, env) local seg = segments[i] local cand = seg:get_selected_candidate() - if cand then - local cand_text = cand.text - local preedit = comment_cache[cand_text] + -- 防止单字片段造词 + -- 如果取不到 cand,或者 cand.text 在缓存里没有编码,说明数据缺失,直接放弃 + if not cand or not comment_cache[cand.text] then + comment_cache = {} + return + end - if preedit and preedit ~= "" then - for part in preedit:gmatch("[^" .. escaped_delimiter .. "]+") do - table.insert(preedits_table, part) - end + local cand_text = cand.text + local preedit = comment_cache[cand_text] + + if preedit and preedit ~= "" then + for part in preedit:gmatch("[^" .. escaped_delimiter .. "]+") do + table.insert(preedits_table, part) end end end + -- 二次检查:如果解析出来的编码段数不对,也不存 if #preedits_table == 0 then comment_cache = {} return @@ -233,4 +237,4 @@ function AP.commit_handler(ctx, env) comment_cache = {} end -return AP +return AP \ No newline at end of file