Skip to content

Commit

Permalink
remove duplicates for embedded candidates filter
Browse files Browse the repository at this point in the history
  • Loading branch information
forFudan committed May 26, 2023
1 parent 6130619 commit bbdd268
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 22 deletions.
30 changes: 20 additions & 10 deletions beta/schema/lua/yuhao/yuhao_embeded_cands.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- 作者:王牌餅乾
-- https://github.com/lost-melody/

-- 將要被返回的過濾器對象
local embeded_cands_filter = {}

Expand All @@ -20,7 +23,7 @@ local index_indicators = {"¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "

-- 首選/非首選格式定義
-- seq: 候選序號; code: 編碼; 候選: 候選文本; comment: 候選提示
local first_format = "[候選code]comment"
local first_format = "候選code comment"
local next_format = "seq候選comment"
local separator = ""

Expand Down Expand Up @@ -101,28 +104,35 @@ function embeded_cands_filter.func(input, env)
page_cands, page_rendered = {}, {}
end

local hash = {}

-- 迭代器
local iter, obj = input:iter()
-- 迭代由翻譯器輸入的候選列表
local next = iter(obj)
while next do
-- 頁索引自增, 滿足 1 <= index <= page_size
index = index + 1

-- 當前遍歷候選項
local cand = next

if index == 1 then
-- 把首選捉出來
first_cand = cand
end
-- 去除重複項
if (not hash[cand.text]) then
hash[cand.text] = true

-- 修改首選的預编輯文本, 這会作爲内嵌編碼顯示到輸入處
preedit = render_cand(index, first_cand.preedit, cand.text, cand.comment)
if index == 1 then
-- 把首選捉出來
first_cand = cand
end

-- 存入候選
table.insert(page_cands, cand)
table.insert(page_rendered, preedit)
-- 修改首選的預编輯文本, 這会作爲内嵌編碼顯示到輸入處
preedit = render_cand(index, first_cand.preedit, cand.text, cand.comment)

-- 存入候選
table.insert(page_cands, cand)
table.insert(page_rendered, preedit)
end
-- 遍歷完一頁候選後, 刷新預編輯文本
if index == page_size then
refresh_preedit()
Expand Down
3 changes: 2 additions & 1 deletion beta/schema/yuhao.custom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ patch:
switches/@0/reset: 1 # [只出常用字, 常用字前置, 全字集原排序]
switches/@1/reset: 0 # [字詞同出, 全碼出單]
switches/@2/reset: 0 # [原始排序, 全碼後置]
switches/@3/reset: 0 # [〇註解, 一重註解, 二重註解, 三重註解]
switches/@3/reset: 0 # [〇註解, 一重註解, 二重註解, 三重註解]
switches/@4/reset: 0 # [普通候選, 嵌入候選]
7 changes: 4 additions & 3 deletions beta/schema/yuhao.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ switches:
- yuhao_chaifen.lv3
states: [〇註解, 一重註解, 二重註解, 三重註解]
reset: 0
- name: embeded_cands
reset: 0
states: [普通候選, 嵌入候選]
# Control+Shift+E
- name: traditionalization
states: [简保持, 简转繁]
reset: 0
Expand All @@ -53,9 +57,6 @@ switches:
reset: 0
states: [繁保持, 繁轉簡]
# Control+Shift+J
- name: embeded_cands
reset: 0
states: [普通, 嵌入候选]
- name: ascii_punct
states: [。,, .,]
reset: 0
Expand Down
3 changes: 2 additions & 1 deletion beta/schema/yuhao_tradition.custom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ patch:
switches/@0/reset: 1 # [只出常用字, 常用字前置, 全字集原排序]
switches/@1/reset: 0 # [字詞同出, 全碼出單]
switches/@2/reset: 0 # [原始排序, 全碼後置]
switches/@3/reset: 0 # [〇註解, 一重註解, 二重註解, 三重註解]
switches/@3/reset: 0 # [〇註解, 一重註解, 二重註解, 三重註解]
switches/@4/reset: 0 # [普通候選, 嵌入候選]
7 changes: 4 additions & 3 deletions beta/schema/yuhao_tradition.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ switches:
- yuhao_chaifen.lv3
states: [〇註解, 一重註解, 二重註解, 三重註解]
reset: 0
- name: embeded_cands
reset: 0
states: [普通候選, 嵌入候選]
# Control+Shift+E
- name: simplification
states: [繁保持, 繁轉簡]
reset: 0
# Control+Shift+J
- name: embeded_cands
reset: 0
states: [普通, 嵌入候選]
- name: ascii_punct
states: [。,, .,]
reset: 0
Expand Down
3 changes: 2 additions & 1 deletion beta/schema/yuhao_tradition_tw.custom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ patch:
switches/@0/reset: 1 # [只出常用字, 常用字前置, 全字集原排序]
switches/@1/reset: 0 # [字詞同出, 全碼出單]
switches/@2/reset: 0 # [原始排序, 全碼後置]
switches/@3/reset: 0 # [〇註解, 一重註解, 二重註解, 三重註解]
switches/@3/reset: 0 # [〇註解, 一重註解, 二重註解, 三重註解]
switches/@4/reset: 0 # [普通候選, 嵌入候選]
7 changes: 4 additions & 3 deletions beta/schema/yuhao_tradition_tw.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ switches:
- yuhao_chaifen.lv3
states: [〇註解, 一重註解, 二重註解, 三重註解]
reset: 0
- name: embeded_cands
reset: 0
states: [普通候選, 嵌入候選]
# Control+Shift+E
- name: simplification
states: [繁保持, 繁轉簡]
reset: 0
# Control+Shift+J
- name: embeded_cands
reset: 0
states: [普通, 嵌入候选]
- name: ascii_punct
states: [。,, .,]
reset: 0
Expand Down

0 comments on commit bbdd268

Please sign in to comment.