1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| function date_translator(input, seg)
if (input == "date") then
--- Candidate(type, start, end, text, comment)
yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), "日期"))
yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), "日期"))
end
if (input == "time") then
--- Candidate(type, start, end, text, comment)
yield(Candidate("date", seg.start, seg._end, os.date("%H:%M"), "时间"))
yield(Candidate("date", seg.start, seg._end, os.date("%H:%M:%S"), "时间"))
end
if (input == "datetime") then
--- Candidate(type, start, end, text, comment)
yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d %H:%M:%S"), "日期时间"))
end
end
--- 过滤器:单字在先
function single_char_first_filter(input)
local l = {}
for cand in input:iter() do
if (utf8.len(cand.text) == 1) then
yield(cand)
else
table.insert(l, cand)
end
end
for i, cand in ipairs(l) do
yield(cand)
end
end
|