config: 提取日期时间的关键词配置到方案中; close #47

This commit is contained in:
Dvel 2022-11-29 18:23:53 +08:00
parent 81b5018667
commit 5f26cf56ff
4 changed files with 44 additions and 8 deletions

View File

@ -80,6 +80,15 @@ engine:
code_length_limit_processor: 100
# 日期、时间、星期、ISO 8601、时间戳的触发关键字
date_translator:
date: date # 日期: 2022-11-29
time: time # 时间: 18:13
week: week # 星期: 星期二
datetime: datetime # ISO 8601 2022-11-29T18:13:11+08:00
timestamp: timestamp # 时间戳: 1669716794
# 从 default 继承快捷键
key_binder:
import_preset: default

View File

@ -80,6 +80,15 @@ engine:
code_length_limit_processor: 100
# 日期、时间、星期、ISO 8601、时间戳的触发关键字
date_translator:
date: date # 日期: 2022-11-29
time: time # 时间: 18:13
week: week # 星期: 星期二
datetime: datetime # ISO 8601 2022-11-29T18:13:11+08:00
timestamp: timestamp # 时间戳: 1669716794
# 从 default 继承快捷键
key_binder:
import_preset: default

View File

@ -2,9 +2,15 @@
-------------------------------------------------------------
-- 日期时间
-- 提高权重的原因:因为在方案中设置了大于 1 的 initial_quality导致 rq sj xq dt ts 产出的候选项在所有词语的最后。
function date_translator(input, seg)
function date_translator(input, seg, env)
local config = env.engine.schema.config
local date = config:get_string(env.name_space .."/date") or "rq"
local time = config:get_string(env.name_space .."/time") or "sj"
local week = config:get_string(env.name_space .."/week") or "xq"
local datetime = config:get_string(env.name_space .."/datetime") or "dt"
local timestamp = config:get_string(env.name_space .."/timestamp") or "ts"
-- 日期
if (input == "rq") then
if (input == date) then
local cand = Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), "")
cand.quality = 100
yield(cand)
@ -19,7 +25,7 @@ function date_translator(input, seg)
yield(cand)
end
-- 时间
if (input == "sj") then
if (input == time) then
local cand = Candidate("time", seg.start, seg._end, os.date("%H:%M"), "")
cand.quality = 100
yield(cand)
@ -28,17 +34,20 @@ function date_translator(input, seg)
yield(cand)
end
-- 星期
if (input == "xq") then
if (input == week) then
local weakTab = {'', '', '', '', '', '', ''}
local cand = Candidate("week", seg.start, seg._end, "" .. weakTab[tonumber(os.date("%w") + 1)], "")
local cand = Candidate("week", seg.start, seg._end, "星期" .. weakTab[tonumber(os.date("%w") + 1)], "")
cand.quality = 100
yield(cand)
local cand = Candidate("week", seg.start, seg._end, "星期" .. weakTab[tonumber(os.date("%w") + 1)], "")
local cand = Candidate("week", seg.start, seg._end, "礼拜" .. weakTab[tonumber(os.date("%w") + 1)], "")
cand.quality = 100
yield(cand)
local cand = Candidate("week", seg.start, seg._end, "" .. weakTab[tonumber(os.date("%w") + 1)], "")
cand.quality = 100
yield(cand)
end
-- ISO 8601/RFC 3339 的时间格式 (固定东八区)(示例 2022-01-07T20:42:51+08:00
if (input == "dt") then
if (input == datetime) then
local cand = Candidate("datetime", seg.start, seg._end, os.date("%Y-%m-%dT%H:%M:%S+08:00"), "")
cand.quality = 100
yield(cand)
@ -47,7 +56,7 @@ function date_translator(input, seg)
yield(cand)
end
-- 时间戳(十位数,到秒,示例 1650861664
if (input == "ts") then
if (input == timestamp) then
local cand = Candidate("datetime", seg.start, seg._end, os.time(), "")
cand.quality = 100
yield(cand)

View File

@ -74,6 +74,15 @@ engine:
code_length_limit_processor: 100
# 日期、时间、星期、ISO 8601、时间戳的触发关键字
date_translator:
date: rq # 日期: 2022-11-29
time: sj # 时间: 18:13
week: xq # 星期: 星期二
datetime: dt # ISO 8601 2022-11-29T18:13:11+08:00
timestamp: ts # 时间戳: 1669716794
# 长词优先,提升 count 个词语,插入到第 idx 个位置,默认 2、4。
# 示例:将 2 个词插入到第 4、5 个候选项,输入 jie 得到「1接 2解 3姐 4饥饿 5极恶」
long_word_filter: