Created
July 9, 2012 12:23
-
-
Save lotem/3076166 to your computer and use it in GitHub Desktop.
自動識別西文及數字組成的用戶名
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# default.custom.yaml | |
# 全局範圍識別輸入串爲 rime + 任意數字序列,以及形如 rimeime-1.2.3 的常用西文短語 | |
# 也可將本組 patch 寫入 <輸入方案ID>.custom.yaml 使這組規則僅在一款輸入方案中有效 | |
# | |
# 第一例,輸入 rime 之後,再輸入任意一個數字,則立即識別爲西文輸入 | |
# 再加上 default.yaml 原有的 email 規則,識別包含 @ 字符的郵箱,於是可以一氣呵成 rime123@company.com | |
# 第二例,輸入到 rimeime 時,立即識別爲西文輸入,並可跟隨任意位數字及指定的符號 | |
patch: | |
recognizer/patterns/rime123: "^rime[0-9]+$" | |
recognizer/patterns/rimeime: "^rimeime[-_.0-9]*$" |
我试了一下, 两个分号上屏我也没搞定, 应该有一个lua确认函数, 我现在不知道是啥, 不过输入分号, 目前可以输入一个分号, 然后使用空格或者回车来解决.
连续多个分号, 会有问题.
这里问题的核心是, 不能触发候选框, 不然分号的语义就成为了第二选词键而不是分号内容本身.
所以必须在lua函数中处理. 同时第二个分号后面的分号必须被所有模式组捕获. 理想情况是这样的.
starts_with_semicolon: ';[;A-Za-z_<>\[\]\-+=~@.#?!%^&$*()\\]*$'
function append_original_filter(input, env)
local envengine = env.engine
local composition = envengine.context.composition
local segmentation = composition:toSegmentation()
local schema = envengine.schema
if(not composition:empty()) then
local seg = composition:back()
if schema.schema_id == "easy_en" then
yield(Candidate("string", seg.start, seg._end, segmentation.input, ""))
elseif segmentation.input:sub(1, 1) == ";" and segmentation.input:len() > 1 then
if segmentation.input:sub(2, 2) == ";" then
envengine:commit_text(";")
return
else
yield(Candidate("space", seg.start, seg._end, string.sub(segmentation.input, 2), ""))
end
-- yield(Candidate("space", seg.start, seg._end, string.sub(segmentation.input, 2), ""))
end
end
for cand in input:iter() do
yield(cand)
end
end
但是我试了一个, commit_text这个函数应该不是最终上屏键, 这样做的话, 输入序列会有一个分号被append_original_filter这个处理器后面的处理器处理. 于是出现输入冗余.
目前暂时只能用.
starts_with_semicolon: ';[A-Za-z_<>\[\]\-+=~@.#?!%^&$*()\\]*$'
同时
function append_original_filter(input, env)
local envengine = env.engine
local composition = envengine.context.composition
local segmentation = composition:toSegmentation()
local schema = envengine.schema
if(not composition:empty()) then
local seg = composition:back()
if schema.schema_id == "easy_en" then
yield(Candidate("string", seg.start, seg._end, segmentation.input, ""))
elseif segmentation.input:sub(1, 1) == ";" and segmentation.input:len() > 1 then
yield(Candidate("space", seg.start, seg._end, string.sub(segmentation.input, 2), ""))
end
end
for cand in input:iter() do
yield(cand)
end
end
来搞. 如果要输入分号 就使用 分号+空格或分号加回车来输入
好的, 你这个(同时存在半角和全角)确实无法做到双分号上屏, 因为这里有一个二元语义, 逻辑上冲突了, 第二个分号到底是要上屏备选2, 全角分号. 还是第二个分号只想做为一个顶格键直接上屏.
感谢反馈, 这样我也修复了一个自己使用的bug.
好的, 你这个(同时存在半角和全角)确实无法做到双分号上屏, 因为这里有一个二元语义, 逻辑上冲突了, 第二个分号到底是要上屏备选2, 全角分号. 还是第二个分号只想做为一个顶格键直接上屏.
是用来上屏中文(全角)分号的,我没有用冒号和分号作为候选上屏的。用的以前极点的逻辑,1个分号临时英文,2个分号输入分号,有时输入中文时确实需要分号。
搞定了. 对我这边是完美了. 不过不知道你适用不适用,
放出来供其他朋友参考.
参见上面的考虑.
最后的模式组
starts_with_semicolon: ';[;A-Za-z_<>\[\]\-+=~@.#?!%^&$*()\\]*$'
最后的函数
function append_original_filter(input, env)
local envengine = env.engine
local envcontext = envengine.context
local composition = envcontext.composition
local segmentation = composition:toSegmentation()
local schema = envengine.schema
if(not composition:empty()) then
local seg = composition:back()
if schema.schema_id == "easy_en" then
yield(Candidate("string", seg.start, seg._end, segmentation.input, ""))
elseif segmentation.input:sub(1, 1) == ";" and segmentation.input:len() > 1 then
if segmentation.input:sub(2, 2) == ";" then
envengine:commit_text(";")
envcontext:clear()
return
else
yield(Candidate("space", seg.start, seg._end, string.sub(segmentation.input, 2), ""))
end
end
end
for cand in input:iter() do
yield(cand)
end
end
这样就可以使用分号上屏分号了, 空格, 回车也同样上屏分号.
稍等,我今晚回去看看On Jan 22, 2024 4:59 PM, redleafnew ***@***.***> ***@***.*** commented on this gist.我的出不来,按分号就是上屏个分号。没有临时拼音出现了,改了rime.rua和方案中的image.png (view on web)—Reply to this email directly, view it on GitHub or unsubscribe.You are receiving this email because you commented on the thread.Triage notifications on the go with GitHub Mobile for iOS or Android.
作者大大,麻烦整理一下最终版?从最开始的评论依次跟着评论调整下来,效果还是差强人意。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
倒是只出现一个了,但按两个没有上屏一个,而且也没有原来eassy_en中的词了。