mirror of
https://github.com/iDvel/rime-ice.git
synced 2026-05-14 00:30:37 +08:00
config: 将长词优先的配置放到方案中。
This commit is contained in:
14
rime.lua
14
rime.lua
@@ -139,10 +139,12 @@ end
|
||||
-- 长词优先(提升「西安」「提案」「图案」「饥饿」等词汇的优先级)
|
||||
-- 感谢&参考于: https://github.com/tumuyan/rime-melt
|
||||
-- 修改:不提升英文和中英混输的
|
||||
function long_word_filter(input)
|
||||
-- 目前的效果:将 2 个词插入到第 4、5 个候选项
|
||||
local count = 2 -- 提升 count 个词语
|
||||
local idx = 4 -- 插入到第 idx 位
|
||||
function long_word_filter(input, env)
|
||||
-- 提升 count 个词语,插入到第 idx 个位置,默认 2、4。
|
||||
local config = env.engine.schema.config
|
||||
local count = config:get_string(env.name_space .."/count") or 2
|
||||
local idx = config:get_string(env.name_space .."/idx") or 4
|
||||
|
||||
|
||||
local l = {}
|
||||
local firstWordLength = 0 -- 记录第一个候选词的长度,提前的候选词至少要比第一个候选词长
|
||||
@@ -152,7 +154,7 @@ function long_word_filter(input)
|
||||
local i = 1
|
||||
for cand in input:iter() do
|
||||
leng = utf8.len(cand.text)
|
||||
if (firstWordLength < 1 or i < idx) then
|
||||
if (firstWordLength < 1 or i < tonumber(idx)) then
|
||||
i = i + 1
|
||||
firstWordLength = leng
|
||||
yield(cand)
|
||||
@@ -167,7 +169,7 @@ function long_word_filter(input)
|
||||
-- end
|
||||
-- 换了个正则,否则中英混输的也会被提升
|
||||
-- elseif ((leng > firstWordLength) and (s2 < count)) and (string.find(cand.text, "^[%w%p%s]+$")==nil) then
|
||||
elseif ((leng > firstWordLength) and (s2 < count)) and (string.find(cand.text, "[%w%p%s]+") == nil) then
|
||||
elseif ((leng > firstWordLength) and (s2 < tonumber(count))) and (string.find(cand.text, "[%w%p%s]+") == nil) then
|
||||
yield(cand)
|
||||
s2 = s2 + 1
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user