-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
1 deletion.
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,62 @@ | ||
local Module = {} | ||
|
||
function Module.init(env) | ||
env.enable_quick_code_hint = env.engine.schema.config:get_bool("moran/enable_quick_code_hint") | ||
log.error("moran_quick_code_hint: init " .. tostring(env.enable_quick_code_hint)) | ||
if env.enable_quick_code_hint then | ||
-- The user might have changed it. | ||
local dict = env.engine.schema.config:get_string("fixed/dictionary") | ||
log.error("moran_quick_code_hint: using dict" .. dict) | ||
env.quick_code_hint_reverse = ReverseLookup(dict) | ||
log.error("moran_quick_code_hint: enabled") | ||
else | ||
env.quick_code_hint_reverse = nil | ||
log.error("moran_quick_code_hint: disabled") | ||
end | ||
|
||
env.quick_code_indicator = env.engine.schema.config:get_string("moran/quick_code_indicator") | ||
env.enable_aux_hint = env.engine.schema.config:get_bool("moran/enable_aux_hint") | ||
end | ||
|
||
function Module.fini(env) | ||
env.quick_code_hint_reverse = nil | ||
end | ||
|
||
function Module.func(translation, env) | ||
if (not env.enable_quick_code_hint) or env.quick_code_hint_reverse == nil then | ||
for cand in translation:iter() do | ||
yield(cand) | ||
end | ||
return | ||
end | ||
|
||
-- Look up if the "geniune" candidate is already in the qc dict | ||
local indicator = env.quick_code_indicator | ||
if env.enable_aux_hint and indicator == "" then | ||
indicator = "⚡" | ||
end | ||
for cand in translation:iter() do | ||
local gcand = cand:get_genuine() | ||
local word = gcand.text | ||
local all_codes = env.quick_code_hint_reverse:lookup(word) | ||
if all_codes then | ||
local codes = {} | ||
for code in all_codes:gmatch("%S+") do | ||
if #code < 4 then | ||
table.insert(codes, code) | ||
end | ||
end | ||
if #codes > 0 then | ||
-- do not show two indicators | ||
if gcand.comment == indicator then | ||
gcand.comment = gcand.comment .. table.concat(codes, " ") | ||
else | ||
gcand.comment = gcand.comment .. indicator .. table.concat(codes, " ") | ||
end | ||
end | ||
end | ||
yield(cand) | ||
end | ||
end | ||
|
||
return Module |
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
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