Skip to content

Commit 050ec64

Browse files
committed
test: 调试代码开源
1 parent 88afb38 commit 050ec64

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

lua/tag_user_dict.lua

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
--[[
2+
调试候选词工具代码。
3+
作者:[Mintimate](https://github.com/Mintimate)
4+
5+
默认不启用,用于调试候选词。
6+
--]]
7+
8+
9+
local M = {}
10+
11+
function M.init(env)
12+
local config = env.engine.schema.config
13+
env.name_space = env.name_space:gsub('^*', '')
14+
M.user_table = config:get_string(env.name_space .. "/user_table")
15+
M.completion = config:get_string(env.name_space .. "/completion")
16+
M.sentence = config:get_string(env.name_space .. "/sentence")
17+
M.phrase = config:get_string(env.name_space .. "/phrase")
18+
M.user_phrase = config:get_string(env.name_space .. "/user_phrase")
19+
end
20+
21+
function M.processCandidate(cand)
22+
if cand.comment ~= "" then
23+
cand:get_genuine().comment = cand.comment .. " "
24+
end
25+
end
26+
27+
-- 这个函数处理输入并对每个候选项应用条件。
28+
-- @param input 包含候选项的输入对象。
29+
-- @param env 环境对象。
30+
function M.func(input, env)
31+
-- 定义要应用于每个候选项的条件。
32+
local conditions = {
33+
{type = "user_table", value = M.user_table}, -- 用户表条件
34+
{type = "sentence", value = M.sentence}, -- 句子条件
35+
{type = "user_phrase", value = M.user_phrase}, -- 用户短语条件
36+
{type = "phrase", value = M.phrase}, -- 短语条件
37+
{type = "completion", value = M.completion} -- 完成条件
38+
}
39+
40+
-- 遍历输入中的每个候选项。
41+
for cand in input:iter() do
42+
-- 对候选项应用条件。
43+
for _, condition in ipairs(conditions) do
44+
if cand.type == condition.type and condition.value then
45+
-- 处理候选项。
46+
M.processCandidate(cand)
47+
-- 将条件值追加到候选项的注释中。
48+
cand:get_genuine().comment = cand.comment .. condition.value
49+
break
50+
end
51+
end
52+
-- 返回候选项。
53+
yield(cand)
54+
end
55+
end
56+
57+
return M
58+

0 commit comments

Comments
 (0)