-
Notifications
You must be signed in to change notification settings - Fork 617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如何保存英文自造词? #280
Comments
不是的。 没有给英文自造词的功能,缺失的常见单词可以提个 issue。 |
|
rime-easy-en 这个可以,但是在英文方案下。 |
可以参考我的 lua 脚本实现 , 点这里 我的是只给英文单词 左侧加上了空格 |
你好,我下载了这个lua脚本,在方案的custom里加入了
但是重新部署后没有起作用,是还需要其他额外的操作吗? |
不是 processor 哦, 是要加这两个: engine/+:
translators/+:
- lua_translator@engword_autocaps_translator
filters/+:
- lua_filter@engword_autocaps_filter |
成功了!能让首词大写按大写输出真的方便了不少。不过在单词前追加空格的方式跟我的输入有点不符,我给改了。 谢谢分享🙏 |
老哥有没有用过iOS上的仓输入法,我按你的教程设置后重新部署不起作用。 不知道是不是文件读写路径的问题? |
不是很了解ios,不知道什么问题 |
我在PC上也试了一下,也不行,我做的步骤是这样的:
会是什么原因呢,还有哪里没设置好吗? |
|
尝试了你罗列的三种解决方法,均无效。 我感觉还是lua文件的问题,因为我将 |
那只可能是你的librime版本有问题了 |
用了这个安装包的确可行了。再请教一下,我想将用户文件夹设置为我之前使用的路径,但在程序的设定中设定后重新部署并不能生效,是因为这个安装包修改过的关系吗? |
不清楚,建议把原先的复制粘贴进来,这个Rime ice包是绿色,不会影响原先的Rime |
因为用户文件夹不能自定义的原因,我尝试去下载fxliang 最新的构建,重新安装,设定成我自定义的用户文件夹后,又不能出来英文自造词的提示了。 会不会是en_custom.lua 文件里指定的共享数据文件夹路径不同有关系? |
这么一说我就回过神来了 local data_dir = string.gsub(rime_api:get_shared_data_dir(),"\\","\\\\") 因此提到 具体解决办法是,使用以下代码替换原本代码,基本上没有区别,但是能同时在 local user_data_dir = string.gsub(rime_api:get_user_data_dir(),"\\","\\\\")
local shared_data_dir = string.gsub(rime_api:get_shared_data_dir(),"\\","\\\\")
local dict_name = "\\_dic_en\\en_custom.dict.yaml"
local dict_dir = nil -- 初始化变量
if (io.open(user_data_dir..dict_name,"r") )then --如果用户文件夹中找到了dict_name指向的词库文件,则将文件目录赋值给dict_dir
dict_dir = user_data_dir..dict_name
else
if(io.open(shared_data_dir..dict_name,"r"))then --如果用户文件夹中没找到dict_name指向的词库文件,但是程序文件夹中找到了,则将文件目录赋值给dict_dir
dict_dir = shared_data_dir..dict_name
else return
end
end
local function user_dict_exists_(str,dir) --输入字符串和文件路径,在路径指向文件中逐行查找完全对应的字符串,如果已存在则返回true,适用于小狼毫判断词条是否已经存在
local file = io.open(dir, "r")
for line in file:lines() do
if line == str then
file:close()
return true
end
end
file:close()
return false
end
return function (input,seg)
if(input:sub(-2)=="-=" and input~="-=")then --输入末尾必须是-=,并且排除只包含-=的情况。
local inp = input:sub(1,-3):gsub("|"," ")
local unconfirm = inp.."\t"..inp:gsub("[^%a]+",""):lower().."\t100000"
if(user_dict_exists_(unconfirm,dict_dir))then
local file = io.open(dict_dir, "r+")
local content = file:read("*all")
file:close()
content = content:gsub("\n"..unconfirm:gsub("([%%%(%)%[%]%-*+?%.%^])", "%%%1"), "")
file = io.open(dict_dir, "w+")
file:write(content)
file:close()
yield(Candidate("en_custom",seg.start,seg._end,inp," 词已删 再输-=可重添"))
else
local file = io.open(dict_dir,"a")
file:write("\n"..unconfirm):close()
yield(Candidate("en_custom",seg.start,seg._end,inp," 已保存为用户词"))
end
end
end |
总算可以了,在win上现在能正常使用了。 |
不,iOS使用的文件夹路径分隔符与Windows不同,具体地说,Windows使用 local sep = package.config:sub(1, 1)
local user_data_dir = nil
local shared_data_dir = nil
if(sep=="\\")then
user_data_dir = string.gsub(rime_api:get_user_data_dir(),"\\","\\\\")
shared_data_dir = string.gsub(rime_api:get_shared_data_dir(),"\\","\\\\")
elseif(sep=="/")then
user_data_dir = rime_api:get_user_data_dir()
shared_data_dir = rime_api:get_shared_data_dir()
else return
end
local dict_name = sep.."en_dicts"..sep.."en_custom.dict.yaml"
local dict_dir = user_or_shared(dict_name)
local function user_or_shared(file_name)
if (io.open(user_data_dir..file_name,"r") )then --在用户文件夹中找到
return user_data_dir..file_name
else
if(io.open(shared_data_dir..file_name,"r"))then --只在程序文件夹中找到
return shared_data_dir..file_name
else return nil --什么也没找到
end
end
end
local function user_dict_exists_(str,dir) --判断词条str是否已经在文件夹dir中存在
local file = io.open(dir, "r")
for line in file:lines() do
if line == str then
file:close()
return true
end
end
file:close()
return false
end
return function (input,seg)
if(input:sub(-2)=="-=" and input~="-=")then --输入末尾必须是-=,并且排除只包含-=的情况。
local inp = input:sub(1,-3):gsub("|"," ")
local unconfirm = inp.."\t"..inp:gsub("[^%a]+",""):lower().."\t100000"
if(user_dict_exists_(unconfirm,dict_dir))then
local file = io.open(dict_dir, "r+")
local content = file:read("*all")
file:close()
content = content:gsub("\n"..unconfirm:gsub("([%%%(%)%[%]%-*+?%.%^])", "%%%1"), "")
file = io.open(dict_dir, "w+")
file:write(content)
file:close()
yield(Candidate("en_custom",seg.start,seg._end,inp," 词已删 再输-=可重添"))
else
local file = io.open(dict_dir,"a")
file:write("\n"..unconfirm):close()
yield(Candidate("en_custom",seg.start,seg._end,inp," 已保存为用户词"))
end
end
end |
我将之前代码中的斜杠转换后,能在iOS仓输入法上看到保存用户词的提示。但是我打开en_custom.dict.yaml,却没在里面看到增加对应的用户词, 然而这时候我再次输入这个词再用 照理说,如果没有存到词典,就不会检测到输入内容的存在从而提示词已删。 所以,我推测用上面API获取的用户文件夹,也许并不是仓输入法App内的那个Rime文件夹? |
有这么邪门,试试把 yield(Candidate("en_custom",seg.start,seg._end,inp," 已保存为用户词")) 改成 yield(Candidate("en_custom",seg.start,seg._end,dict_dir ," 已保存为用户词")) 这样,他就会显示究竟检索到了哪个文件了。 |
我刚刚还真试过,是类似这样的文件:/private/var/mobile/Containers/Shared/AppGroup/ACC508BD-517F-4EB1-9FAE/InputSchema/Rime,我现在推测可能是出于iOS的安全机制,新词是被被保存在键盘内的对应字典中,而不是App内的,也许键盘无法直接访问、修改App内的文件 |
那就没有办法了 |
输入词库中不存在的英文单词后,都是用回车键上屏的,这个如何记录在词典中以便下次复用呢?
方案里中有
请问上面的
enable_sentence
和enable_user_dict
是用来做这件事的吗?The text was updated successfully, but these errors were encountered: