「FCITX/5」- 词库管理、扩充词库

词库的英文术语是什么?

ChatGPT 4.0 —— 输入法词库是什么?请用英语解释

针对英文文献资料的搜索,需要知道中文术语对应的英文单词。如果使用强行翻译的英语(Chinglish),很多时候无法搜索到结果;

An input method editor (IME) dictionary, also known as a lexicon, is a critical part of input method software. It’s a database that contains a vast number of words and phrases. When a user types letters or pinyin on the keyboard, the input method uses the dictionary to search for corresponding Chinese characters or phrases, which are then presented to the user for selection. Therefore, the quality of the dictionary directly affects the accuracy and efficiency of the input method.

输入法词库是输入法软件中的一个关键部分,它是一个包含大量字词和短语的数据库。当用户在键盘上输入字母或拼音时,输入法会根据词库搜索对应的中文字符或词组,然后提供给用户选择。因此,词库的质量直接影响了输入法的准确性和效率。

“输入法词库”的英文是 “Input Method Dictionary”,在 Arch Wiki 中,使用 Words Library 一词;

[FCITX/5] 增加词库容纳的词语数量

在进行中文输入时,选字是件繁琐的事情。例如,输入四字成语,如果词库没有对应的词语,那么就要挨个拼音进行选字,极其繁琐;

所以,我们需要增加输入法词库的容量,向其中添加更多的词语,以快速匹配我们的拼音

通过 Cloud Pinyin 插件

https://fcitx-im.org/wiki/Cloudpinyin
https://wiki.archlinux.org/title/Fcitx5#Cloud_Pinyin
https://github.com/fcitx/fcitx-cloudpinyin

通过 Cloud Pinyin 插件,在用户输入时,其将调用在线词库搜索词语;

支持后端:Google, Baidu, GoogleCN

根据源码(fsrc/cloudpinyin.c),其使用接口地址(我们仅大致了解,并非要深究细节):
1)http://web.pinyin.sogou.com/web_ime/patch.php
2)http://web.pinyin.sogou.com/api/py?key=%s&query=%s
3)http://ime.qq.com/fcgi-bin/getkey
4)http://ime.qq.com/fcgi-bin/getword?key=%s&q=%s
5)https://www.google.com/inputtools/request?ime=pinyin&text=%s
6)https://olime.baidu.com/py?py=%s&rn=0&pn=1&ol=1

[FCITX/4] 导入搜狗词库文件

fcitx输入法导入搜狗scel词库方法

注 1:文中部分内容属于个人推断,并未研究过,请以文档为准。

#1 下载搜狗词库文件(.scel)

到搜狗官网下载词库文件

下载词库以后得到一个扩展名为scel的文件。比如:demo.secl

#2 将.scel文件转化为.org文件

#!/bin/bash

# 将scel文件转化为org文件
scel2org -o tmp.org demo.scel

# 执行结束以后会得到一个tmp.org文件

#3 将.org词库与原有的.org词库进行合并

#!/bin/bash

cat pyPhrase.org tmp.org > final.org

# pyPhrase.org文件位于源码/build/src/im/pinyin/data/pyPhrase.org
# build目录是构建的时候,我们自己创建的。
# 而pyPhrase.org的源文件为源码目录/src/im/pinyin/data/pinyin.tar.gz解压所得

#4 对生成的新的.org文件进行合并去重

可以对final.org文件先执行sort命令,后执行uniq命令进行去重。

这里略过,不再详述。

#5 将.org文件转化为.mb文件

#!/bin/bash

# 将ORG文件转化为MB文件
createPYMB gbkpy.org final.org

# 注意:gbkpy.org文件位与fcitx的源码目录/src/im/pinyin/data/gbkpy.org

#6 复制.mb文件到特定位置

将生成的.mb文件复制到/usr/share/fcitx/pinyin下,但这会覆盖目录下原有的pybase.mb和pyphrase.mb文件。

也可以将其生成的.mb文件复制到~/.config/fcitx/pinyin下,但是这样就不会再读取/usr/share/fcitx/pinyin/*.mb文件了。所以和合并新词库和旧词库是十分重要的。

#7 重启FCITX

执行:fcitx -d -r

按理说重启是不应该重启系统的,但是重启FCITX会使我的桌面系统卡死,还要重启桌面,为了方便我就直接重启了。