【筆記】將尹倉導入ibus

一直覺的更新ibus的碼表挺麻煩,其實並不。通過這次記錄,今後我就可以快速的更新倉頡輸入法碼表。

  • 作業系統:ubuntu22.04
  • 輸入法:ibus
  • 碼表:尹倉

步驟

  1. 製作文本碼表
  2. 導入ibus
  3. logout/login即可生效

一,製作文本碼表

ibus-table的碼表格式

### File header must not be modified
### This file must be encoded into UTF-8.
### This table under LGPL
### comments start with ### not single #
### Derive from the format of SCIM Table, so you can modify the table from
### scim-tables' table

Ejsoon_Cangjie_Table_Phrase_Library_TEXT
VERSION_202208

### Begin Table definition.
BEGIN_DEFINITION

### License
LICENSE = LGPL

### An unique id to distinguish this table among others.
### Use uuidgen to generate this kind of id.
UUID = 41d16dbb-3765-4b30-8547-9fc7379930f1

### A unique number indicates the version of this file.
### For example the last modified date of this file.
### This number must be less than 2^32.
### Just make your table version-able
SERIAL_NUMBER = 20220805

### ICON can be any format as long as your pygtk can recognized
### the most widely ones are "png" and "svg", letter one is recommended
ICON = ibus-table.svg

### The symbol to be displayed in IM switchers
SYMBOL = 尹

### The default name of this table, this is needed
NAME = Table

### The local names of this table, this is optional
NAME.zh_CN = 尹倉
NAME.zh_HK = 尹倉
NAME.zh_TW = 尹倉

### Description
DESCRIPTION = This is a template engine table for IBus Table.

### Supported languages of this table
### sigle "zh_CN" just be recognized as zh_CN,
### but "zh_CN, zh_HK" or more zh_XX will be recognized as zh;
### and "en_US, zh_CN" will be just ignored.
LANGUAGES = zh_CN,zh_SG,zh_TW,zh_HK

### The author of this table
AUTHOR = Ejsoon <ejsoon@outlook.com>

### Prompt string to be displayed in the status area, CN will be replaced by
### the gettext tools in runtime as 中.
STATUS_PROMPT = CN

### Valid input chars.
VALID_INPUT_CHARS = abcdefghijklmnopqrstuvwxyz

### Layout
LAYOUT = us

### The max number of input keys for every phrase or character.
MAX_KEY_LENGTH = 5

### Use auto_commit mode as default
AUTO_COMMIT = FALSE

### Automatically selects the first phrase when typing
AUTO_SELECT = FALSE

### Use full width punctuation by default
DEF_FULL_WIDTH_PUNCT = TRUE
### Not use full width letter by default
DEF_FULL_WIDTH_LETTER = FALSE

### Whether user are allow to define phrase, default is true
### You have to define the word construction rules below.
### For input methods which do not input phrases, set this to False
USER_CAN_DEFINE_PHRASE = FALSE

### Whether support PinYin Mode, default is true.
### this feature is just for Chinese, set it to False if your IM is not
### Chinese.
PINYIN_MODE = FALSE

### If true then the phrases' frequencies will be adjusted dynamically
### according your using frequency.
DYNAMIC_ADJUST = FALSE

### Some characters whose frequencies should be fix all the time, e.g.
### some punctuations
### NO_CHECK_CHARS =

### Rules for constructing user defined phrase
### "ce" stands for "ci equal", a Chinese English :), means "phrase length
### equal to", thus ce2 -> phrase length equal to 2; and "ca" means "phrase
### length equal or above", so ca4 -> phrase length equal or above 4.
### p21 -> the 1st key of 2nd character in the phrase, and so on.
### Each rule separate via ";".
### Example below is a complete rule-set,
### becuase [2,2] ∩ [3,3] ∩ [4,+∞] = [2,+∞], which is the range of length
### of phrase. This have to be satisfied if you need ibus-table to build up
### your own inputed phrase via your daily using.
RULES = ce2:p11+p12+p21+p22;ce3:p11+p21+p22+p31;ca4:p11+p21+p31+p41

### The key strokes to page up the lookup table.
PAGE_UP_KEYS = Page_Up,KP_Page_Up,minus,comma

### The key strokes to page down.
PAGE_DOWN_KEYS = Page_Down,KP_Page_Down,equal,period

### The key strokes to select candidiate phrases.
### Usually "1,2,3,4,5,6,7,8,9" but if this conflicts with
### characters one wants to use for input one can also
### use something like “F1,F2,F3,F4,F5,F6,F7,F8,F9”
SELECT_KEYS = 1,semicolon,apostrophe,4,5,6,7,8,9

### The default orientation of the candidate list
### TRUE means the candidate list is vertical, FALSE means it is vertical
ORIENTATION=FALSE

END_DEFINITION

### Begin Table data.
### Format of every line whose formated in "input_keys\tphrase\tfreq\n" is an
### entry.
### From left to right, the 1st column are the input key combination that you
### entered via keyboard; the 2nd column are presented character or phrase of
### the key combination you want; the 3rd column are frequency of the character
### or phrase.
BEGIN_TABLE
a 日 20902
a 曰 20901
...
yyyb 髙 1
END_TABlE

 

將以上的文本文件複製保存成一個txt文件,建議用vim來處理。

需要更改以下三行,都在文件前面,其中第一和第三處為手填,而uuid需要用到uuidgen來生成。

VERSION_20230611
UUID = f399676f-64c9-497f-b542-16a5a349290c
SERIAL_NUMBER = 202306110915

下面就是難度比較大的地方,把尹倉碼表載入BEGIN_TABLE與END_TABlE中間。記的把〇跟33個標點也加進去。

這之後,ibus-table還要求後面要跟一個權重數字。vim新建一個文本,生成遞減數字,命令是r !seq 20902 -1 1。再把這些數字前面補0以使之長度相等(如何補0這裏就不介紹了)。這之後要用到「垂直選取」,快捷建是ctrl+v。

現在回到TABLE,把它每行前面騰出一個空格和一個\t,再把垂直選取的數字粘貼至行首。再用正則表達式,去掉行首的0,之後用正則把數字調到後面。

二,導入ibus

之後用ibus-table-createdb -s 碼表,生成db之後,放進「/usr/share/ibus-table/tables/」,之後在設置->鍵盤裏面,就可以添加尹倉。

三,logout,login,即可生效

或者重啟。

每次修改碼表導入時,都要生成一個新的uuid。否則系統可能會認為是同一個碼表。

Leave a Comment