feat: 降低部分英语单词在候选项的位置 close #61
This commit is contained in:
parent
a3f7d27b1c
commit
0d4f1e3727
@ -9,6 +9,7 @@
|
|||||||
- 简体 | 全拼 | 双拼
|
- 简体 | 全拼 | 双拼
|
||||||
- 主要功能
|
- 主要功能
|
||||||
- [melt_eng](https://github.com/tumuyan/rime-melt) 英文输入
|
- [melt_eng](https://github.com/tumuyan/rime-melt) 英文输入
|
||||||
|
- [优化英文输入体验](https://dvel.me/posts/make-rime-en-better/)
|
||||||
- [两分输入法](http://cheonhyeong.com/Simplified/download.html) 拼字
|
- [两分输入法](http://cheonhyeong.com/Simplified/download.html) 拼字
|
||||||
- 简繁切换
|
- 简繁切换
|
||||||
- 日期、时间、星期
|
- 日期、时间、星期
|
||||||
|
@ -79,11 +79,11 @@ engine:
|
|||||||
- uniquifier # 去重
|
- uniquifier # 去重
|
||||||
|
|
||||||
|
|
||||||
# 限制码长,默认 100。(最多能输入的字符个数)
|
# Lua 配置: 限制码长,默认 100。(最多能输入的字符个数)
|
||||||
code_length_limit_processor: 100
|
code_length_limit_processor: 100
|
||||||
|
|
||||||
|
|
||||||
# 日期、时间、星期、ISO 8601、时间戳的触发关键字
|
# Lua 配置: 日期、时间、星期、ISO 8601、时间戳的触发关键字
|
||||||
date_translator:
|
date_translator:
|
||||||
date: date # 日期: 2022-11-29
|
date: date # 日期: 2022-11-29
|
||||||
time: time # 时间: 18:13
|
time: time # 时间: 18:13
|
||||||
|
@ -79,11 +79,11 @@ engine:
|
|||||||
- uniquifier # 去重
|
- uniquifier # 去重
|
||||||
|
|
||||||
|
|
||||||
# 限制码长,默认 100。(最多能输入的字符个数)
|
# Lua 配置: 限制码长,默认 100。(最多能输入的字符个数)
|
||||||
code_length_limit_processor: 100
|
code_length_limit_processor: 100
|
||||||
|
|
||||||
|
|
||||||
# 日期、时间、星期、ISO 8601、时间戳的触发关键字
|
# Lua 配置: 日期、时间、星期、ISO 8601、时间戳的触发关键字
|
||||||
date_translator:
|
date_translator:
|
||||||
date: date # 日期: 2022-11-29
|
date: date # 日期: 2022-11-29
|
||||||
time: time # 时间: 18:13
|
time: time # 时间: 18:13
|
||||||
|
46
rime.lua
46
rime.lua
@ -151,8 +151,8 @@ end
|
|||||||
function long_word_filter(input, env)
|
function long_word_filter(input, env)
|
||||||
-- 提升 count 个词语,插入到第 idx 个位置,默认 2、4。
|
-- 提升 count 个词语,插入到第 idx 个位置,默认 2、4。
|
||||||
local config = env.engine.schema.config
|
local config = env.engine.schema.config
|
||||||
local count = config:get_string(env.name_space .. "/count") or 2
|
local count = config:get_int(env.name_space .. "/count") or 2
|
||||||
local idx = config:get_string(env.name_space .. "/idx") or 4
|
local idx = config:get_int(env.name_space .. "/idx") or 4
|
||||||
|
|
||||||
local l = {}
|
local l = {}
|
||||||
local firstWordLength = 0 -- 记录第一个候选词的长度,提前的候选词至少要比第一个候选词长
|
local firstWordLength = 0 -- 记录第一个候选词的长度,提前的候选词至少要比第一个候选词长
|
||||||
@ -162,7 +162,7 @@ function long_word_filter(input, env)
|
|||||||
local i = 1
|
local i = 1
|
||||||
for cand in input:iter() do
|
for cand in input:iter() do
|
||||||
leng = utf8.len(cand.text)
|
leng = utf8.len(cand.text)
|
||||||
if (firstWordLength < 1 or i < tonumber(idx)) then
|
if (firstWordLength < 1 or i < idx) then
|
||||||
i = i + 1
|
i = i + 1
|
||||||
firstWordLength = leng
|
firstWordLength = leng
|
||||||
yield(cand)
|
yield(cand)
|
||||||
@ -177,7 +177,7 @@ function long_word_filter(input, env)
|
|||||||
-- end
|
-- end
|
||||||
-- 换了个正则,否则中英混输的也会被提升
|
-- 换了个正则,否则中英混输的也会被提升
|
||||||
-- elseif ((leng > firstWordLength) and (s2 < count)) and (string.find(cand.text, "^[%w%p%s]+$")==nil) then
|
-- elseif ((leng > firstWordLength) and (s2 < count)) and (string.find(cand.text, "^[%w%p%s]+$")==nil) then
|
||||||
elseif ((leng > firstWordLength) and (s2 < tonumber(count))) and (string.find(cand.text, "[%w%p%s]+") == nil) then
|
elseif ((leng > firstWordLength) and (s2 < count)) and (string.find(cand.text, "[%w%p%s]+") == nil) then
|
||||||
yield(cand)
|
yield(cand)
|
||||||
s2 = s2 + 1
|
s2 = s2 + 1
|
||||||
else
|
else
|
||||||
@ -189,6 +189,35 @@ function long_word_filter(input, env)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
|
-- 降低部分英语单词在候选项的位置
|
||||||
|
-- https://dvel.me/posts/make-rime-en-better/#短单词置顶的问题
|
||||||
|
-- 感谢大佬 @[Shewer Lu](https://github.com/shewer) 指点
|
||||||
|
function reduce_english_filter(input, env)
|
||||||
|
local config = env.engine.schema.config
|
||||||
|
local idx = config:get_int(env.name_space .. "/idx") -- 要插入的位置
|
||||||
|
local words = {} -- 要过滤的词
|
||||||
|
local list = config:get_list(env.name_space .. "/words")
|
||||||
|
for i = 0, list.size - 1 do
|
||||||
|
table.insert(words, list:get_value_at(i).value)
|
||||||
|
end
|
||||||
|
|
||||||
|
local l = {}
|
||||||
|
local code = env.engine.context.input -- 当前编码
|
||||||
|
for cand in input:iter() do
|
||||||
|
table.insert(l, cand)
|
||||||
|
end
|
||||||
|
for _, word in ipairs(words) do
|
||||||
|
if (code == word) then
|
||||||
|
first_element = table.remove(l, 1)
|
||||||
|
table.insert(l, 2, first_element)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for _, cand in ipairs(l) do
|
||||||
|
yield(cand)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-------------------------------------------------------------
|
||||||
-- v 模式,单个字符优先
|
-- v 模式,单个字符优先
|
||||||
-- 因为设置了英文翻译器的 initial_quality 大于 1,导致输入「va」时,候选项是「van vain …… ā á ǎ à」
|
-- 因为设置了英文翻译器的 initial_quality 大于 1,导致输入「va」时,候选项是「van vain …… ā á ǎ à」
|
||||||
-- 把候选项应改为「ā á ǎ à …… van vain」,让单个字符的排在前面
|
-- 把候选项应改为「ā á ǎ à …… van vain」,让单个字符的排在前面
|
||||||
@ -196,7 +225,7 @@ function v_filter(input, env)
|
|||||||
local code = env.engine.context.input -- 当前编码
|
local code = env.engine.context.input -- 当前编码
|
||||||
local l = {}
|
local l = {}
|
||||||
for cand in input:iter() do
|
for cand in input:iter() do
|
||||||
-- 特殊情况处理
|
-- 特殊情况处理
|
||||||
if (cand.text == "Vs.") then
|
if (cand.text == "Vs.") then
|
||||||
yield(cand)
|
yield(cand)
|
||||||
end
|
end
|
||||||
@ -205,6 +234,7 @@ function v_filter(input, env)
|
|||||||
for _, v in ipairs(arr) do
|
for _, v in ipairs(arr) do
|
||||||
if (v == cand.text and string.len(code) == 2 and string.find(code, "v") == 1) then
|
if (v == cand.text and string.len(code) == 2 and string.find(code, "v") == 1) then
|
||||||
yield(cand)
|
yield(cand)
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- 以 v 开头、2 个长度的编码、候选项为单个字符的,提到前面来。
|
-- 以 v 开头、2 个长度的编码、候选项为单个字符的,提到前面来。
|
||||||
@ -214,7 +244,7 @@ function v_filter(input, env)
|
|||||||
table.insert(l, cand)
|
table.insert(l, cand)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i, cand in ipairs(l) do
|
for _, cand in ipairs(l) do
|
||||||
yield(cand)
|
yield(cand)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -237,9 +267,9 @@ function code_length_limit_processor(key, env)
|
|||||||
local ctx = env.engine.context
|
local ctx = env.engine.context
|
||||||
local config = env.engine.schema.config
|
local config = env.engine.schema.config
|
||||||
-- 限制
|
-- 限制
|
||||||
local length_limit = config:get_string(env.name_space) or 100
|
local length_limit = config:get_int(env.name_space) or 100
|
||||||
if (length_limit ~= nil) then
|
if (length_limit ~= nil) then
|
||||||
if (string.len(ctx.input) > tonumber(length_limit)) then
|
if (string.len(ctx.input) > length_limit) then
|
||||||
-- ctx:clear()
|
-- ctx:clear()
|
||||||
ctx:pop_input(1) -- 删除输入框中最后个编码字符
|
ctx:pop_input(1) -- 删除输入框中最后个编码字符
|
||||||
return 1
|
return 1
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
schema:
|
schema:
|
||||||
schema_id: rime_ice
|
schema_id: rime_ice
|
||||||
name: 雾凇拼音
|
name: 雾凇拼音
|
||||||
version: "1.2.4"
|
version: "1.3.0"
|
||||||
author:
|
author:
|
||||||
- Dvel
|
- Dvel
|
||||||
description: |
|
description: |
|
||||||
@ -65,18 +65,19 @@ engine:
|
|||||||
- reverse_lookup_translator@liangfen # 反查,两分拼字
|
- reverse_lookup_translator@liangfen # 反查,两分拼字
|
||||||
- lua_translator@unicode # Unicode
|
- lua_translator@unicode # Unicode
|
||||||
filters:
|
filters:
|
||||||
- lua_filter@long_word_filter # 长词优先
|
- lua_filter@long_word_filter # 长词优先
|
||||||
- simplifier@emoji # Emoji
|
- simplifier@emoji # Emoji
|
||||||
- simplifier@traditionalize # 简繁切换
|
- simplifier@traditionalize # 简繁切换
|
||||||
- lua_filter@v_filter # v 模式 symbols 优先(否则是英文优先)
|
- lua_filter@v_filter # v 模式 symbols 优先(否则是英文优先)
|
||||||
- uniquifier # 去重
|
- lua_filter@reduce_english_filter # 降低部分英语单词在候选项的位置
|
||||||
|
- uniquifier # 去重
|
||||||
|
|
||||||
|
|
||||||
# 限制码长,默认 100。(最多能输入的字符个数)
|
# Lua 配置: 限制码长,默认 100。(最多能输入的字符个数)
|
||||||
code_length_limit_processor: 100
|
code_length_limit_processor: 100
|
||||||
|
|
||||||
|
|
||||||
# 日期、时间、星期、ISO 8601、时间戳的触发关键字
|
# Lua 配置: 日期、时间、星期、ISO 8601、时间戳的触发关键字
|
||||||
date_translator:
|
date_translator:
|
||||||
date: rq # 日期: 2022-11-29
|
date: rq # 日期: 2022-11-29
|
||||||
time: sj # 时间: 18:13
|
time: sj # 时间: 18:13
|
||||||
@ -85,13 +86,26 @@ date_translator:
|
|||||||
timestamp: ts # 时间戳: 1669716794
|
timestamp: ts # 时间戳: 1669716794
|
||||||
|
|
||||||
|
|
||||||
# 长词优先,提升 count 个词语,插入到第 idx 个位置。
|
# Lua 配置: 长词优先,提升 count 个词语,插入到第 idx 个位置。
|
||||||
# 示例:将 2 个词插入到第 4、5 个候选项,输入 jie 得到「1接 2解 3姐 4饥饿 5极恶」
|
# 示例:将 2 个词插入到第 4、5 个候选项,输入 jie 得到「1接 2解 3姐 4饥饿 5极恶」
|
||||||
long_word_filter:
|
long_word_filter:
|
||||||
count: 2
|
count: 2
|
||||||
idx: 4
|
idx: 4
|
||||||
|
|
||||||
|
|
||||||
|
# Lua 配置: 降低部分英语单词在候选项的位置
|
||||||
|
# 详细介绍 https://dvel.me/posts/make-rime-en-better/#短单词置顶的问题
|
||||||
|
# 正常情况: 输入 rug 得到 「1.rug 2.如果 …… 」
|
||||||
|
# 降低之后: 输入 rug 得到 「1.如果 2.rug …… 」
|
||||||
|
reduce_english_filter:
|
||||||
|
idx: 2 # 降低到第 idx 个位置
|
||||||
|
words: # 要降低的单词,匹配的是输入码,即全小写。
|
||||||
|
- rug
|
||||||
|
- bus
|
||||||
|
- ship
|
||||||
|
# words: [rug, bus, ship] # 这么写也行
|
||||||
|
|
||||||
|
|
||||||
# 从 default 继承快捷键
|
# 从 default 继承快捷键
|
||||||
key_binder:
|
key_binder:
|
||||||
import_preset: default
|
import_preset: default
|
||||||
|
Loading…
x
Reference in New Issue
Block a user