# Rime schema
# vim: set sw=2 sts=2 et:
# encoding: utf-8

schema:
  schema_id: japanese
  name: 日本語
  version: 'v0.2'
  author:
    - ensigma96 <ensigma96@gmail.com>
  dependencies:
    - terra_pinyin.extended # for using reverse lookup
    - stroke

switches:
  - name: ascii_mode
    reset: 0
    states: [ 中文, 西文 ]
  - name: full_shape
    states: [ 半角, 全角 ]
  - name: simplification
    states: [ 漢字, 汉字 ]
    reset: 0
  #- options: [jp_variants, zh_simp, zh_tw ]
  #- options: [zh_simp, zh_tw ]
  #  reset: 0
  #  states:
  #    #- 字形 → 日本
  #    - 字形 → 大陸
  #    - 字形 → 台灣
  - name: ascii_punct
    states: [ 。，, ．， ]

engine:
  processors:
    - ascii_composer
    - recognizer
    - key_binder
    - speller
    - punctuator
    - selector
    - navigator
    - express_editor
  segmentors:
    - ascii_segmentor
    - matcher
    - abc_segmentor
    - affix_segmentor@putonghua_to_kanji_lookup
    - affix_segmentor@hannom_lookup
    - affix_segmentor@hanja_lookup
    - punct_segmentor
    - fallback_segmentor
  translators:
    - punct_translator
    - script_translator
    - reverse_lookup_translator
    - script_translator@putonghua_to_kanji_lookup
    - script_translator@hannom_lookup
    - script_translator@hanja_lookup
  filters:
    - simplifier
    #- simplifier@jp_variants
    #- simplifier@zh_simp
    #- simplifier@zh_tw
    - uniquifier
    - reverse_lookup_filter@putonghua_to_kanji_reverse_lookup
    - reverse_lookup_filter@hannom_reverse_lookup
    - reverse_lookup_filter@hanja_reverse_lookup

speller:
  alphabet: 'zyxwvutsrqponmlkjihgfedcba-_'
  delimiter: " '"
  algebra:
    - 'derive/_/x/'
    - 'derive/-/q/'
    # Add / remove rules the as you wish
    - 'derive/i_e/ye/'
    # - 'derive/fu/hu/'

translator:
  dictionary: japanese
  spelling_hints: 5
  comment_format:
    - 'xlit|q|ー|'
  preedit_format:
    - 'xlit|q|ー|'

putonghua_to_kanji_lookup:
  tag: putonghua_to_kanji_lookup
  prefix: "`"  # 獨用jyutping_lookup反查在反查鍵「`」之後再鍵入〔大寫〕「J」
  dictionary: terra_pinyin.extended
  prism: td_pinyin_flypy
  preedit_format:
    - xform/([bpmfdtnljqx])n/$1iao/
    - xform/(\w)g/$1eng/
    - xform/(\w)q/$1iu/
    - xform/(\w)w/$1ei/
    - xform/([dtnlgkhjqxyvuirzcs])r/$1uan/
    - xform/(\w)t/$1ve/
    - xform/(\w)y/$1un/
    - xform/([dtnlgkhvuirzcs])o/$1uo/
    - xform/(\w)p/$1ie/
    - xform/([jqx])s/$1iong/
    - xform/(\w)s/$1ong/
    - xform/(\w)d/$1ai/
    - xform/(\w)f/$1en/
    - xform/(\w)h/$1ang/
    - xform/(\w)j/$1an/
    - xform/([gkhvuirzcs])k/$1uai/
    - xform/(\w)k/$1ing/
    - xform/([jqxnl])l/$1iang/
    - xform/(\w)l/$1uang/
    - xform/(\w)z/$1ou/
    - xform/([gkhvuirzcs])x/$1ua/
    - xform/(\w)x/$1ia/
    - xform/(\w)c/$1ao/
    - xform/([dtgkhvuirzcs])v/$1ui/
    - xform/(\w)b/$1in/
    - xform/(\w)m/$1ian/
    - xform/([aoe])\1(\w)/$1$2/
    - "xform/(^|[ '])v/$1zh/"
    - "xform/(^|[ '])i/$1ch/"
    - "xform/(^|[ '])u/$1sh/"
    - xform/([nl])v/$1ü/
    - xform/([nl])ue/$1üe/
    - xform/([jqxy])v/$1u/
    - xform/eh/ê/
    - 'xform ([aeiou])(ng?|r)([-;/<,>\\.]) $1$3$2'
    - 'xform ([aeo])([iuo])([-;/<,>\\.]) $1$3$2'
    - 'xform a[-;] ā'
    - 'xform a/ á'
    - 'xform a[<,] ǎ'
    - 'xform a[>\\.] à'
    - 'xform e[-;] ē'
    - 'xform e/ é'
    - 'xform e[<,] ě'
    - 'xform e[>\\.] è'
    - 'xform o[-;] ō'
    - 'xform o/ ó'
    - 'xform o[<,] ǒ'
    - 'xform o[>\\.] ò'
    - 'xform i[-;] ī'
    - 'xform i/ í'
    - 'xform i[<,] ǐ'
    - 'xform i[>\\.] ì'
    - 'xform u[-;] ū'
    - 'xform u/ ú'
    - 'xform u[<,] ǔ'
    - 'xform u[>\\.] ù'
    - 'xform ü[-;] ǖ'
    - 'xform ü/ ǘ'
    - 'xform ü[<,] ǚ'
    - 'xform ü[>\\.] ǜ'
  comment_format:
    - xform ([aeiou])(ng?|r)([1234]) $1$3$2
    - xform ([aeo])([iuo])([1234]) $1$3$2
    - xform a1 ā
    - xform a2 á
    - xform a3 ǎ
    - xform a4 à
    - xform e1 ē
    - xform e2 é
    - xform e3 ě
    - xform e4 è
    - xform o1 ō
    - xform o2 ó
    - xform o3 ǒ
    - xform o4 ò
    - xform i1 ī
    - xform i2 í
    - xform i3 ǐ
    - xform i4 ì
    - xform u1 ū
    - xform u2 ú
    - xform u3 ǔ
    - xform u4 ù
    - xform v1 ǖ
    - xform v2 ǘ
    - xform v3 ǚ
    - xform v4 ǜ
    - xform/([nljqxy])v/$1ü/
    - xform/eh[0-5]?/ê/
    - xform/([a-z]+)[0-5]/$1/
  tips: 【普查日】
  #closing_tips: 【粵拼】

putonghua_to_kanji_reverse_lookup:
  tags: [ putonghua_to_kanji_lookup ]
  dictionary: japanese
  spelling_hints: 10
  comment_format:
    - 'xlit|q|ー|'
  preedit_format:
    - 'xlit|q|ー|'

# simplifier:
#  option_name: jp_variants
#  opencc_config: jp_t2s.json

reverse_lookup:
  dictionary: stroke
  enable_completion: true
  prefix: "`H"
  suffix: "`"
  tips: 〔筆畫〕
  preedit_format:
    - xlit/hspnz/一丨丿丶乙/
  comment_format:
    - 'xlit|q|ー|'

hannom_lookup:
  tag: hannom_lookup
  prefix: "`V"  # 獨用jyutping_lookup反查在反查鍵「`」之後再鍵入〔大寫〕「J」
  suffix: "`"
  dictionary: hannomPS
  preedit_format:
    - 'xform ([aeiouâăôê])(ng|nh|ch)([sfjxr]) $1$3$2'
    - 'xform ([aeiouâăôê])([iunptcmy])([sfjxr]) $1$3$2'
    - 'xform ([ae])([ou])([sfjxr]) $1$3$2'
    - 'xform (aw|ow|uw)([iunptcmy])([sfjxr]) $1$3$2'
    - 'xform (aw|ow|uw)(ng|nh|ch)([sfjxr]) $1$3$2'
    - 'xform z '
    #- 'xform , '
    - 'xform A 　'
    - 'xform dd đ'
    - 'xform aa â'
    - 'xform âs ấ'
    - 'xform âf ầ'
    - 'xform âj ậ'
    - 'xform âx ẫ'
    - 'xform âr ẩ'
    - 'xform aw ă'
    - 'xform ăs ắ'
    - 'xform ăf ằ'
    - 'xform ăj ặ'
    - 'xform ăx ẵ'
    - 'xform ăr ẳ'
    - 'xform oo ô'
    - 'xform ôs ố'
    - 'xform ôf ồ'
    - 'xform ôj ộ'
    - 'xform ôx ỗ'
    - 'xform ôr ổ'
    - 'xform ee ê'
    - 'xform ês ế'
    - 'xform êf ề'
    - 'xform êj ệ'
    - 'xform êx ễ'
    - 'xform êr ể'
    - 'xform uw ư'
    - 'xform ưs ứ'
    - 'xform ưf ừ'
    - 'xform ưj ự'
    - 'xform ưx ữ'
    - 'xform ưr ử'
    - 'xform ow ơ'
    - 'xform ơs ớ'
    - 'xform ơf ờ'
    - 'xform ơj ợ'
    - 'xform ơx ỡ'
    - 'xform ơr ở'
    - 'xform as á'
    - 'xform af à'
    - 'xform aj ạ'
    - 'xform ax ã'
    - 'xform ar ả'
    - 'xform is í'
    - 'xform if ì'
    - 'xform ij ị'
    - 'xform ix ĩ'
    - 'xform ir ỉ'
    - 'xform us ú'
    - 'xform uf ù'
    - 'xform uj ụ'
    - 'xform ux ũ'
    - 'xform ur ủ'
    - 'xform es é'
    - 'xform ef è'
    - 'xform ej ẹ'
    - 'xform ex ẽ'
    - 'xform er ẻ'
    - 'xform os ó'
    - 'xform of ò'
    - 'xform oj ọ'
    - 'xform ox õ'
    - 'xform or ỏ'
    - 'xform ys ý'
    - 'xform yf ỳ'
    - 'xform yj ỵ'
    - 'xform yx ỹ'
    - 'xform yr ỷ'
  tips: 【越】

hannom_reverse_lookup:
  tags: [ hannom_lookup ]
  dictionary: hannomPS
  comment_format:
    - 'xform ([aeiouâăôê])(ng|nh|ch)([sfjxr]) $1$3$2'
    - 'xform ([aeiouâăôê])([iunptcmy])([sfjxr]) $1$3$2'
    - 'xform ([ae])([ou])([sfjxr]) $1$3$2'
    - 'xform (aw|ow|uw)([iunptcmy])([sfjxr]) $1$3$2'
    - 'xform (aw|ow|uw)(ng|nh|ch)([sfjxr]) $1$3$2'
#    - 'xform z ，【𡨸標準】'
#    - 'xform , ，【𡨸異體】'
    - 'xform z '
    - 'xform dd đ'
    - 'xform aa â'
    - 'xform âs ấ'
    - 'xform âf ầ'
    - 'xform âj ậ'
    - 'xform âx ẫ'
    - 'xform âr ẩ'
    - 'xform aw ă'
    - 'xform ăs ắ'
    - 'xform ăf ằ'
    - 'xform ăj ặ'
    - 'xform ăx ẵ'
    - 'xform ăr ẳ'
    - 'xform oo ô'
    - 'xform ôs ố'
    - 'xform ôf ồ'
    - 'xform ôj ộ'
    - 'xform ôx ỗ'
    - 'xform ôr ổ'
    - 'xform ee ê'
    - 'xform ês ế'
    - 'xform êf ề'
    - 'xform êj ệ'
    - 'xform êx ễ'
    - 'xform êr ể'
    - 'xform uw ư'
    - 'xform ưs ứ'
    - 'xform ưf ừ'
    - 'xform ưj ự'
    - 'xform ưx ữ'
    - 'xform ưr ử'
    - 'xform ow ơ'
    - 'xform ơs ớ'
    - 'xform ơf ờ'
    - 'xform ơj ợ'
    - 'xform ơx ỡ'
    - 'xform ơr ở'
    - 'xform as á'
    - 'xform af à'
    - 'xform aj ạ'
    - 'xform ax ã'
    - 'xform ar ả'
    - 'xform is í'
    - 'xform if ì'
    - 'xform ij ị'
    - 'xform ix ĩ'
    - 'xform ir ỉ'
    - 'xform us ú'
    - 'xform uf ù'
    - 'xform uj ụ'
    - 'xform ux ũ'
    - 'xform ur ủ'
    - 'xform es é'
    - 'xform ef è'
    - 'xform ej ẹ'
    - 'xform ex ẽ'
    - 'xform er ẻ'
    - 'xform os ó'
    - 'xform of ò'
    - 'xform oj ọ'
    - 'xform ox õ'
    - 'xform or ỏ'
    - 'xform ys ý'
    - 'xform yf ỳ'
    - 'xform yj ỵ'
    - 'xform yx ỹ'
    - 'xform yr ỷ'
  #closing_tips: 【粵拼】

hanja_lookup:
  tag: hanja_lookup
  prefix: "`K"  # 獨用jyutping_lookup反查在反查鍵「`」之後再鍵入〔大寫〕「J」
  suffix: "`"
  dictionary: "hangyl"
  preedit_format:
    - xform/'/ /
    - xform/(^|[ '])([qx])/$1/
    - xform/([qx])/ng/
  tips: 【韓】

hanja_reverse_lookup:
  tags: [ hanja_lookup ]
  dictionary: "hangyl"
  comment_format:
    - xform/(^|[ '])q/$1/
    - xform/q/ng/

punctuator:
  import_preset: default

key_binder:
  bindings:
    - {accept: "Control+Shift+1", select: .next, when: always}
    - {accept: "Control+Shift+n", select: japanese, when: always}
    - {accept: "Control+Shift+N", select: japanese, when: always}
    - {accept: "Control+Shift+k", select: korean, when: always}
    - {accept: "Control+Shift+K", select: korean, when: always}
    - {accept: "Control+Shift+v", select: vietnamese, when: always}
    - {accept: "Control+Shift+V", select: vietnamese, when: always}
    - {accept: "Control+Shift+j", select: double_jyutping_extra, when: always}
    - {accept: "Control+Shift+J", select: double_jyutping_extra, when: always}
    - {accept: "Control+Shift+m", select: td_pinyin_flypy_extra, when: always}
    - {accept: "Control+Shift+M", select: td_pinyin_flypy_extra, when: always}
    - {accept: "Control+Shift+l", select: international, when: always}
    - {accept: "Control+Shift+L", select: international, when: always}
    - {accept: "F16", select: .next, when: always}
    - {accept: "F19", select: international, when: always}
    # [] Pagination
    - {accept: bracketleft, send: Page_Up , when: has_menu}
    - {accept: bracketright, send: Page_Down , when: has_menu}

recognizer:
  import_preset: default
  patterns:
    reverse_lookup: "`H[a-z]*`?$"
    putonghua_to_kanji_lookup: "`[a-z;/,.]*`?$"
    hannom_lookup: "`V[a-z]*?$"
    hanja_lookup: "`K[a-z]*?$"

#zh_jp:
#  option_name: zh_jp
#  opencc_config: jp_t2s.json
#  #tips: all
#  tips: none

# zh_simp:
#   option_name: zh_simp
#   opencc_config: t2s.json
#   tips: none

# zh_tw:
#   option_name: zh_tw
#   opencc_config: t2tw.json
#   tips: none

# jp_variants:
#   option_name: jp_variants
#   opencc_config: jp_t2s.json
#   tips: none