• 中州韵输入法(rime)导入搜狗词库


    rime是一个非常优秀的输入法,linux平台下的反应速度远超搜狗,也没有隐私风险。2012年开始接触它,到后来抛弃了它,因为rime自带的词库真的太弱了,也懒得折腾。最近发现一个词库转换软件叫 imewlconverter,于是发现rime导入其他输入法(比如搜狗)的词库其实还挺方便的。

    要导入词库需要两个文件:

    1. luna_pinyin_simp.custom.yaml 是配置文件

    rime在部署的时候会自动加载。因为我用的是明月简体schema,所以是这个名字。如果你用的是明月schema,那就是luna_pinyin.custom.yaml

    # luna_pinyin_simp.custom.yaml
    patch:
    # 指定自定义词库位置
      "translator/dictionary": luna_pinyin.sogou
    

    2. luna_pinyin.sogou.dict.yaml 是词库文件

    文件名是上面配置文件中设置的名字加上.dict.yaml后缀。内容是一个rime定义的文件头加上转换好的txt格式的词库:

    将这两个文件放置在rime的配置文件夹之后,点击rime输入法图标的“重新部署”按钮就可以了。输入“yxlm”会自动出现原来没有的候选词“英雄联盟”。

    3. 怎么生成这个luna_pinyin.sogou.dict.yaml

    • 首先安装一下imewlconverter,怎么安装就不说了。
    • 然后下载搜狗的scel细胞词库到某个文件夹
    • 然后在这个文件夹写一个批量转换的python脚本(见最后)。
    • 然后运行这个脚本,就会用imewlconverter把所有的scel细胞词库文件转换成一个txt格式的词库文件,并以自定义的文件名保存,然后添加rime定义的yaml头。
    • 拷贝文件到rime配置文件夹。
    #!/usr/bin/env python
    # coding=utf-8
    
    # ============================================================
    # filename : convert.py
    #  author  : chdy.uuid@gmail.com
    # modified : 2019-09-11 15:39
    # descrip. :
    # ============================================================
    
    from glob import glob
    import os
    import shutil
    
    if not os.path.exists('./output/'):
        os.mkdir('output')
    
    original_files = glob("*.scel")
    print("---------------")
    for of in original_files:
        if ' ' in of:
            new_fn = of.replace(' ', '_')
            print('rename "%s" to "%s"' % (of, new_fn))
            shutil.move(of, new_fn)
            of = new_fn
        print('>> ', of)
    print("---------------")
    
    original_files = glob("*.scel")
    # print(original_files)
    
    yaml_file = 'luna_pinyin.sogou.dict.yaml'
    
    command='''imewlconverter -i:scel %s -o:rime "%s"''' % (str(original_files).strip('[]').replace(',', ''), yaml_file)
    print(command)
    os.system(command)
    
    data = '''---
    name: luna_pinyin.sogou
    version: "1.0"
    sort: by_weight
    use_preset_vocabulary: true
    # 此处为扩充词库(基本)默认链接载入的词库
    import_tables:
        - luna_pinyin
        - luna_pinyin.sogou
    ...
    
    # 自定义词语
    
    '''
    with open(yaml_file, "r+") as f:
         old = f.read()
         f.seek(0)
         f.write(data)
         f.write(old)
    
    print("Now don't forget to copy the file to rime config folder (like ~/.config/fcitx/rime)")
    

    https://www.jianshu.com/p/300bbe1602d4

  • 相关阅读:
    二、Python基础练习
    代码测试服同步到生产服务器
    支付宝网站支付 异步验签成功 同步验签失败
    最近机房让整改的漏洞 设置cookie httponly X-Frame-Options头未设置
    连连支付,或微信或支付宝支付,商品名称最后一个字乱码,php解决
    ci 框架新手使用
    php制作公司五章,圆形印章和椭圆形印章,正方形印章,圆角正方形印章,圆角框
    Libreoffice php使用命令行office转pdf,pdf转图片
    后台返回数据回显,使用js控制默认选中复选框和下拉框
    Nginx日志按日期切割详解(按天切割)
  • 原文地址:https://www.cnblogs.com/dylanchu/p/11507492.html
Copyright © 2020-2023  润新知