Skip to content

Commit

Permalink
feat: reverse lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
halfmoonvic committed Feb 25, 2023
1 parent 16fc331 commit 17f5f85
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 25 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ var:
previously_selected_schema: luna_pinyin # 输入方案为朙月拼音
```
# [schema](https://github.com/rime/home/wiki/RimeWithSchemata#%E8%A9%B3%E8%A7%A3%E8%BC%B8%E5%85%A5%E6%96%B9%E6%A1%88)
question:
请在较为详细的说下流程,比如我键盘敲击 “nihao“ 是怎样输出汉字 “你好” 的过程。
详细到 processors segmentors translators 里所具体采用的处理细节
ChatGPT answer:
首先,"nihao" 这个字符串将会被 Rime 的输入法框架识别并传递给 processors 模块进行处理。这里的处理可能包括字符串的预处理,比如去除首尾空格,转换为小写字母等。
接下来,字符串将会被传递给 segmentors 模块进行分词,这里的分词是指将输入字符串分成一个一个的词语。在这个例子中,"nihao" 将会被分成 "ni" 和 "hao" 两个词语。
接下来,这两个词语将会被传递给 translators 模块进行翻译,也就是将拼音翻译成汉字。在这个例子中,"ni" 和 "hao" 将会被翻译成 "你" 和 "好"。
最后,翻译完的汉字将会被传递给 selector 和 navigator 模块进行选择和导航。Selector 模块负责选择最终的词语,也就是将 "你" 和 "好" 结合成一个词语 "你好"。Navigator 模块负责根据用户的选择结果进行导航,最终将词语 "你好" 输出到屏幕上。
# reference
搜狗细胞词库 [Rime 输入法简中用户新手套餐](https://github.com/ACsediment/RimeNewbie)
Expand Down
2 changes: 1 addition & 1 deletion easy_en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ patch:
easy_en:
__include: easy_en.schema:/translator
enable_completion: true
enable_sentence: true
enable_sentence: false
initial_quality: -1
recognizer/patterns/uppercase: ""
speller/alphabet:
Expand Down
16 changes: 8 additions & 8 deletions japanese.custom.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# https://github.com/gkovacs/rime-japanese

patch:
# https://github.com/rime/rime-emoji
__include: emoji_suggestion:/patch

# https://github.com/BlindingDark/rime-easy-en
__include: easy_en:/patch
easy_en/enable_sentence: false
__include: reverse_lookup:/patch_luna_pinyin2

# import shortcut key
key_binder/import_preset: default
Expand All @@ -20,7 +17,10 @@ patch:
recognizer/patterns/number: "^/[0-9]+$"

# lua
"engine/translators/@90": lua_translator@time_translator
"engine/translators/@91": lua_translator@lunar_translator
"engine/translators/@92": lua_translator@number_translator
"engine/translators/@93": lua_translator@thousand_translator
engine/translators/@90: lua_translator@time_translator
engine/translators/@91: lua_translator@lunar_translator
engine/translators/@92: lua_translator@number_translator
engine/translators/@93: lua_translator@thousand_translator

# default 漢字 
switches/@2/reset: 0
13 changes: 5 additions & 8 deletions luna_pinyin.custom.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# https://github.com/rime/rime-luna-pinyin

patch:
# https://github.com/rime/rime-emoji
__include: emoji_suggestion:/patch

# https://github.com/BlindingDark/rime-easy-en
__include: easy_en:/patch
easy_en/enable_sentence: false
__include: reverse_lookup:/patch_japanese

# import shortcut key
key_binder/import_preset: default
Expand All @@ -20,10 +17,10 @@ patch:
recognizer/patterns/number: "^/[0-9]+$"

# lua
"engine/translators/@90": lua_translator@time_translator
"engine/translators/@91": lua_translator@lunar_translator
"engine/translators/@92": lua_translator@number_translator
"engine/translators/@93": lua_translator@thousand_translator
engine/translators/@90: lua_translator@time_translator
engine/translators/@91: lua_translator@lunar_translator
engine/translators/@92: lua_translator@number_translator
engine/translators/@93: lua_translator@thousand_translator

# load luna_pinyin dict
translator/dictionary: luna_pinyin.extended
Expand Down
68 changes: 68 additions & 0 deletions reverse_lookup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# pinyin simp reverse lookup, trigger with `P
patch_pinyin_simp:
recognizer/patterns/zlookup: "`[a-z]*'?$"
recognizer/patterns/reverse_lookup: "`P[a-z]*'?$"

reverse_lookup:
dictionary: pinyin_simp
prefix: "`P"
suffix: "'"
tips: 〔拼音〕
preedit_format:
- xform/([nl])v/$1ü/
- xform/([nl])ue/$1üe/
- xform/([jqxy])v/$1u/

# luna_pinyin reverse lookup, trigger with `P
patch_luna_pinyin:
recognizer/patterns/zlookup: "`[a-z]*'?$"
recognizer/patterns/reverse_lookup: "`P[a-z]*'?$"

reverse_lookup:
dictionary: luna_pinyin.extended
prefix: "`P"
suffix: "'"
tips: 〔lunar_pinyin〕
preedit_format:
- xform/([nl])v/$1ü/
- xform/([nl])ue/$1üe/
- xform/([jqxy])v/$1u/

# luna_pinyin reverse lookup, trigger with `p
patch_luna_pinyin2:
# to recognize '`p' to prevent it from being directly
# recognized as 'punct' and being displayed directly.
recognizer/patterns/zlookup: "`[a-z]*'?$"
# the short dash at the beginning of '_luna_pinyin_lookup' is to
# make it recognizable as the first one.
recognizer/patterns/_luna_pinyin_lookup: "`p[a-z]*'?$"

# @2 is abc_segmentor
engine/segmentors/@after 2: affix_segmentor@_luna_pinyin_lookup
engine/translators/@999: script_translator@_luna_pinyin_lookup

_luna_pinyin_lookup:
tag: _luna_pinyin_lookup
dictionary: luna_pinyin.extended
prefix: "`p"
suffix: "'"
tips: 〔朙月拼音〕
preedit_format:
- xform/([nl])v/$1ü/
- xform/([nl])ue/$1üe/
- xform/([jqxy])v/$1u/

# japanese reverse lookup, trigger with `j
patch_japanese:
recognizer/patterns/zlookup: "`[a-z]*'?$"
recognizer/patterns/_japanese_lookup: "`j[a-z]*'?$"

engine/segmentors/@after 2: affix_segmentor@_japanese_lookup
engine/translators/@999: script_translator@_japanese_lookup

_japanese_lookup:
tag: _japanese_lookup
dictionary: japanese
prefix: "`j"
suffix: "'"
tips: 〔japanese〕
13 changes: 5 additions & 8 deletions wubi86.custom.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# https://github.com/rime/rime-wubi

patch:
# https://github.com/rime/rime-emoji
__include: emoji_suggestion:/patch

# https://github.com/BlindingDark/rime-easy-en
__include: easy_en:/patch
easy_en/enable_sentence: false
__include: reverse_lookup:/patch_luna_pinyin2

# import shortcut key
key_binder/import_preset: default
Expand All @@ -20,10 +17,10 @@ patch:
recognizer/patterns/number: "^/[0-9]+$"

# lua
"engine/translators/@90": lua_translator@time_translator
"engine/translators/@91": lua_translator@lunar_translator
"engine/translators/@92": lua_translator@number_translator
"engine/translators/@93": lua_translator@thousand_translator
engine/translators/@90: lua_translator@time_translator
engine/translators/@91: lua_translator@lunar_translator
engine/translators/@92: lua_translator@number_translator
engine/translators/@93: lua_translator@thousand_translator

# 五笔回车清屏和分号、引号上屏幕二三候选词
key_binder/bindings:
Expand Down

0 comments on commit 17f5f85

Please sign in to comment.