UBUNTU下的中文输入法:fcitx 4.x with sunpinyin
?在Ubuntu下的中文輸入一直是一件很頭疼的事情,原先使用多年的scim輸入平臺已經(jīng)腐朽不堪,現(xiàn)在默認的ibus雖然是一個優(yōu)秀的平臺,但是缺乏優(yōu)秀的輸入法——常用的ibus pinyin的算法實在是令人無語,只好通過使用更大的詞庫(100MB+的搜狗詞庫)來彌補不足,不過效果也只是一般般,而且由于詞庫變大了許多,響應速度也變慢了。有一個基于統(tǒng)計語言模型的優(yōu)秀輸入法——sunpinyin,但是詞庫不大。性能低下的主要原因,是因為他們都是運行于一個“輸入平臺”ibus之上的——越復雜的系統(tǒng)架構(gòu)會帶來越低下的性能,ibus是一個十分靈活的、能夠安裝各種語言的輸入法的平臺,十分臃腫,其性能很難好到哪里去。種種原因之下,我選擇安裝了fcitx。
在安裝之前先說一下fcitx 輸入法吧。
什么是fcitx-小企鵝輸入法
Fcitx──小企鵝輸入法:Free Chinese Input Toy for X是國產(chǎn)軟件的精品,是一個以GPL方式發(fā)布的、基于XIM的簡體中文輸入法集合(原為G五筆),包括五筆、五筆拼音、二筆、倉頡、晚風、冰蟾全息、拼音 (全拼和雙拼)、區(qū)位以及碼表輸入模塊。
進入正題
fcitx 4.x with sunpinyin ?并且使用hubert整理的sunpinyin詞庫。這是我個人使用的先當滿意個一個組合。雖然現(xiàn)在還是讀入到內(nèi)存中運行,但是,現(xiàn)在的個人電腦的內(nèi)存都是相當?shù)拇蟆>捅热缥业墓P記本,現(xiàn)在是8G的內(nèi)存,除去我開虛擬機模擬做實驗的時間,大部分都是在空閑,因此這樣也能充分利用自己電腦的資源。
Ubuntu下的安裝方法:
添加fcitx的nightly build PPA源(這樣才有最新的4.x版)并安裝
1.sudo apt-add-repository ppa:wengxt/fcitx-nightly
2.sudo apt-get update
3.sudo apt-get install fcitx fcitx-config fcitx-sunpinyin
4.im-switch -s fcitx -z default #設(shè)為默認輸入法,一般不需要,除非系統(tǒng)有多個輸入法
注意:
如果你之前有使用過ibus-sunpinyin,請將其完全刪除。
sudo apt-get remove ibus
對于已經(jīng)安裝老版 的fcitx,刪掉再裝.
sudo apt-get remove fcitx
?
切換至fcitx,注銷后再次登陸你的輸入法就將變?yōu)閒citx了
右鍵點擊fcitx托盤圖表 -> 配置fcitx,會打開fcitx-config進行配置(推薦使用dark皮膚~);右鍵點擊托盤圖表 -> 切換輸入法,設(shè)置為sunpinyin。
前往hubert的google code(http://code.google.com/p/hslinuxextra/downloads/list)頁面下載sunpinyin-userdict.7z ?,并解壓到~/.sunpinyin下覆蓋userdict文件。這個是sunpinyin的大詞庫,加載運行會占據(jù)一定的內(nèi)存,為了提高輸入的效率,所以寫了一個加速的腳本,如下
#!/bin/bash
#sunpinyin_speed_up.sh
# Sunpinyin Speed Up Script for Ubuntu (by memory caching, and no data loss)
# You can run this script in background on GNOME logging in.
# Originally written Hubert Star, modified by Bob Robot (http://robotshell.org/).
# Capture the exit signal, make sure it is the FIRST uncommented line.
trap?"do_exit"?SIGHUP SIGINT SIGQUIT SIGTERM
SUN_DIR="${HOME}/.sunpinyin"
SHM_USERDICT="/dev/shm/sunpinyin_userdict.sh0"
# Backup the userdict and restore all changes made by this script on exit.
do_exit()?{
??cp?-f?"${SHM_USERDICT}"?"${SUN_DIR}/userdict.real"
??rm?-f?"${SHM_USERDICT}"
??mv?-f?"${SUN_DIR}/userdict.real"?"${SUN_DIR}/userdict"
??exit?0
}
# Work around for abnormal quit.
if?[?-e?"${SUN_DIR}/userdict.real"?]
then
??rm?-f?"${SHM_USERDICT}"
??mv?-f?"${SUN_DIR}/userdict.real"?"${SUN_DIR}/userdict"
fi
# Rename the real userdict, copy it to RAM and make a symblic link back.
# From now on the modification and query on userdict takes place in RAM.
mv?-f?"${SUN_DIR}/userdict"?"${SUN_DIR}/userdict.real"
cp?-f?"${SUN_DIR}/userdict.real"?"${SHM_USERDICT}"
ln?-sf?"${SHM_USERDICT}"?"${SUN_DIR}/userdict"
# Automatically backup the userdict, make sure not losing the modification.
p_count=0
while?[?true?]
do
??p_count=$(($p_count+1))
??sleep?1800
??
??if?[?$p_count?==?4?]
??then
? ? ?p_count=0
? ? ?cp?-f?"${SHM_USERDICT}"?"${SUN_DIR}/userdict.real"
??fi
??
??p_size_shm=$(ls?-l?"${SHM_USERDICT}"?|?awk?'{print $5}')
??p_size_real_t=$(ls?-l?"${SUN_DIR}/userdict.real"?|?awk?'{print $5}')
??p_size_real=$(($p_size_real_t+512))
??
??if?[?$p_size_shm?-ge?$p_size_real?]
??then
? ? ?cp?-f?"${SHM_USERDICT}"?"${SUN_DIR}/userdict.real"
??fi
done
使用方式:將這個腳本放在方便的地方,通過chmod +x賦予可執(zhí)行權(quán)利,在“系統(tǒng) -> 首選項 -> 啟動應用程序”中添加這個腳本。
到這里就算安裝配置完成了。
轉(zhuǎn)載于:https://blog.51cto.com/ninglinux/1107061
總結(jié)
以上是生活随笔為你收集整理的UBUNTU下的中文输入法:fcitx 4.x with sunpinyin的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WCF入门(六)——回调
- 下一篇: union-find算法分析(2)