Skip to content

Instantly share code, notes, and snippets.

@Des-Nerger
Last active October 14, 2020 17:22
Show Gist options
  • Save Des-Nerger/5713142c97ec97e7cf109ce51770a6d1 to your computer and use it in GitHub Desktop.
Save Des-Nerger/5713142c97ec97e7cf109ce51770a6d1 to your computer and use it in GitHub Desktop.
# -*- coding: UTF-8 -*-
# integrate cangjie5 into ibus-anthy
# USAGE: $ python2.7 export_cangjie5codes_to_ibus-anthy.py <libcangjie-1.2/data/table.txt >>~/.anthy/private_words_default
# after that, you need ibus-anthy to reload it somehow. I personally do it by starting kasumi and pressing the "Save" button.
import os, sys
from os import path
pkg_data_dir='/usr/share/ibus-anthy'
sys.path.append(path.join(pkg_data_dir, 'setup'))
from anthyprefs import AnthyPrefs
sys.path.append(path.join(pkg_data_dir, 'engine'))
from jastring import JaString
JaString._prefs = AnthyPrefs()
js = JaString()
def get_hiragana(s):
for c in s: js.insert(c)
hiragana=js.get_hiragana(commit=True)
js.reset(); return hiragana
for line in sys.stdin:
if line[0] in ('\n', '#'): continue
f = line.split(' ', 14)
if '1' not in (f[2], f[5]): continue
for code in f[11].split(','):
if code[0] in ('z', 'x', 'N'): continue
print '{} #T35*500 {}'.format(get_hiragana(code)[0].replace('ヴ','う゛'), f[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment