Skip to content

Instantly share code, notes, and snippets.

@amorphobia
Created November 5, 2023 09:24
Show Gist options
  • Save amorphobia/79f7e1a0d8bc4b524b1bee3d3d4c12c7 to your computer and use it in GitHub Desktop.
Save amorphobia/79f7e1a0d8bc4b524b1bee3d3d4c12c7 to your computer and use it in GitHub Desktop.
格道双拼-仓
# Rime schema
# encoding: utf-8
schema:
schema_id: gedao
name: 格道双拼
version: "1.0.0"
author:
- fkxxyz (四叶草拼音词库)
- 吅吅大牛 (格道17键双拼布局)
- amorphobia
description: |
格道双拼
由四叶草拼音词库、格道17键双拼布局共同驱动
dependencies:
- clover
switches:
- name: ascii_mode
reset: 0
states: [ "中", "英" ]
- name: full_shape
states: [ "半", "全" ]
- name: zh_simp_s2t
reset: 0
states: [ "简", "繁" ]
- name: emoji
reset: 1
states: [ "🈚️", "🈶️" ]
- name: symbols
reset: 1
states: [ "无", "符" ]
engine:
processors:
- ascii_composer
- recognizer
- key_binder
- speller
- punctuator
- selector
- navigator
- express_editor
segmentors:
- ascii_segmentor
- matcher
- abc_segmentor
- punct_segmentor
- fallback_segmentor
translators:
- punct_translator
- script_translator
- table_translator@user_phrases
filters:
- simplifier
- simplifier@emoji
- simplifier@symbols
- uniquifier
- lua_filter@*gedao_filter
speller:
alphabet: "zscfwmldynjtpqgbxviu"
initials: "zscfwmldynjtpqgbx"
delimiter: " 'viu"
algebra:
- xform/^([jqxy])u$/$1v/
- xform/^zh/Z/
- xform/^sh/S/
- xform/^ch/C/
- xform/^z/F/
- xform/^s/W/
- xform/^c/M/
- xform/^h/N/
- xform/^r/T/
- xform/^k/P/
- xform/^([aoe])([iounr])/Q$1$2/
- xform/^([aoe])(ng?)?/Q$1$2/
- xform/iang/Z/
- xform/uang/Q/
- xform/ang/F/
- xform/ian/Q/
- xform/uan/M/
- xform/an/W/
- xform/uai/P/
- xform/ai/L/
- xform/iao/X/
- xform/ao/B/
- xform/ia/C/
- xform/ua/F/
- xform/a/C/
- xform/iong/B/
- xform/ong/T/
- xform/ou/X/
- xform/uo/Y/
- xform/o/M/
- xform/eng/S/
- xform/en/Z/
- xform/ei/P/
- xform/er/F/
- xform/ie/S/
- xform/ue/L/
- xform/ve/X/
- xform/e/N/
- xform/ing/Y/
- xform/in/G/
- xform/iu/T/
- xform/ui/G/
- xform/i/J/
- xform/un/P/
- xform/u/D/
- xform/v/M/
- xlit/ZSCFWMLDYNJTPQGBX/zscfwmldynjtpqgbx/
translator:
dictionary: clover
# prism: clover
# enable_sentence: true
# enable_user_dict: true
# enable_encoder: true
# enable_commit_history: true
# enable_completion: true
# db_class: tabledb
user_phrases:
dictionary: ""
user_dict: gedao_user
db_class: tabledb
enable_sentence: false
initial_quality: 0
punctuator:
import_preset: default
key_binder:
import_preset: default
simplifier:
option_name: zh_simp_s2t
opencc_config: s2tg.json
emoji:
opencc_config: emoji.json
option_name: emoji
tips: all
symbols:
opencc_config: symbol.json
option_name: symbols
tips: all
recodnizer:
import_preset: default
menu:
page_size: 9
local function pinyin_to_shuangpin(py)
if not py then
return nil
end
py = py:gsub("^([jqxy])u$", "%1v")
py = py:gsub("^zh", "Z")
py = py:gsub("^sh", "S")
py = py:gsub("^ch", "C")
py = py:gsub("^z", "F")
py = py:gsub("^s", "W")
py = py:gsub("^c", "M")
py = py:gsub("^h", "N")
py = py:gsub("^r", "T")
py = py:gsub("^k", "P")
py = py:gsub("^([aoe])([iounr])", "Q%1%2")
py = py:gsub("^([aoe])(ng?)", "Q%1%2")
py = py:gsub("^([aoe])", "Q%1")
py = py:gsub("iang", "Z")
py = py:gsub("uang", "Q")
py = py:gsub("ang", "F")
py = py:gsub("ian", "Q")
py = py:gsub("uan", "M")
py = py:gsub("an", "W")
py = py:gsub("uai", "P")
py = py:gsub("ai", "L")
py = py:gsub("iao", "X")
py = py:gsub("ao", "B")
py = py:gsub("ia", "C")
py = py:gsub("ua", "F")
py = py:gsub("a", "C")
py = py:gsub("iong", "B")
py = py:gsub("ong", "T")
py = py:gsub("ou", "X")
py = py:gsub("uo", "Y")
py = py:gsub("o", "M")
py = py:gsub("eng", "S")
py = py:gsub("en", "Z")
py = py:gsub("ei", "P")
py = py:gsub("er", "F")
py = py:gsub("ie", "S")
py = py:gsub("ue", "L")
py = py:gsub("ve", "X")
py = py:gsub("e", "N")
py = py:gsub("ing", "Y")
py = py:gsub("in", "G")
py = py:gsub("iu", "T")
py = py:gsub("ui", "G")
py = py:gsub("i", "J")
py = py:gsub("un", "P")
py = py:gsub("u", "D")
py = py:gsub("v", "M")
return py:lower()
end
local function correct_preedit(text, inp, db)
if not db then
return nil
end
if inp:len() < 2 then
return nil
end
local inp = inp:sub(1, 2)
local lookup = db:lookup(text)
for pinyin in lookup:gmatch("(%w+)%s?") do
local shuangpin = pinyin_to_shuangpin(pinyin)
if shuangpin and shuangpin == inp then
pinyin = pinyin:gsub("lv", "lü")
pinyin = pinyin:gsub("nv", "nü")
return pinyin
end
end
return nil
end
local function filter(input, env)
local input_text = env.engine.context.input
for cand in input:iter() do
local cand_inp = input_text:sub(cand.start + 1, cand._end)
if utf8.len(cand.text) == 1 then
local preedit = correct_preedit(cand.text, cand_inp, env.pinyin_db)
if preedit then
if cand_inp:len() > 2 then
preedit = preedit .. "." .. cand_inp:sub(3)
end
if cand._end < input_text:len() then
preedit = preedit .. " "
end
cand:get_genuine().preedit = preedit
end
else
-- assume phrases do not have any strokes
local preedit = ""
local i = 0
for text in cand.text:gmatch(utf8.charpattern) do
i = i + 1
local inp = cand_inp:sub(i*2-1, i*2)
local char_preedit = correct_preedit(text, inp, env.pinyin_db)
if char_preedit and preedit:len() > 0 then
preedit = preedit .. " "
end
if char_preedit then
preedit = preedit .. char_preedit
else
preedit = preedit .. inp
end
end
cand.preedit = preedit
end
yield(cand)
end
end
local function init(env)
env.pinyin_db = ReverseDb("build/clover.reverse.bin")
end
return { init = init, func = filter }
keyboards:
- name: 格道
rows:
- keys:
- action: character(z)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: zh
swipe:
- action: character(1)
label: en
display: true
processByRIME: true
direction: up
- action: character(!)
label: iang
display: true
processByRIME: true
direction: down
- action: tab
display: true
processByRIME: true
direction: right
- action: character(s)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: sh
swipe:
- action: character(2)
label: eng
display: true
processByRIME: true
direction: up
- action: character(@)
label: ie
display: true
processByRIME: true
direction: down
- action: shortCommand(#上个输入方案)
display: true
processByRIME: true
direction: left
- action: shortCommand(#RimeSwitcher)
display: true
processByRIME: true
direction: right
- action: character(c)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: ch
swipe:
- action: character(3)
label: a
display: true
processByRIME: true
direction: up
- action: character(#)
label: ia
display: true
processByRIME: true
direction: down
- action: none
width:
portrait: percentage(0.01)
landscape: percentage(0.1)
- action: character(f)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: z f
swipe:
- action: character(0)
label: ang
display: true
processByRIME: true
direction: up
- action: character())
label: ua er
display: true
processByRIME: true
direction: down
- action: character(w)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: s w
swipe:
- action: character(-)
label: an
display: true
processByRIME: true
direction: up
- action: character(_)
display: false
processByRIME: true
direction: down
- action: character(m)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: c m
swipe:
- action: character(=)
label: o
display: true
processByRIME: true
direction: up
- action: character(+)
label: uan ü
display: true
processByRIME: true
direction: down
- keys:
- action: character(l)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: l
swipe:
- action: character(4)
label: ue
display: true
processByRIME: true
direction: up
- action: character($)
label: ai
display: true
processByRIME: true
direction: down
- action: character(`)
display: true
processByRIME: true
direction: right
- action: character(d)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: d
swipe:
- action: character(5)
label: u
display: true
processByRIME: true
direction: up
- action: character(%)
display: false
processByRIME: true
direction: down
- action: character(y)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: y
swipe:
- action: character(6)
label: ing
display: true
processByRIME: true
direction: up
- action: character(^)
label: uo
display: true
processByRIME: true
direction: down
- action: none
width:
portrait: percentage(0.01)
landscape: percentage(0.1)
- action: character(n)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: n h
swipe:
- action: character([)
label: e
display: true
processByRIME: true
direction: up
- action: character({)
display: false
processByRIME: true
direction: down
- action: character(j)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: j
swipe:
- action: character(])
label: i
display: true
processByRIME: true
direction: up
- action: character(})
display: false
processByRIME: true
direction: down
- action: character(t)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: t r
swipe:
- action: character(\)
label: ong
display: true
processByRIME: true
direction: up
- action: character(|)
label: iu
display: true
processByRIME: true
direction: down
- keys:
- action: character(p)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: p k
swipe:
- action: character(7)
label: ei
display: true
processByRIME: true
direction: up
- action: character(&)
label: un uai
display: true
processByRIME: true
direction: down
- action: character(~)
display: true
processByRIME: true
direction: right
- action: character(q)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: q '
swipe:
- action: character(8)
label: ian
display: true
processByRIME: true
direction: up
- action: character(*)
label: uang
display: true
processByRIME: true
direction: down
- action: character(g)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: g
swipe:
- action: character(9)
label: in
display: true
processByRIME: true
direction: up
- action: character(()
label: ui
display: true
processByRIME: true
direction: down
- action: none
width:
portrait: percentage(0.01)
landscape: percentage(0.1)
- action: character(b)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: b
swipe:
- action: character(<)
label: iong
display: true
processByRIME: true
direction: up
- action: character(>)
label: ao
display: true
processByRIME: true
direction: down
- action: character(x)
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
label: x
swipe:
- action: character(;)
label: iao
display: true
processByRIME: true
direction: up
- action: character(:)
label: ou üe
display: true
processByRIME: true
direction: down
- action: character(')
display: true
processByRIME: true
direction: left
- action: character(")
display: true
processByRIME: true
direction: right
- action: backspace
width:
portrait: percentage(0.165)
landscape: percentage(0.1)
swipe:
- action: shortCommand(#重输)
display: true
processByRIME: true
direction: left
- keys:
- action: keyboardType(alphabetic)
width:
portrait: percentage(0.2)
landscape: percentage(0.1)
swipe:
- action: keyboardType(custom(36键))
display: true
processByRIME: true
direction: up
- action: keyboardType(numericNineGrid)
display: true
processByRIME: true
direction: right
- action: character(,)
width: percentage(0.1)
swipe:
- action: character(.)
display: true
processByRIME: true
direction: up
- action: space
width:
portrait: percentage(0.4)
landscape: percentage(0.1)
swipe:
- action: shortCommand(#次选上屏)
display: true
processByRIME: true
direction: up
- action: shortCommand(#左移)
display: true
processByRIME: true
direction: left
- action: shortCommand(#右移)
display: true
processByRIME: true
direction: right
- action: character(/)
width: percentage(0.1)
swipe:
- action: character(?)
display: true
processByRIME: true
direction: up
- action: enter
width:
portrait: percentage(0.2)
landscape: percentage(0.1)
swipe:
- action: shortCommand(#换行)
display: true
processByRIME: true
direction: up
buttonInsets: left(3),bottom(4),top(8),right(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment