├── .gitignore ├── README.org ├── gbkpy.org ├── pyim2fcitx.py └── pyphrase.mb /.gitignore: -------------------------------------------------------------------------------- 1 | ### /Users/cb/.gitignore-boilerplates/Global/Emacs.gitignore 2 | 3 | *~ 4 | \#*\# 5 | /.emacs.desktop 6 | /.emacs.desktop.lock 7 | .elc 8 | auto-save-list 9 | tramp 10 | .\#* 11 | 12 | # Org-mode 13 | .org-id-locations 14 | *_archive 15 | 16 | 17 | ### /Users/cb/.gitignore-boilerplates/Global/Vim.gitignore 18 | 19 | .*.sw[a-z] 20 | *.un~ 21 | Session.vim 22 | .netrwhist 23 | 24 | *.tar 25 | *.elc 26 | *.pyim 27 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | * pyim2fcitx 2 | Convert [[https://github.com/tumashu/pyim][pyim]] dictionary to [[https://fcitx-im.org/wiki/Fcitx][fcitx]] dictionary. 3 | 4 | 将 pyim 词库转换成 fcitx4/fcitx5 词库 5 | * Usage 6 | ** Fcitx4 7 | - Run =python pyim2fcitx.py my-personal.pyim > my-personal.org= 8 | - Run =createPYMB gbkpy.org my-personal.org= (=createPYMB= is from =fcitx-tools=) 9 | - Copy =pyphrase.mb= to =~/.config/fcitx/pinyin/= or do [[https://wiki.archlinux.org/index.php/Fcitx_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)]] as instructed 10 | - Restart fcitx 11 | 12 | You can also use my [[https://github.com/redguardtoo/pyim2fcitx/raw/master/pyphrase.mb][pyphrase.mb]] converted from [[https://github.com/tumashu/pyim-greatdict][pyim-greatdict]], containing 3296385 words. 13 | 14 | ** Fcitx5 15 | - Run =python pyim2fcitx.py -f 5 my-personal.pyim > my-personal.org= 16 | - Run =libime_pinyindict my-personal.org chaizi.dict= 17 | - Stop fcitx5 18 | - Copy "chaizi.dict" to "/usr/share/fcitx5/pinyin/" 19 | - Start fcitx5 20 | 21 | * 使用方法 22 | ** Fcitx4 23 | 24 | - 运行 =python pyim2fcitx.py my-personal.pyim > my-personal.org= 25 | - 运行 =createPYMB gbkpy.org my-personal.org= (=createPYMB= 来自于 =fcitx-tools=) 26 | - 复制 =pyphrase.mb= 到 =~/.config/fcitx/pinyin/= 或参照 [[https://wiki.archlinux.org/index.php/Fcitx_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)]] 27 | - 重启 fcitx 28 | 29 | 也可直接下载 [[https://github.com/redguardtoo/pyim2fcitx/raw/master/pyphrase.mb][我的 pyphrase.mb]]. 该词库的数据从 [[https://github.com/tumashu/pyim-greatdict][pyim-greatdict]] 转化过来. 包含 3296385 个词. 30 | 31 | ** Fcitx5 32 | - 运行 =python pyim2fcitx.py -f 5 my-personal.pyim > my-personal.org= 33 | - 运行 =libime_pinyindict my-personal.org chaizi.dict= 34 | - 停止 fcitx5 35 | - 拷贝 "chaizi.dict" 到 "/usr/share/fcitx5/pinyin/" 36 | - 启动 fcitx5 37 | -------------------------------------------------------------------------------- /pyim2fcitx.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import sys 3 | import re 4 | import getopt 5 | 6 | 7 | def usage(): 8 | print("Usage:") 9 | print(" python pyim2fcitx.py [-f 5] my-dict.pyim\n") 10 | print(" -f: fcitx version whose default value is 4 \n") 11 | print(" Visit https://github.com/tumashu/pyim to get pyim dictionaries") 12 | 13 | 14 | if __name__ == "__main__": 15 | all_args = sys.argv[1:] 16 | opts, arg = getopt.getopt(all_args, 'f:') 17 | fcitx_version = 4 18 | 19 | if len(arg) < 1: 20 | usage() 21 | exit(1) 22 | 23 | for opt, arg_val in opts: 24 | if opt == "-f" and int(arg_val) > fcitx_version: 25 | fcitx_version = int(arg_val) 26 | rd = open(arg[0], "r") 27 | while True: 28 | line = rd.readline() 29 | 30 | if not line: 31 | break 32 | # strip new line 33 | line = line.strip() 34 | 35 | # fcitx tools can't handle unusual pinyin 36 | if re.search("^[a-z-]+ ", line): 37 | # multiple words in one line 38 | m = re.search("^([a-z-.]+) ([^ ]+ [^ ]+.*)$", line) 39 | if m: 40 | pinyin = m.group(1).replace("-", "'") 41 | words = m.group(2).split() 42 | for word in words: 43 | if fcitx_version == 5: 44 | print("%s %s 0" % (word, pinyin)) 45 | else: 46 | print("%s %s" % (pinyin, word)) 47 | else: 48 | if fcitx_version == 5: 49 | pinyin_and_word = line.replace("-", "'").split() 50 | # first is pinyin, second is word 51 | print("%s %s 0" % (pinyin_and_word[1], pinyin_and_word[0])) 52 | else: 53 | print(line.replace("-", "'")) 54 | -------------------------------------------------------------------------------- /pyphrase.mb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redguardtoo/pyim2fcitx/0bea491bb3fb28f8415a13dd2beafdb00b88a0f7/pyphrase.mb --------------------------------------------------------------------------------