forked from hchunhui/librime-lua
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: shewer <[email protected]>
- Loading branch information
Showing
3 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#! /usr/bin/env lua | ||
-- | ||
-- script_translator.lua | ||
-- Copyright (C) 2023 Shewer Lu <[email protected]> | ||
-- | ||
-- Distributed under terms of the MIT license. | ||
-- | ||
|
||
--[[ | ||
''' custom.yaml' | ||
patch: | ||
engine/translators/+: | ||
- lua_translator@*table_translator@translator | ||
- lua_translator@*script_translator@cangjie | ||
```` | ||
------- methods return | ||
env.tran:start_session false function() | ||
env.tran:finish_session false function() | ||
env.tran:discard_session false function() | ||
env.tran:query false function(inp, seg) | ||
env.tran:memorize false function(commit_entrys) | ||
env.tran:update_entry false function(entry, state, prefix_str) | ||
------- vars_set | ||
env.tran.spelling_hints = int >0 | ||
env.tran.initial_quality = double | ||
env.tran.contextual_suggestions = boolean | ||
env.tran.enable_completion = boolean | ||
env.tran.always_show_comments = boolean | ||
env.tran.strict_spelling = boolean | ||
env.tran.max_homophones = int | ||
env.tran.memorize_callback = function(self, commit_entry) | ||
env.tran.enable_correction = boolean | ||
env.tran.tag = string | ||
env.tran.delimiters = string | ||
------- vars_get | ||
res = env.tran.spelling_hints 0 number | ||
res = env.tran.initial_quality 0.0 number | ||
res = env.tran.contextual_suggestions false boolean | ||
res = env.tran.enable_completion true boolean | ||
res = env.tran.always_show_comments false boolean | ||
res = env.tran.strict_spelling false boolean | ||
res = env.tran.max_homophones 1 number | ||
res = env.tran.memorize_callback function: 0x557a0c15ef40 function | ||
res = env.tran.enable_correction false boolean | ||
res = env.tran.tag abc string | ||
res = env.tran.delimiters ' string | ||
--]] | ||
local M={} | ||
local function simple_callback(self, commits) | ||
local context = self.engine.context | ||
if true then | ||
return self:memorize(commits) | ||
end | ||
end | ||
local function callback(self, commits) -- self : env.tran commits : list | ||
local context = self.engine.context | ||
for i, entry in ipairs(commits:get()) do | ||
self:update_entry(dictentry,0,"") -- do nothing to userdict | ||
-- self:update_entry(dictentry,1,"") -- update entry to userdict | ||
-- self:update_entry(dictentry,-1,"") -- delete entry to userdict | ||
end | ||
end | ||
function M.init(env) | ||
env.tran = Component.TableTranslator(env.engine, env.name_space, "table") | ||
env.tran.memorize_callback = simple_callback | ||
end | ||
|
||
function M.fini(env) | ||
end | ||
|
||
function M.func(inp, seg, env) | ||
local t = env.tran:query(inp,seg) | ||
if not t then return end | ||
for cand in t:iter() do | ||
yield(cand) | ||
end | ||
end | ||
|
||
return M |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#! /usr/bin/env lua | ||
-- | ||
-- table_translator.lua | ||
-- Copyright (C) 2023 Shewer Lu <[email protected]> | ||
-- | ||
-- Distributed under terms of the MIT license. | ||
-- | ||
--[[ | ||
-- | ||
''' custom.yaml' | ||
patch: | ||
engine/translators/+: | ||
- lua_translator@*table_translator@translator | ||
- lua_translator@*script_translator@cangjie | ||
```` | ||
------- methods | ||
env.tran:finish_session bool function() | ||
env.tran:start_session bool function() | ||
env.tran:discard_session bool function() | ||
env.tran:query translation function(inp, seg) | ||
env.tran:memorize bool function(commit_entrys) | ||
env.tran:update_entry bool function(entry) | ||
------- vars_set 設定值 | ||
env.tran.max_homophones = number | ||
env.tran.spelling_hints = number | ||
env.tran.enable_correction = boolean | ||
env.tran.memorize_callback = function(self, commits) | ||
env.tran.enable_completion = false boolean | ||
env.tran.delimiters = false string | ||
env.tran.strict_spelling = boolean | ||
env.tran.contextual_suggestions = boolean | ||
env.tran.initial_quality = double | ||
env.tran.always_show_comments = boolean | ||
env.tran.tag = string | ||
------- vars_get 取值 | ||
res = env.tran.max_homophones 1 number | ||
res = env.tran.spelling_hints 0 number | ||
res = env.tran.enable_correction false boolean | ||
res = env.tran.memorize_callback function: 0x562c732947e0 function | ||
res = env.tran.enable_completion true boolean | ||
res = env.tran.delimiters ' string | ||
res = env.tran.strict_spelling false boolean | ||
res = env.tran.contextual_suggestions false boolean | ||
res = env.tran.initial_quality 0.0 number | ||
res = env.tran.always_show_comments false boolean | ||
res = env.tran.tag cangjie string | ||
--]] | ||
|
||
local M={} | ||
local function simple_callback(self, commits) | ||
local context = self.engine.context | ||
if true then | ||
return self:memorize(commits) | ||
end | ||
end | ||
local function callback(self, commits) -- self : env.tran commits : list | ||
local context = self.engine.context | ||
for i, entry in ipairs(commits:get()) do | ||
self:update_entry(dictentry,0,"") -- do nothing to userdict | ||
-- self:update_entry(dictentry,1,"") -- update entry to userdict | ||
-- self:update_entry(dictentry,-1,"") -- delete entry to userdict | ||
end | ||
end | ||
function M.init(env) | ||
env.tran = Component.TableTranslator(env.engine, env.name_space, "table") | ||
env.tran.memorize_callback = simple_callback | ||
end | ||
|
||
function M.fini(env) | ||
end | ||
|
||
function M.func(inp, seg, env) | ||
local t = env.tran:query(inp,seg) | ||
if not t then return end | ||
for cand in t:iter() do | ||
yield(cand) | ||
end | ||
end | ||
|
||
return M |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
patch: | ||
engine/translators/+: | ||
- lua_translator@*table_translator@translator | ||
- lua_translator@*script_translator@cangjie | ||
|
||
|