在Ubuntu下的中文输入一直是一件很头疼的事情,原先使用多年的scim输入平台已经腐朽不堪,现在默认的ibus虽然是一个优秀的平台,但是缺乏优秀的输入法——常用的ibus pinyin的算法实在是令人无语,只好通过使用更大的词库(100MB+的搜狗词库)来弥补不足,不过效果也只是一般般,而且由于词库变大了许多,响应速度也变慢了。有一个基于统计语言模型的优秀输入法——sunpinyin,但是词库不大。性能低下的主要原因,是因为他们都是运行于一个“输入平台”ibus之上的——越复杂的系统架构会带来越低下的性能,ibus是一个十分灵活的、能够安装各种语言的输入法的平台,十分臃肿,其性能很难好到哪里去。种种原因之下,我选择安装了fcitx。
在安装之前先说一下fcitx 输入法吧。
什么是fcitx-小企鹅输入法
Fcitx──小企鹅输入法:Free Chinese Input Toy for X是国产软件的精品,是一个以GPL方式发布的、基于XIM的简体中文输入法集合(原为G五笔),包括五笔、五笔拼音、二笔、仓颉、晚风、冰蟾全息、拼音 (全拼和双拼)、区位以及码表输入模块。
进入正题
fcitx 4.x with sunpinyin 并且使用hubert整理的sunpinyin词库。这是我个人使用的先当满意个一个组合。虽然现在还是读入到内存中运行,但是,现在的个人电脑的内存都是相当的大。就比如我的笔记本,现在是8G的内存,除去我开虚拟机模拟做实验的时间,大部分都是在空闲,因此这样也能充分利用自己电脑的资源。
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 #设为默认输入法,一般不需要,除非系统有多个输入法
注意:
如果你之前有使用过ibus-sunpinyin,请将其完全删除。
sudo apt-get remove ibus
对于已经安装老版 的fcitx,删掉再装.
sudo apt-get remove fcitx
切换至fcitx,注销后再次登陆你的输入法就将变为fcitx了
右键点击fcitx托盘图表 -> 配置fcitx,会打开fcitx-config进行配置(推荐使用dark皮肤~);右键点击托盘图表 -> 切换输入法,设置为sunpinyin。
前往hubert的google code(http://code.google.com/p/hslinuxextra/downloads/list)页面下载sunpinyin-userdict.7z ,并解压到~/.sunpinyin下覆盖userdict文件。这个是sunpinyin的大词库,加载运行会占据一定的内存,为了提高输入的效率,所以写了一个加速的脚本,如下
#!/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赋予可执行权利,在“系统 -> 首选项 -> 启动应用程序”中添加这个脚本。
到这里就算安装配置完成了。
转载于:https://blog.51cto.com/ninglinux/1107061