hchunhui / librime-lua

Extending RIME with Lua scripts
BSD 3-Clause "New" or "Revised" License
310 stars 43 forks source link

How to get the candidate's word freq / word weight in a filter? #132

Open edward-martyr opened 3 years ago

edward-martyr commented 3 years ago

I read https://github.com/hchunhui/librime-lua/pull/80, but was still unsure of how to associate this with a candidate in lua script.

Desired result:

I want to move the most frequent single characters ahead of less used words. For example, when I input gaoyixie, I would like

高一些 # first candidate
高一 # frequent words
高醫
高 # move frequent single char forward
搞
稿
告
... some more frequent single char
高邑 # less used words, not needed for most of the time
高義
高逸
高誼

Instead of

高一些
高一
高邑
高義
高逸
高誼
... many more less used words
搞
稿
告

when what I really want to input is 搞一些, this hampers the input a lot.

I'm very new to lua, but I reckon it should be the best way to implement this desired result. Thanks in advance, @TsinamLeung @hchunhui

TsinamLeung commented 3 years ago

in these samples, I suggest you to edit your dictionary to lower the uncommon word or use lua_filter to advance the frequent word.

txxia commented 3 years ago

A debug filter I have in hand should help you get started:

local function filter(input, env)
    for cand in input:iter() do
        cand:get_genuine().comment = string.format("%s | %2.2f | %d | %s", cand.type, cand.quality * 100, cand.start, cand.comment)
        yield(cand)
    end
end