hchunhui / librime-lua

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

请问能否在用户词典中彻底删除词条 而不只是标记为已删除? #314

Closed Tsinswreng closed 3 months ago

Tsinswreng commented 4 months ago

我想要删除用户词典中长度>4的条目。我尝试了以下做法:

local function deleteLong()
    mem:user_lookup('', true)
    for de in mem:iter_user()do
        if utf8.len(de.text)>4 then
            mem:update_userdict(de, -1, '')
        end
    end
end

执行上面的函数后, 点击小狼毫输入法的菜单-用户词典管理-输出词典快照, 在输出的.userdb.txt文件中, 发现欲删除的词条仍然存在, 只是变成c=-1。如:

zqs zxd mqs uat izx     牀前明月光   c=-1 d=5.08447e-14 t=16984
zqs zxd mqs uat izx wja     牀前明月光疑  c=-1 d=5.18719e-14 t=16984
zqs zxd mqs uat izx wja dsq     牀前明月光疑是 c=-1 d=5.29197e-14 t=16984
zqs zxd mqs uat izx wja dsq lzn     牀前明月光疑是地    c=-1 d=5.39888e-14 t=16984
zqs zxd mqs uat izx wja dsq lzn daw     牀前明月光疑是地上   c=-1 d=5.50794e-14 t=16984
zqs zxd mqs uat izx wja dsq lzn daw sqs     牀前明月光疑是地上霜  c=-1 d=5.61921e-14 t=16984

请问有没有办法在用户词典中彻底删除词条 而不只是标记为已删除?

shewer commented 4 months ago

可以用 userDB ,
LevelDb (levelDB) 無法重覆開啓 , 在載入 translator (userdict) 前 處理 且關閉 db TableDb (text) 可以重覆開啓, 可在工作中處理, (不保證正確 , 沒試過)

找value 中 c=-1 的key : "字根\s\t詞\s" earse(key)


 local db  LevelDb( dbname)
 if db then db:open()
 for key,value in db:query("") do -- 從頭    
     if value:match("c=-1") then
        db:earse(key)
     end
end

240

shewer commented 3 months ago

可以用 userDB , LevelDb (levelDB) 無法重覆開啓 , 在載入 translator (userdict) 前 處理 且關閉 db TableDb (text) 可以重覆開啓, 可在工作中處理, (不保證正確 , 沒試過)

找value 中 c=-1 的key : "字根\s\t詞\s" earse(key)

local db  LevelDb( dbname)
if db then db:open()
for key,value in db:query("") do -- 從頭    
    if value:match("c=-1") then
       db:earse(key)
    end
end

240

不行的 這個 dbpool 和 user_dict 中的dbpool 是不同的 lua 中的userdb 原本是提供 給 librime-lua 使用(大量key value, 想要處理 user_dict 還是同上文說明,在載入 translator 前,線外處理。 運行中只有調整 commit_count

Tsinswreng commented 3 months ago

謝謝。用LevelDb就足夠了。