fix: 适配元书的九宫格处理器

This commit is contained in:
amzxyz
2026-01-10 22:40:48 +08:00
parent 0673f3fab2
commit 45124a26f8
3 changed files with 27 additions and 31 deletions

View File

@@ -15,6 +15,8 @@ sort: original #字典初始排序可選original或by_weight
4H 4H
4X 4X
7z 7z
+86 jiā'86
WiFi伴侣 wifi'bàn'lǚ
AA制 AA'zhì
A班 A'bān
A杯 A'bēi

View File

@@ -28,7 +28,7 @@ local M = {}
local byte, find, gsub, upper, sub = string.byte, string.find, string.gsub, string.upper, string.sub
-- ========= 工具 =========
-- 工具
local function fast_type(c)
local t = c.type
if t then return t end
@@ -72,32 +72,20 @@ local function has_english_token_fast(s)
return false
end
-- ========= 英文候选判定 =========
-- 使用现有的 has_english_token_fast 叠加 is_table_type
-- - 若不属于 table/user_table/fixed只要含英文 token 即视为英文候选
-- - 若属于 table/user_table/fixed要求“只含 ASCII”没有中文且含英文 token
-- 纯ASCII判定
local function is_english_candidate(cand)
if not cand or not cand.text or cand.text == "" then return false end
local txt = cand.text
local txt = cand and cand.text
if not txt or txt == "" then return false end
if not has_english_token_fast(txt) then
return false
end
if is_table_type(cand) then
-- 表内候选如果混有非 ASCII大概率是中文就不当英文处理
for i = 1, #txt do
local b = byte(txt, i)
if b > 127 then
return false
end
end
if string.find(txt, "[\128-\255]") then
return false
end
return true
end
-- ========= 文本格式化(转义 + 自动大写)=========
-- 文本格式化(转义 + 自动大写)
local escape_map = {
["\\n"] = "\n", ["\\t"] = "\t", ["\\r"] = "\r",
["\\\\"] = "\\", ["\\s"] = " ", ["\\d"] = "-",
@@ -137,7 +125,7 @@ local function clone_candidate(c)
return nc
end
-- ========= 包裹映射 =========
-- 包裹映射
local default_wrap_map = {
-- 单字母:常用成对括号/引号(每项恰好两个字符)
a = "[]", -- 方括号
@@ -167,14 +155,14 @@ local default_wrap_map = {
y = "⟪⟫", -- 双角括号
z = "{}", -- 花括号
-- ===== 扩展括号族 / 引号 =====
-- 扩展括号族 / 引号
dy = "''", -- 英文单引号
sy = "\"\"", -- 英文双引号
zs = "“”", -- 中文弯双引号
zd = "", -- 中文弯单引号
fy = "``", -- 反引号
-- ===== 双字母括号族 =====
-- 双字母括号族
aa = "〚〛", -- 双中括号
bb = "〘〙", -- 双中括号(小)
cc = "〚〛", -- 双中括号(重复,可用于 Lua 匹配)
@@ -201,7 +189,7 @@ local default_wrap_map = {
yy = "⌠⌡", -- 数学 / 程序符号
zz = "⟅⟆", -- 数学 / 装饰括号
-- ===== Markdown / 标记 =====
-- Markdown / 标记
md = "**|**", -- Markdown 粗体
jc = "**|**", -- 加粗
it = "__|__", -- 斜体
@@ -222,7 +210,7 @@ local default_wrap_map = {
br = "| ", -- 换行
cm = "<!--|-->", -- 注释
-- ===== 运算与标记符 =====
-- 运算与标记符
pl = "++",
mi = "--",
sl = "//",
@@ -292,7 +280,7 @@ local function precompile_wrap_parts(wrap_map, delimiter)
end
return parts
end
-- ========= 字符集过滤工具 =========
-- 字符集过滤工具
-- 单个码点是否在 charset 里(带缓存,考虑白名单 + 黑名单)
local function codepoint_in_charset(env, codepoint)
if not env then
@@ -390,7 +378,7 @@ local function is_reverse_lookup_segment(env)
or seg:has_tag("add_user_dict")
or seg:has_tag("punct")
end
-- ========= 字符集过滤初始化 =========
-- 字符集过滤初始化
-- 从 schema 里读取 charsetlist / charsetblacklist
local function init_charset_filter(env, cfg)
-- 主字符集(表滤镜)
@@ -441,7 +429,7 @@ local function init_charset_filter(env, cfg)
load_charset_list("charsetblacklist", env.charset_block)
end
-- ========= 生命周期 =========
-- 生命周期
function M.init(env)
local cfg = env.engine and env.engine.schema and env.engine.schema.config or nil
env.wrap_map = cfg and load_mapping_from_config(cfg) or default_wrap_map
@@ -489,7 +477,7 @@ end
function M.fini(env)
end
-- ========= 统一产出通道 =========
-- 统一产出通道
-- ctxs:
-- charset : 字符集过滤
-- suppress_set : { [text] = true } 阻止镜像文本
@@ -542,7 +530,7 @@ local function emit_with_pipeline(cand, ctxs)
cand = ctxs.unify_tail_span(cand)
yield(cand)
end
-- ========= 主流程 =========
-- 主流程
function M.func(input, env)
local ctx = env and env.engine and env.engine.context or nil
local code = ctx and (ctx.input or "") or ""
@@ -701,7 +689,7 @@ function M.func(input, env)
return true
end
-- ===== 非分组路径 =====
-- 非分组路径
if not do_group then
local idx = 0
for cand in input:iter() do
@@ -755,7 +743,7 @@ function M.func(input, env)
return
end
-- ===== 分组路径2..6 码)=====
-- 分组路径2..6 码)
local idx2, mode, grouped_cnt = 0, "unknown", 0
local window_closed = false
local group2_others = {}

View File

@@ -43,6 +43,7 @@ switches:
# 输入引擎
engine:
processors:
- t9_processor #元书T9处理器
- lua_processor@*super_tips #超级提示模块:表情、简码、翻译、化学式、等等靠你想象
- lua_processor@*partial_commit #通过ctrl+1~0局部提交10个字以内的句子的前几个字一般为正确的前几个使用时要遵循合理的分词结构能促进后续编码打出正确的词汇
- lua_processor@*super_sequence*P #手动排序,高亮候选 ctrl+j左移动 ctrl+k 右移动 ctrl+l 移除位移 ctrl+p 置顶
@@ -89,6 +90,11 @@ engine:
- lua_filter@*super_sequence*F #手动排序,高亮候选 ctrl+j左移动 ctrl+k 右移动 ctrl+0 移除位移
- uniquifier # 去重
t9:
enable: true #启用仓、元书t9输入方式
super_comment: # 超级注释模块,子项配置 true 开启false 关闭
candidate_length: 1 # 候选词辅助码提醒的生效长度0为关闭 但同时清空其它,应当使用上面开关来处理
corrector_type: "comment" # 错音措字,随意更换左右括号,比如"comment" 不加括号为无括号comment占位不能动