Linux 下 Rime 使用白霜拼音配置 + 万象语言模型 + 同步

之前在 Linux 上先后用过雾凇拼音、万象拼音,最后切到白霜拼音。再按照 README 的说明把语法模型换成了万象 LTS 模型。这里把完整步骤记下来,包括 Fcitx5 和 IBus 的路径差异、Rime 同步,以及水平候选词。

综合下来体验很好,既没有万象拼音一些奇怪的功能和 bug,又比雾凇拼音奇怪的分词匹配要好得多。

基础组件

Ubuntu 上先装 Rime 前端和 octagram 插件。语言模型依赖 librime-plugin-octagram

Fcitx5:

1
sudo apt install fcitx5-rime librime-plugin-octagram

IBus:

1
sudo apt install ibus-rime librime-plugin-octagram

两个前端的 Rime 配置目录不同:

1
2
Fcitx5: ~/.local/share/fcitx5/rime
IBus: ~/.config/ibus/rime

后文用 $rime_dir 表示当前机器正在使用的目录。

安装 Plum

Plum 是 Rime 生态常用的配置管理工具。

1
2
mkdir -p ~/Programs
git clone --depth 1 https://github.com/rime/plum ~/Programs/Plum

如果之前已经装过,更新即可:

1
git -C ~/Programs/Plum pull

安装白霜拼音

Fcitx5:

1
2
rime_dir="$HOME/.local/share/fcitx5/rime"
env rime_dir="$rime_dir" bash ~/Programs/Plum/rime-install gaboolic/rime-frost:others/recipes/full

IBus:

1
2
rime_dir="$HOME/.config/ibus/rime"
env rime_dir="$rime_dir" bash ~/Programs/Plum/rime-install gaboolic/rime-frost:others/recipes/full

本次实践中,Plum 拉下来的白霜包里有些文件没有自动放进活动目录。若部署时提示缺少 zh-moqi.gramrime_frost_aux,可以从 Plum 的 package 目录手动补进去:

1
2
cp ~/Programs/Plum/package/gaboolic/frost/zh-moqi.gram "$rime_dir"/
cp ~/Programs/Plum/package/gaboolic/frost/rime_frost_aux.* "$rime_dir"/

然后把默认方案限定为白霜拼音。新建或修改 $rime_dir/default.custom.yaml

1
2
3
4
5
6
# Rime default custom settings
# encoding: utf-8

patch:
schema_list:
- schema: rime_frost

下载万象 LTS 模型

前往 RIME-LMDG 下载万象 LTS 模型。这里使用简体模型:

1
2
curl -L -o "$rime_dir/wanxiang-lts-zh-hans.gram" \
https://github.com/amzxyz/RIME-LMDG/releases/download/LTS/wanxiang-lts-zh-hans.gram

启用万象模型

新建 $rime_dir/rime_frost.custom.yaml

1
vim $rime_dir/rime_frost.custom.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
# Rime schema custom settings
# encoding: utf-8

patch:
grammar:
language: wanxiang-lts-zh-hans
non_collocation_penalty: -4
collocation_max_length: 5
collocation_min_length: 2
collocation_penalty: -14
translator/contextual_suggestions: true
translator/max_homophones: 4
translator/max_homographs: 2

这里的 language 要和 .gram 文件名前缀一致。也就是:

1
wanxiang-lts-zh-hans.gram -> language: wanxiang-lts-zh-hans

万象 release 里也提醒过,模型和词库是紧耦合的;云插件和模型也不适合同时开,因为云插件会占用候选位置,等于削弱模型效果。我的做法是只用本地模型,不开云插件。

部署

Fcitx5:

1
2
rime_deployer --build "$HOME/.local/share/fcitx5/rime"
fcitx5-remote -r

IBus:

1
2
rime_deployer --build "$HOME/.config/ibus/rime"
ibus restart

如未生效,也可以从 Rime 菜单里手动点击「部署」。部署后用 Ctrl + ~ 打开方案选单,确认当前方案是白霜拼音。

验证模型配置

部署后可以看 build 文件确认配置是否进去了。

Fcitx5:

1
sed -n '/^grammar:/,/^[^ ]/p' ~/.local/share/fcitx5/rime/build/rime_frost.schema.yaml

IBus:

1
sed -n '/^grammar:/,/^[^ ]/p' ~/.config/ibus/rime/build/rime_frost.schema.yaml

应能看到类似内容:

1
2
3
4
5
6
grammar:
collocation_max_length: 5
collocation_min_length: 2
collocation_penalty: "-14"
language: "wanxiang-lts-zh-hans"
non_collocation_penalty: "-4"

也可以确认 octagram 插件存在:

1
dpkg -L librime-plugin-octagram | grep librime-octagram

这只能说明配置层面已经生效。实际排序效果还是要靠输入体验判断,尤其是长句和同音词较多的场景。

设置水平候选词

IBus 和 Fcitx5 的候选词方向不在同一个地方。

IBus 使用 Rime 前端配置。新建 $rime_dir/ibus_rime.custom.yaml

1
2
3
4
5
# ibus-rime custom settings
# encoding: utf-8

patch:
style/horizontal: true

然后重新部署:

1
2
rime_deployer --build "$HOME/.config/ibus/rime"
ibus restart

如未生效,也可以从 Rime 菜单里手动点击「部署」。

Fcitx5 的候选方向通常由 Fcitx5 的 UI 插件控制,不是 rime_frost.custom.yaml。推荐打开配置工具:

1
fcitx5-configtool

进入 Addons / Classic User Interface / Configure,把 Vertical Candidate List 关掉,即为水平候选。

也可以直接编辑 ~/.config/fcitx5/conf/classicui.conf,加入或修改:

1
2
# Vertical Candidate List
Vertical Candidate List=False

然后重载 Fcitx5:

1
fcitx5-remote -r

如果使用的不是 Classic UI,而是桌面环境自己的候选窗口或 Kimpanel,候选方向可能要在对应的输入法面板设置里改。

Rime 同步

Rime 的 sync 适合同步用户词库和配置,但不要假设 .gram 模型会可靠同步。万象模型有几百 MB,最好每台机器本地各放一份。

先设置每台机器自己的 installation_id,并让它们指向同一个 sync_dir

Fcitx5 的文件是:

1
~/.local/share/fcitx5/rime/installation.yaml

示例:

1
2
installation_id: atlas
sync_dir: "/home/sammy/Drives/MEGA/Settings/Rime"

IBus 的文件是:

1
~/.config/ibus/rime/installation.yaml

示例:

1
2
3
distribution_code_name: "ibus-rime"
installation_id: carbon
sync_dir: "/home/sammy/Drives/MEGA/Settings/Rime"

要点是:

  • 每台机器的 installation_id 必须不同。
  • 每台机器的 sync_dir 指向同一个网盘同步目录。
  • sync_dir 下会生成与 installation_id 同名的子目录。
  • 先确保本机活动目录里已经有 wanxiang-lts-zh-hans.gram,再部署使用同步来的 rime_frost.custom.yaml

配置完成后,在 Rime 菜单中点击「同步用户资料」。同步后可以检查:

1
find "/home/sammy/Drives/MEGA/Settings/Rime" -maxdepth 2 -type f | sort

我的经验是,迁移输入方案时最好先清理旧同步目录里明显过时的方案文件,例如旧的 wanxiang*rime_ice*luna_pinyin*。否则新机器同步时可能把历史方案和当前方案混在一起。

回退

如果想回到白霜默认模型,删除或改名:

1
$rime_dir/rime_frost.custom.yaml

然后重新部署即可。保留 zh-moqi.gram 的意义就在这里:回退时不用重新找白霜默认模型。

参考

Mastodon