使用者工具

網站工具


os:linux:ibus_大易輸入法的問題

自製 IBus 用的大易輸入法表格檔

1. 製作輸入法表

輸入法表範本

先由 /usr/share/ibus-table/tables/template.txt 取得輸入法表的範本 (template),可以把它複製至您的家目錄 (home directory): (若沒有此檔, 直接複製以下也行)

cd
cp /usr/share/ibus-table/tables/template.txt .

把檔案重新命名您要製作輸入法 (習慣上仍是以 .txt 結尾):

mv template.txt Cantonese.txt

然後使用任何文字編輯器編輯範本檔案:

gedit Cantonese.txt

以下是一個很典型的輸入法表範本

### File header must not be modified
### This file must be encoded into UTF-8.
### Derive from the format of SCIM Table, so you can modify the table from
### scim-tables' table
### 輸入法表一定要使用 UTF-8 編碼
SCIM_Generic_Table_Phrase_Library_TEXT
VERSION_1_0

### Begin Table definition.
BEGIN_DEFINITION

### 指定輸入法表的使用授權,常見授權包括 GPL 或 LGPL。
### 留意現時大部份輸入法都有版權,請先查証才填寫此欄和分派輸入法表。
LICENSE = LGPL

### UUID 為一個識別碼用作識別不同的輸入法表。
### 請自行用 uuidgen 產生另一個新 UUID 並取替以下值
UUID = 95af07bc-3fee-4541-ac74-c53e9a5fe342

### SERIAL_NUMBER 為另一個識別碼用作識別此輸入法表檔案的不同版本。
### 一般會用最後修改的日期時間來作 SERIAL_NUMBER
### SERIAL_NUMBER 的數值一定要小於 4294967296 (2^32) 的正整數。
SERIAL_NUMBER = 2010060801

### 輸入法圖示檔案,可以為 PNG 或 SVG 檔案 。(為放便以不同大小顯示,SVG 會較佳) 
ICON = ibus-table.svg

### 此輸入法的名稱 (英文)
NAME = Cantonese

### 此輸入法在不同語言下的名稱。(可以省略)
NAME.zh_CN = 倉頡第三代
NAME.zh_TW = 倉頡第三代
NAME.zh_HK = 倉頡第三代

### 本輸入法的簡單描述
DESCRIPTION = This is a template engine table for IBus Table.

### 此輸入法表製作者的姓名和電郵地址
AUTHOR = J. Random <jrandom@example.com>

### 此輸入法支援的語言
LANGUAGES = zh_CN,zh_HK,zh_SG,zh_TW

### 在狀態列顯示的提示字串。填上 CN 會被 gettext 翻譯成 "中"。
STATUS_PROMPT = CN

### 列出合法的輸入字元
VALID_INPUT_CHARS = abcdefghijklmnopqrstuvwxyz

### 鍵盤排列,一般為美式鍵盤 us
LAYOUT = us

### Use auto_commit mode as default
AUTO_COMMIT = 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 = TRUE

### 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 = TRUE

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

### 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, 
### because [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

END_DEFINITION

### Define the prompts of each valid input char.
BEGIN_CHAR_PROMPTS_DEFINITION
a 日
b 月
c 金
....
x 難
y 卜
z 重
END_CHAR_PROMPTS_DEFINITION
END_DEFINITION

### Begin Table data.
BEGIN_TABLE
input_keys      aim_chars       freq
input_keys      aim_chars       freq
input_keys      aim_chars       freq
END_TABLE

### Since some input methods use different table for every character to make
### phrase, such as ZhengMa, they need explict define the goucima (the
### phrase-building code for the given character), the format of every entry is
### "character\tgoucima\n". 
### For the input method which just use the full code as word-building code
### just skip this field. The ibus-table will build the codes needed from
### above TABLE.
### if you don't need different word-building code, please comment out the
### next few lines with ###, just like these lines you are look at now.
BEGIN_GOUCI
character_1     goucima_1
character_1     goucima_2
END_GOUCI

輸入法對照表

BEGIN_TABLE 下面 就係輸入碼同字既對照表,可以有三欄,欄與欄之間一定要用 tab 分隔。例如以下 cantonese.txt 的輸入法表

BEGIN_TABLE
fan        瞓
fun        瞓
ngam       啱
....
fai        鐨
fai        廢
fai        徽
fai        輝
fai        煇
fai        沸
  • 第一欄 (e.g. fan, fun, ngam) 就是輸入碼
  • 第二欄 (e.g. 瞓, 啱, 鐨) 就是對應字
  • 第三欄可有可無, 有的話就必定是一個數目字表示呢個字的預設選擇次數, 數字越大, 個字會排得前 d

例如你想打 fai 時 “癈” 排前過 “鐨”, 你可以在兩字後家上數字 , 如下:

fai        鐨 495
fai        廢 500

只要“癈” 的數字大過 “鐨” 那個, 那“癈”就會排前

2. 轉換輸入法表

輸成輸入法表後,請用 ibus-table-createdb 把輸入法表轉換成資料庫格式 (*.db)

ibus-table-createdb -n Cantonese.db -s Cantonese.txt

3. 安裝輸入法

然後把 Cantonese.db 複製至目錄 /usr/share/ibus-table/tables 中。

重新啟動 IBus 並在 IBus 偏好設定上加入新輸入法就可以了。

4. 以大易為例

取得字根表

大易三碼表:ftp://ftp.isu.edu.tw/Windows/Chinese/input/dayi/da3.zip 本地副本

大易四碼表:ftp://ftp.isu.edu.tw/Windows/Chinese/input/dayi/dayi13053.rar 本地副本

註:也可到 opensource.nchc.org.tw 下載,但因有授權聲明所以本人就不採用它了!需要的人請自行下載作業!

大易三碼表:http://opensource.nchc.org.tw/odp/others/OXIM/cin_tables/dayi3.cin.gz 本地副本

大易四碼表:http://opensource.nchc.org.tw/odp/others/OXIM/cin_tables/dayi4.cin.gz 本地副本

可參考 gcin_大易輸入法的問題

重製字根表 for IBus

利用底下的指令取得字根表,並且將字根表的空白改為tab,並且加上權重,然後將所有的大寫字母改為小寫字母

awk '/\%chardef begin/{f=1;next}/\%chardef end/{exit}f' dayi4.cin | awk '{count[$1]++}{print $1"\t"$2"\t"101-count[$1]}' | tr '[A-Z]' '[a-z]' > dayi4.txt

修改 template.txt

準備修改template.txt表頭資料,加上大易的相關資料,有修改的地方如下

### 利用 uuidgen 指令產生一組UUID後貼到這裡.
UUID = 730a0da0-20e9-45d9-befa-cbe59375be2d

### 可直接使用日期簡單省事
SERIAL_NUMBER = 20121010

### 出現的圖示,這裡直接使用內建的圖型,可自己另行設計
ICON = cb-mode.svg

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

### the gettext tools in runtime as 中.
STATUS_PROMPT = 易

### Valid input chars.
VALID_INPUT_CHARS = ,./;'1234567890-abcdefghijklmnopqrstuvwxyz

BEGIN_TABLE

END_TABlE

### 把最後三行加上三個#號,表示註解,也就是不要用它啦
### BEGIN_GOUCI
### character_1 goucima_1
### character_1 goucima_2
### END_GOUCI

加入字根

將第2項做出來的檔案資料dayi4.txt的所有內容,複製貼上拷貝到template.txt中的BEGIN_TABLE和END_TABLE之間。做好之後假設存檔命名為dayi4_ibus.txt。

產生 IBus 字根檔

ibus-table-createdb -s dayi4_ibus.txt -n dayi4.db

重啟 IBus - 完成

將做出來的dayi4.db拷貝到/usr/share/ibus-table/tables底下

重新啟動 IBus 並在 IBus 偏好設定上加入新輸入法就可以了。

Sample File

os/linux/ibus_大易輸入法的問題.txt · 上一次變更: 2019/11/16 08:12 (外部編輯)