Skip to content
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

使用更多rime-melt的lua? #101

Closed
hoofcushion opened this issue Mar 13, 2023 · 14 comments
Closed

使用更多rime-melt的lua? #101

hoofcushion opened this issue Mar 13, 2023 · 14 comments

Comments

@hoofcushion
Copy link
Contributor

https:/tumuyan/rime-melt/blob/master/lua/melt.lua

  • 1. 大写字母开头 ,将转化英文词条

image
image
image

  • 1.1 关于词条转化范围的改进

image

  • 2.有候选时以--结尾,将你的输入码写入指定词库,也就是英文造词

image
image

@hoofcushion
Copy link
Contributor Author

#35 可以增加英文造词了

@iDvel
Copy link
Owner

iDvel commented Mar 13, 2023

第一个功能感觉没必要,大写按回车上屏就行了。

英文造词的功能,path = getCurrentDir() .. "melt_eng_custom.dict.yaml" 这一行似乎获取不到,我改成绝对路径是可以的。
这个功能其实就是写入一个已经挂载了的词库文件,之后还是需要重新部署才可以打出来。

需要的可以自行添加这个功能:
(改成两个下划线了)

function custom_en(input, seg, env)
    if (string.sub(input, -1) == "_") then
        local inpu = string.gsub(input, "[_]+$", "")
        if (string.len(inpu) > 1 and string.sub(input, 1, 1) ~= "_") then
            if (string.sub(input, -2) == "__") then
                path = "/Users/xxx/Library/Rime/en_dicts/custom_en.dict.yaml"
                local file = io.open(path, "a")
                file:write("\n" .. inpu .. "\t" .. inpu)
                file:close()
                yield(Candidate("pin", seg.start, seg._end, inpu, " 已保存"))
            else
                yield(Candidate("pin", seg.start, seg._end, inpu, " -保存"))
            end
        end
    end
end

启用:
修改上面脚本中 path 变量为自己机器中的实际路径。
将脚本放进 rime.lua 中。
创建 path 中指定的那个词库文件,如示例中,在 en_dicts 下创建 custom_en.dict.yaml
在这个词库文件中写上这些前缀:

---
name: custom_en
version: "1"
sort: by_weight
...

将这个词库挂载,在 melt_eng.dict.yaml 增加一行 - en_dicts/custom_en
方案中启用:

engine:
  translators:
    - lua_translator@custom_en # 在 engine/translators 下增加这一行

使用方法:
输入一个不存在的单词,如 aabbcc,再输入两个下划线(Shift + 减号)。
看到出现「已保存」提示,按空格上屏,就自动写入 custom_en.dict.yaml 了。
图片
重新部署后,下次就可以直接打出来了。

@iDvel iDvel closed this as not planned Won't fix, can't repro, duplicate, stale Mar 13, 2023
@iDvel
Copy link
Owner

iDvel commented Mar 30, 2023

engine: translators: - lua_translator@custom_en # 在 engine/translators 下增加这一行

这个是加在那个文件里?

你用的方案,全拼就是 rime_ice.schema.yaml,双拼就是 double_pinyin.schema.yamldouble_pinyin_flypy.schema.yaml

@zhjh0521
Copy link

engine: translators: - lua_translator@custom_en # 在 engine/translators 下增加这一行
这个是加在那个文件里?

你用的方案,全拼就是 rime_ice.schema.yaml,双拼就是 double_pinyin.schema.yamldouble_pinyin_flypy.schema.yaml

谢谢,刚发了消息我自己就找到了

@zhjh0521
Copy link

zhjh0521 commented May 5, 2023

custom_en

Lua重构了以后,custom_en这个function建议放在哪个lua文件里?

@iDvel
Copy link
Owner

iDvel commented May 5, 2023

Lua重构了以后,custom_en这个function建议放在哪个lua文件里?

和以前其实差不多。

  • 放到 lua/ 文件夹里,取名为 custom_en.lua
  • function 前面加个 local
  • 文件结尾加个 return custom_en
  • - lua_translator@custom_en 改成 - lua_translator@*custom_en(多一个星号)

@zhjh0521
Copy link

zhjh0521 commented May 5, 2023

Lua重构了以后,custom_en这个function建议放在哪个lua文件里?

和以前其实差不多。

  • 放到 lua/ 文件夹里,取名为 custom_en.lua
  • function 前面加个 local
  • 文件结尾加个 return custom_en
  • - lua_translator@custom_en 改成 - lua_translator@*custom_en(多一个星号)

按照你说得,不工作啊。新建了一个custom_en.lua文件,然后在rime_ice.schema.yaml里加上了- lua_translator@*custom_en

@iDvel
Copy link
Owner

iDvel commented May 5, 2023

小狼毫更新一下 librime #133

@zhjh0521
Copy link

zhjh0521 commented May 5, 2023

Lua重构了以后,custom_en这个function建议放在哪个lua文件里?

和以前其实差不多。

  • 放到 lua/ 文件夹里,取名为 custom_en.lua
  • function 前面加个 local
  • 文件结尾加个 return custom_en
  • - lua_translator@custom_en 改成 - lua_translator@*custom_en(多一个星号)

大佬,你有试验过重构后这个方法工作吗?我现在又改回去了

@iDvel
Copy link
Owner

iDvel commented May 5, 2023

试了,可以。

local function custom_en(input, seg, env)
    if (string.sub(input, -1) == "_") then
        local inpu = string.gsub(input, "[_]+$", "")
        if (string.len(inpu) > 1 and string.sub(input, 1, 1) ~= "_") then
            if (string.sub(input, -2) == "__") then
                path = "/Users/dvel/Library/Rime/en_dicts/custom_en.dict.yaml"
                local file = io.open(path, "a")
                file:write("\n" .. inpu .. "\t" .. inpu)
                file:close()
                yield(Candidate("pin", seg.start, seg._end, inpu, " 已保存"))
            else
                yield(Candidate("pin", seg.start, seg._end, inpu, " -保存"))
            end
        end
    end
end

return custom_en
    - lua_translator@*custom_en
2023-05-05-000429.mp4

@zhjh0521
Copy link

zhjh0521 commented May 5, 2023

试了,可以。

local function custom_en(input, seg, env)
    if (string.sub(input, -1) == "_") then
        local inpu = string.gsub(input, "[_]+$", "")
        if (string.len(inpu) > 1 and string.sub(input, 1, 1) ~= "_") then
            if (string.sub(input, -2) == "__") then
                path = "/Users/dvel/Library/Rime/en_dicts/custom_en.dict.yaml"
                local file = io.open(path, "a")
                file:write("\n" .. inpu .. "\t" .. inpu)
                file:close()
                yield(Candidate("pin", seg.start, seg._end, inpu, " 已保存"))
            else
                yield(Candidate("pin", seg.start, seg._end, inpu, " -保存"))
            end
        end
    end
end

return custom_en
    - lua_translator@*custom_en

2023-05-05-000429.mp4

咋这么奇怪啊,我的设置跟你的一模一样。但当我输入“aa”,然后(Shift + 一个减号)就直接上屏了,变成“啊啊——”

是不是还有那个地方没设置?

@iDvel
Copy link
Owner

iDvel commented May 5, 2023

得让下划线不上屏,不然怎么用下划线。
default.yaml 里解开 underscore: "^[A-Za-z]+_.*" 的注释。
或者 default.custom.yaml 补丁:

patch:
  recognizer/patterns/+:
    underscore: "^[A-Za-z]+_.*"

@zhjh0521
Copy link

zhjh0521 commented May 5, 2023

得让下划线不上屏,不然怎么用下划线。 default.yaml 里解开 underscore: "^[A-Za-z]+_.*" 的注释。 或者 default.custom.yaml 补丁:

patch:
  recognizer/patterns/+:
    underscore: "^[A-Za-z]+_.*"

我把default.yaml 里解开 underscore: "^[A-Za-z]+_.*" 的注释。就能工作了

但我看了之前的配置,以前的default.yaml 里下划线也是被注释掉的,我也没有搞过default.custom.yaml,奇怪了。我再研究研究,但谢谢,已经工作了

@zhjh0521
Copy link

zhjh0521 commented May 5, 2023

找到原因了,在之前的版本里,在rime_ice.schema.yaml里面是把下划线解开的。新版本里没有了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants