This commit is contained in:
parent
0dc60fb756
commit
84106b2e26
39
rime.lua
39
rime.lua
@ -62,6 +62,16 @@ function date_translator(input, seg, env)
|
|||||||
cand.quality = 100
|
cand.quality = 100
|
||||||
yield(cand)
|
yield(cand)
|
||||||
end
|
end
|
||||||
|
-- 输出内存
|
||||||
|
-- local cand = Candidate("date", seg.start, seg._end, ("%.f"):format(collectgarbage('count')), "")
|
||||||
|
-- cand.quality = 100
|
||||||
|
-- yield(cand)
|
||||||
|
-- if input == "xxx" then
|
||||||
|
-- collectgarbage()
|
||||||
|
-- local cand = Candidate("date", seg.start, seg._end, "collectgarbage()", "")
|
||||||
|
-- cand.quality = 100
|
||||||
|
-- yield(cand)
|
||||||
|
-- end
|
||||||
end
|
end
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
-- 以词定字
|
-- 以词定字
|
||||||
@ -155,16 +165,14 @@ function long_word_filter(input, env)
|
|||||||
local count = config:get_int(env.name_space .. "/count") or 2
|
local count = config:get_int(env.name_space .. "/count") or 2
|
||||||
local idx = config:get_int(env.name_space .. "/idx") or 4
|
local idx = config:get_int(env.name_space .. "/idx") or 4
|
||||||
|
|
||||||
|
local code = env.engine.context.input -- 当前编码
|
||||||
|
if string.find(code, "[aeo]") then -- 要提升的词汇拼音一定是包含 a o e 的
|
||||||
local l = {}
|
local l = {}
|
||||||
local firstWordLength = 0 -- 记录第一个候选词的长度,提前的候选词至少要比第一个候选词长
|
local firstWordLength = 0 -- 记录第一个候选词的长度,提前的候选词至少要比第一个候选词长
|
||||||
local s = 0 -- 记录筛选了多少个词条(只提升 count 个词的权重)
|
local s = 0 -- 记录筛选了多少个词条(只提升 count 个词的权重)
|
||||||
|
|
||||||
local i = 1
|
local i = 1
|
||||||
for cand in input:iter() do
|
for cand in input:iter() do
|
||||||
-- 找齐了或者 l 太大了,就不找了
|
-- 找到要提升的词
|
||||||
if (s == count) or (#l > 50) then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
local leng = utf8.len(cand.text)
|
local leng = utf8.len(cand.text)
|
||||||
if (firstWordLength < 1 or i < idx) then
|
if (firstWordLength < 1 or i < idx) then
|
||||||
i = i + 1
|
i = i + 1
|
||||||
@ -176,6 +184,18 @@ function long_word_filter(input, env)
|
|||||||
else
|
else
|
||||||
table.insert(l, cand)
|
table.insert(l, cand)
|
||||||
end
|
end
|
||||||
|
-- 找齐了或者 l 太大了,就不找了
|
||||||
|
if s == count then
|
||||||
|
break
|
||||||
|
elseif #l > 50 then
|
||||||
|
local memory = collectgarbage('count')
|
||||||
|
if memory > 10000 then
|
||||||
|
collectgarbage('collect')
|
||||||
|
elseif memory > 5000 then
|
||||||
|
collectgarbage("step")
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
for _, cand in ipairs(l) do
|
for _, cand in ipairs(l) do
|
||||||
yield(cand)
|
yield(cand)
|
||||||
@ -183,12 +203,11 @@ function long_word_filter(input, env)
|
|||||||
for cand in input:iter() do
|
for cand in input:iter() do
|
||||||
yield(cand)
|
yield(cand)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- 如果内存大于 5000 的话,GC 一次,最小间隔 60s
|
for cand in input:iter() do
|
||||||
-- if collectgarbage('count') > 5000 and (os.time() - last_gc_time) > 60 then
|
yield(cand)
|
||||||
-- collectgarbage("collect")
|
end
|
||||||
-- last_gc_time = os.time()
|
|
||||||
-- end
|
|
||||||
end
|
end
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
-- 降低部分英语单词在候选项的位置
|
-- 降低部分英语单词在候选项的位置
|
||||||
|
Loading…
Reference in New Issue
Block a user