Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
- Remove 'reset' from switches
- Remove moran_patches.yaml
- Remove *.defaults.yaml
- Merge key_bindings into moran.yaml
- Merge algebra into moran.yaml
- Add punctuation.yaml
- Update make_simp_dist.sh
  + Accomodate previously mentioned changes
  + Account for 'simplification' opencc option
  • Loading branch information
ksqsf committed Jan 15, 2024
1 parent ced1406 commit 6c5bc09
Show file tree
Hide file tree
Showing 16 changed files with 475 additions and 305 deletions.
3 changes: 3 additions & 0 deletions default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ switcher:
- zh_hant
- zh_hans
- zh_hant_tw
- emoji
- inflexible
- unicode_comment
fold_options: true
abbreviate_options: true
option_list_separator: ''
Expand Down
67 changes: 67 additions & 0 deletions key_bindings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Rime key bindings
# encoding: utf-8

emacs_editing:
__append:
- { when: composing, accept: Control+p, send: Up }
- { when: composing, accept: Control+n, send: Down }
- { when: composing, accept: Control+b, send: Left }
- { when: composing, accept: Control+f, send: Right }
- { when: composing, accept: Control+a, send: Home }
- { when: composing, accept: Control+e, send: End }
- { when: composing, accept: Control+d, send: Delete }
- { when: composing, accept: Control+k, send: Shift+Delete }
- { when: composing, accept: Control+h, send: BackSpace }
- { when: composing, accept: Control+g, send: Escape }
- { when: composing, accept: Control+bracketleft, send: Escape }
- { when: composing, accept: Control+y, send: Page_Up }
- { when: composing, accept: Alt+v, send: Page_Up }
- { when: composing, accept: Control+v, send: Page_Down }

move_by_word_with_tab:
__append:
- { when: composing, accept: ISO_Left_Tab, send: Shift+Left }
- { when: composing, accept: Shift+Tab, send: Shift+Left }
- { when: composing, accept: Tab, send: Shift+Right }

paging_with_minus_equal:
__append:
- { when: has_menu, accept: minus, send: Page_Up }
- { when: has_menu, accept: equal, send: Page_Down }

paging_with_comma_period:
__append:
- { when: paging, accept: comma, send: Page_Up }
- { when: has_menu, accept: period, send: Page_Down }

paging_with_brackets:
__append:
- { when: paging, accept: bracketleft, send: Page_Up }
- { when: has_menu, accept: bracketright, send: Page_Down }

numbered_mode_switch:
__append:
- { when: always, accept: Control+Shift+1, select: .next }
- { when: always, accept: Control+Shift+2, toggle: ascii_mode }
- { when: always, accept: Control+Shift+3, toggle: full_shape }
- { when: always, accept: Control+Shift+4, toggle: simplification }
- { when: always, accept: Control+Shift+5, toggle: extended_charset }
- { when: always, accept: Control+Shift+exclam, select: .next }
- { when: always, accept: Control+Shift+at, toggle: ascii_mode }
- { when: always, accept: Control+Shift+numbersign, toggle: full_shape }
- { when: always, accept: Control+Shift+dollar, toggle: simplification }
- { when: always, accept: Control+Shift+percent, toggle: extended_charset }

windows_compatible_mode_switch:
__append:
- { when: always, accept: Shift+space, toggle: full_shape }
- { when: always, accept: Control+period, toggle: ascii_punct }

optimized_mode_switch:
__append:
- { when: always, accept: Control+Shift+space, select: .next }
- { when: always, accept: Shift+space, toggle: ascii_mode }
- { when: always, accept: Control+comma, toggle: full_shape }
- { when: always, accept: Control+period, toggle: ascii_punct }
- { when: always, accept: Control+slash, toggle: simplification }
- { when: always, accept: Control+backslash, toggle: extended_charset }
6 changes: 3 additions & 3 deletions lua/moran_express_translator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ function top.func(input, seg, env)

local input_len = utf8.len(input)
local fixed_triggered = false
local flexible = env.engine.context:get_option("flexible")
local inflexible = env.engine.context:get_option("inflexible")
local indicator = env.quick_code_indicator

-- 用戶尚未選過字時,調用碼表。
if (env.engine.context.input == input) then
local fixed_res = env.fixed:query(input, seg)
-- 如果輸入長度爲 4,只輸出 2 字詞。
-- 僅在 not flexible (固詞模式)時才產生這些輸出。
-- 僅在 inflexible (固詞模式)時才產生這些輸出。
if fixed_res ~= nil then
if (input_len == 4) then
if (not flexible) then
if inflexible then
for cand in fixed_res:iter() do
local cand_len = utf8.len(cand.text)
if (cand_len == 2) then
Expand Down
4 changes: 0 additions & 4 deletions lua/moran_quick_code_hint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ local Module = {}

function Module.init(env)
env.enable_quick_code_hint = env.engine.schema.config:get_bool("moran/enable_quick_code_hint")
log.error("moran_quick_code_hint: init " .. tostring(env.enable_quick_code_hint))
if env.enable_quick_code_hint then
-- The user might have changed it.
local dict = env.engine.schema.config:get_string("fixed/dictionary")
log.error("moran_quick_code_hint: using dict" .. dict)
env.quick_code_hint_reverse = ReverseLookup(dict)
log.error("moran_quick_code_hint: enabled")
else
env.quick_code_hint_reverse = nil
log.error("moran_quick_code_hint: disabled")
end

env.quick_code_indicator = env.engine.schema.config:get_string("moran/quick_code_indicator")
Expand Down
24 changes: 18 additions & 6 deletions make_simp_dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,30 @@ sedi () {

# 替換碼表
echo 替換碼表...
sedi 's|\&dict moran_fixed|\&dict moran_fixed_simp|' moran_fixed.defaults.yaml
sedi 's|fixed/dictionary: moran_fixed|fixed/dictionary: moran_fixed_simp|' moran.defaults.yaml
cat > moran_fixed.custom.yaml <<EOF
patch:
translator/dictionary: &dict moran_fixed_simp
fixed/dictionary: *dict
zkci/dictionary: *dict
EOF
cat > moran.custom.yaml <<EOF
patch:
fixed/dictionary: moran_fixed_simp
EOF

# 替换简体语法模型
echo 替换简体语法模型...
wget 'https://github.com/lotem/rime-octagram-data/raw/hans/zh-hans-t-essay-bgc.gram' -O zh-hans-t-essay-bgc.gram
wget 'https://github.com/lotem/rime-octagram-data/raw/hans/zh-hans-t-essay-bgw.gram' -O zh-hans-t-essay-bgw.gram
rm zh-hant-t-essay-bg{c,w}.gram
for f in *.defaults.yaml
do
sedi 's/zh-hant-t-essay-bgw/zh-hans-t-essay-bgw/' $f
sedi 's/zh-hant-t-essay-bgc/zh-hans-t-essay-bgc/' $f
sedi 's/zh-hant-t-essay-bgw/zh-hans-t-essay-bgw/' moran.yaml
sedi 's/zh-hant-t-essay-bgc/zh-hans-t-essay-bgc/' moran.yaml

# 替换 simplification 为 traditionalization
for f in *.schema.yaml; do
sedi 's/simplification/traditionalization/' $f
sedi 's/漢字, 汉字/汉字, 漢字/' $f
sedi 's/moran_t2s.json/s2t.json/' $f
done

cd ..
Expand Down
77 changes: 0 additions & 77 deletions moran.defaults.yaml

This file was deleted.

112 changes: 53 additions & 59 deletions moran.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
schema:
schema_id: moran
name: 魔然
version: "20231125"
version: "20240115"
author:
- 自然碼發明人:周志農
- 方案製作:ksqsf
Expand All @@ -27,14 +27,14 @@ switches:
states: [ 漢字, 汉字 ]
- name: ascii_punct
states: [ 。,, ., ]
- options: [ utf8, gbk+emoji, big5+emoji ]
reset: 1
states: [ UTF-8, GBK, BIG5 ]
- name: flexible
states: [ 固詞, 動詞 ] # 「固詞」表示「固頂詞」
reset: 1
- options: [ gbk+emoji, utf8, big5+emoji ]
states: [ GBK, UTF-8, BIG5 ]
- name: inflexible
states: [ 動詞, 固詞 ] # 「固詞」表示「固頂詞」
# 默認情況下,輸入 4 碼時,會禁止碼表輸出(「動詞」模式)。
# 這是因爲碼表最大碼長爲 4,可能會產生較低頻的多字詞,覆蓋過用戶自造的常用詞語。
# 當固詞模式啓動後,輸入 4 碼時會優先輸出碼表中的二字詞,這些輸出帶有「⚡️」標記。
- name: emoji
reset: 1
states: [ 🈚, 🈶 ]
- name: unicode_comment
states: [ U關, U開 ]
Expand Down Expand Up @@ -91,11 +91,12 @@ speller:
alphabet: abcdefghijklmnopqrstuvwxyz
delimiter: " '"
algebra:
- derive/^(.+);(\w)(\w)$/$1$2$3o/ # 全碼 YYXXo
- abbrev/^(.+);(\w)(\w)$/$1$2$3/ # 降低 YYXX 優先級
- derive/^(.+);(\w)(\w)$/$1$2/ # 構詞可以用 YYX
- derive/^(.+);(\w)(\w)$/$1/ # 構詞可以用 YY
#- abbrev/^([a-z]).+$/$1/ # 首字母簡拼(※ 嚴重影響出字速度,不建議開啓)
__patch:
- moran:/algebra/user_force_top?
- moran:/algebra/user_sentence_top?
- moran:/algebra/generate_code
- moran:/algebra/user_sentence_bottom?
- moran:/algebra/user_force_bottom?

translator: # 整句輸入模式設置,在 top_translator 中被調用
dictionary: moran.extended
Expand All @@ -108,8 +109,8 @@ translator: # 整句輸入模式設置,在 top_translator 中被調用
- xform/([a-z][a-z][a-z][a-z])o/$1°/

fixed: # 固頂輸入模式設置,在 top_translator 中被調用
initial_quality: 100
dictionary: moran_fixed
initial_quality: 100
enable_completion: false
enable_sentence: false
enable_user_dict: false
Expand Down Expand Up @@ -146,6 +147,10 @@ japanese:
comment_format:
- xform/.*//

simplifier:
option_name: simplification
opencc_config: moran_t2s.json

emoji:
opencc_config: moran_emoji.json
option_name: emoji
Expand Down Expand Up @@ -224,40 +229,10 @@ punctuator:
key_binder:
import_preset: default
bindings:
- {when: has_menu, accept: "Control+s", toggle: simplification}
- {when: has_menu, accept: "Control+u", toggle: unicode_comment}
- {when: has_menu, accept: "Control+q", toggle: emoji} # q 表示表情,讓出 Ctrl+e
- {when: has_menu, accept: "Control+Shift+0", toggle: std_opencc}
#- {when: has_menu, accept: semicolon, send: "2"} # 被 moran_semicolon_processor 替換
- {when: has_menu, accept: "Tab", send: "Control+Right"}
- {when: composing, accept: "Tab", send: "Control+Right"}
- {when: has_menu, accept: Shift+A, send_sequence: "{Control+Left}a{Control+Right}"}
- {when: has_menu, accept: Shift+B, send_sequence: "{Control+Left}b{Control+Right}"}
- {when: has_menu, accept: Shift+C, send_sequence: "{Control+Left}c{Control+Right}"}
- {when: has_menu, accept: Shift+D, send_sequence: "{Control+Left}d{Control+Right}"}
- {when: has_menu, accept: Shift+E, send_sequence: "{Control+Left}e{Control+Right}"}
- {when: has_menu, accept: Shift+F, send_sequence: "{Control+Left}f{Control+Right}"}
- {when: has_menu, accept: Shift+G, send_sequence: "{Control+Left}g{Control+Right}"}
- {when: has_menu, accept: Shift+H, send_sequence: "{Control+Left}h{Control+Right}"}
- {when: has_menu, accept: Shift+I, send_sequence: "{Control+Left}i{Control+Right}"}
- {when: has_menu, accept: Shift+J, send_sequence: "{Control+Left}j{Control+Right}"}
- {when: has_menu, accept: Shift+K, send_sequence: "{Control+Left}k{Control+Right}"}
- {when: has_menu, accept: Shift+L, send_sequence: "{Control+Left}l{Control+Right}"}
- {when: has_menu, accept: Shift+M, send_sequence: "{Control+Left}m{Control+Right}"}
- {when: has_menu, accept: Shift+N, send_sequence: "{Control+Left}n{Control+Right}"}
- {when: has_menu, accept: Shift+O, send_sequence: "{Control+Left}o{Control+Right}"}
- {when: has_menu, accept: Shift+P, send_sequence: "{Control+Left}p{Control+Right}"}
- {when: has_menu, accept: Shift+Q, send_sequence: "{Control+Left}q{Control+Right}"}
- {when: has_menu, accept: Shift+R, send_sequence: "{Control+Left}r{Control+Right}"}
- {when: has_menu, accept: Shift+S, send_sequence: "{Control+Left}s{Control+Right}"}
- {when: has_menu, accept: Shift+T, send_sequence: "{Control+Left}t{Control+Right}"}
- {when: has_menu, accept: Shift+U, send_sequence: "{Control+Left}u{Control+Right}"}
- {when: has_menu, accept: Shift+V, send_sequence: "{Control+Left}v{Control+Right}"}
- {when: has_menu, accept: Shift+W, send_sequence: "{Control+Left}w{Control+Right}"}
- {when: has_menu, accept: Shift+X, send_sequence: "{Control+Left}x{Control+Right}"}
- {when: has_menu, accept: Shift+Y, send_sequence: "{Control+Left}y{Control+Right}"}
- {when: has_menu, accept: Shift+Z, send_sequence: "{Control+Left}z{Control+Right}"}
- {when: has_menu, accept: Shift+BackSpace, send_sequence: "{Control+Left}{BackSpace}{Control+Right}"}
__patch:
- moran:/key_bindings/moran_capital_for_last_syllable
- moran:/key_bindings/moran_tab
- moran:/key_bindings/moran_switches

recognizer:
import_preset: default
Expand All @@ -269,19 +244,38 @@ recognizer:
reverse_zrlf: "^olf[A-Za-z]*$"
punct: '^/([0-9]0?|[A-Za-z]+)$'

moran: # 兜底默認值;以防用戶不提供任何值
moran:
# 簡快碼提示符
# 修改爲 "" 可取消提示符
# 建議在熟悉簡碼後再取消
quick_code_indicator: "⚡️"

# 詞輔功能
# 當輸入二字或三字詞時,允許末輸入篩選詞語。
# 例如輸入 lmjxz 可以篩選「連接」。
# 但是與字輔輸入方法不同,詞輔在生效後 *不能* 在句末繼續輸入形成整
# 句——這個功能僅用於「篩選」。因此,這個功能僅適合習慣於以詞語爲單
# 位輸入的用戶。
enable_word_filter: false
enable_aux_hint: false
enable_quick_code_hint: false

# 「出簡讓全」相關設置
# 當一個字具有簡碼時,打其全碼(不論是 yyxx 還是 yyxxo)都會導致該
# 字讓出首位,而被推遲到後位。
ijrq:
enable: true
#defer: 5
show_hint: false
suffix: 'o'
enable: true # 是否啓用出簡讓全?
#defer: 5 # 延遲多少位?若不設置该项,則默認值是推遲到第二頁
show_hint: true # 若讓全,則提示簡碼打法

__patch:
- moran.defaults.yaml:/patch?
- moran_patches.yaml:/fix_opencc_t2s?
- moran.custom.yaml:/patch?
# 單字輔助碼提示
# 注:會顯示出所有可能的輔助碼
enable_aux_hint: false

# 簡快碼提示(包括字和詞)
# 例如 輸入 yy te er 英特爾 會提示「⚡yte」,即使用 yte 可以打出這個詞
enable_quick_code_hint: false

# 默認啓用語言模型
__include: moran:/octagram/enable_for_sentence
# 若要禁用,在 custom 文件中寫入:
# patch:
# __include: moran:/octagram/disable
Loading

0 comments on commit 6c5bc09

Please sign in to comment.