rime是一个很是优秀的输入法,linux平台下的反应速度远超搜狗,也没有隐私风险。2012年开始接触它,到后来抛弃了它,由于rime自带的词库真的太弱了,也懒得折腾。最近发现一个词库转换软件叫 imewlconverter
,因而发现rime导入其余输入法(好比搜狗)的词库其实还挺方便的。python
要导入词库须要两个文件: linux
1. luna_pinyin_simp.custom.yaml 是配置文件
rime在部署的时候会自动加载。由于我用的是明月简体schema,因此是这个名字。若是你用的是明月schema,那就是luna_pinyin.custom.yaml
。ui
# luna_pinyin_simp.custom.yaml patch: # 指定自定义词库位置 "translator/dictionary": luna_pinyin.sogou
2. luna_pinyin.sogou.dict.yaml 是词库文件
文件名是上面配置文件中设置的名字加上.dict.yaml
后缀。内容是一个rime定义的文件头加上转换好的txt格式的词库:spa
将这两个文件放置在rime的配置文件夹以后,点击rime输入法图标的“从新部署”按钮就能够了。输入“yxlm”会自动出现原来没有的候选词“英雄联盟”。code
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)")