def compile(method="builtin_normal"): ''' make hiragana/katakana input state trie-tree >>> hira_tree, kata_tree = compile('builtin_normal') >>> hira_tree[ord('k')][ord('y')][ord('a')][SKK_ROMAN_VALUE] u'\u304d\u3083' >>> hira_tree[ord('t')][ord('t')][ord('a')][SKK_ROMAN_VALUE] u'\u3063\u305f' >>> kata_tree[ord('k')][ord('y')][ord('a')][SKK_ROMAN_VALUE] u'\u30ad\u30e3' >>> hira_tree, kata_tree = compile('builtin_azik') >>> hira_tree[ord('k')][ord('y')][ord('a')][SKK_ROMAN_VALUE] u'\u304d\u3083' >>> kata_tree[ord('k')][ord('y')][ord('a')][SKK_ROMAN_VALUE] u'\u30ad\u30e3' >>> hira_tree, kata_tree = compile('builtin_act') >>> hira_tree[ord('c')][ord('g')][ord('a')][SKK_ROMAN_VALUE] u'\u304d\u3083' >>> kata_tree[ord('c')][ord('g')][ord('a')][SKK_ROMAN_VALUE] u'\u30ad\u30e3' ''' logging.info("compile roman rule: %s" % method) _base_name, base_ruledict = rule.get('builtin_base') name, ruledict = rule.get(method) ruledict.update(base_ruledict) hira_rule, kata_rule = _make_rules(ruledict) if method == 'builtin_normal': onbin = 'bcdfghjkmprstvwxz' else: onbin = 'w' _hira_tree = _maketree(hira_rule, onbin, u'っ', u'ん') _kata_tree = _maketree(kata_rule, onbin, u'ッ', u'ン') return (_hira_tree, _kata_tree)
def _load_builtin_dict(): """ >>> _load_user_dict() """ try: _load_dict(_get_fallback_dict_path('SKK-JISYO.builtin')) except Exception, e: logging.exception(e) import rule template = "@ローマ字ルール /%s;builtin:settings:romanrule:'%s'/" try: loader = SkkLineLoader() for rulename in rule.list(): try: ruledisplay, ruledict = rule.get(rulename) loader.parse(template % (ruledisplay, rulename)) except ImportError, e: logging.exception(e) except Exception, e: logging.exception(e) try: _load_dict(_get_fallback_dict_path('SKK-JISYO.L')) except Exception, e: logging.exception(e) try: _load_dict(_get_fallback_dict_path('SKK-JISYO.JIS2')) except Exception, e: logging.exception(e)