Skip to content

Commit

Permalink
feat: add new filters
Browse files Browse the repository at this point in the history
正确调用过滤器,并添加两个类型
最长词组和单字在先 与 只显示单字
  • Loading branch information
LufsX committed Jan 13, 2023
1 parent b674fd5 commit 2f8bead
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lufs_flypy.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ engine:
- fallback_segmentor
translators:
- punct_translator
- lua_translator@date_translator
- table_translator@custom_phrase
- lua_translator@date_translator # 动态日期时间输入
- table_translator@custom_phrase # 用户自定义词典
- script_translator
filters:
- simplifier@emoji_suggestion
- simplifier
- uniquifier
- single_char_filter
# - lua_filter@long_phrase_first # 最长词组和单字在先
# - lua_filter@single_char_first # 单字优先
# - lua_filter@single_char_only # 只显示单字

emoji_suggestion:
opencc_config: emoji.json
Expand Down
10 changes: 5 additions & 5 deletions lufs_pinyin.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ engine:
- fallback_segmentor
translators:
- punct_translator
- lua_translator@date_translator
- table_translator@custom_phrase
- lua_translator@date_translator # 动态日期时间输入
- table_translator@custom_phrase # 用户自定义词典
- script_translator
filters:
- simplifier@emoji_suggestion
- simplifier
- uniquifier
- single_char_filter
# - lua_filter@long_phrase_first # 最长词组和单字在先
# - lua_filter@single_char_first # 单字优先
# - lua_filter@single_char_only # 只显示单字

emoji_suggestion:
opencc_config: emoji.json
Expand Down
40 changes: 39 additions & 1 deletion rime.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
--- 过滤器:最长词组和单字在先
function long_phrase_first(input)
local l = {}
local s = {}
local c = {}
local max = 1
for cand in input:iter() do
if (utf8.len(cand.text) > max) then
max = utf8.len(cand.text)
end
if (utf8.len(cand.text) == 1) then
table.insert(c, cand)
elseif (utf8.len(cand.text) < max) then
table.insert(s, cand)
else
table.insert(l, cand)
end
end
for i, cand in ipairs(l) do
yield(cand)
end
for i, cand in ipairs(c) do
yield(cand)
end
for i, cand in ipairs(s) do
yield(cand)
end
end

--- 过滤器:单字在先
function single_char_first_filter(input)
function single_char_first(input)
local l = {}
for cand in input:iter() do
if (utf8.len(cand.text) == 1) then
Expand All @@ -13,6 +42,15 @@ function single_char_first_filter(input)
end
end

--- 过滤器:只显示单字
function single_char_only(input)
for cand in input:iter() do
if (utf8.len(cand.text) == 1) then
yield(cand)
end
end
end

-- select_character_processor: 以词定字
-- 详见 `lua/select_character.lua`
select_character_processor = require("select_character")
Expand Down

0 comments on commit 2f8bead

Please sign in to comment.