/python/engine/XingMa/XMDict.py
http://scim-python.googlecode.com/ · Python · 101 lines · 63 code · 11 blank · 27 comment · 8 complexity · 1e708d5d2c04370b902aefb558e31e89 MD5 · raw file
- # -*- coding: utf-8 -*-
- # vim: set noet ts=4:
- #
- # scim-python
- #
- # Copyright (c) 2008-2008 Yu Yuwei <acevery@gmail.com>
- #
- #
- # This library is free software; you can redistribute it and/or
- # modify it under the terms of the GNU Lesser General Public
- # License as published by the Free Software Foundation; either
- # version 2 of the License, or (at your option) any later version.
- #
- # This library is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Lesser General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public
- # License along with this program; if not, write to the
- # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- # Boston, MA 02111-1307 USA
- #
- # $Id: $
- #
- import sys
- reload (sys)
- sys.setdefaultencoding('utf-8')
- XingMa_Dict = {
- '0':0,
- 'a':1, 'b':2, 'c':3, 'd':4, 'e':5,
- 'f':6, 'g':7, 'h':8, 'i':9, 'j':10,
- 'k':11, 'l':12, 'm':13, 'n':14, 'o':15,
- 'p':16, 'q':17, 'r':18, 's':19, 't':20,
- 'u':21, 'v':22, 'w':23, 'x':24, 'y':25,
- 'z':26, "'":27, ';':28, '`':29, '~':30,
- '!':31, '@':32, '#':33, '$':34, '%':35,
- '^':36, '&':37, '*':38, '(':39, ')':40,
- '-':41, '_':42, '=':43, '+':44, '[':45,
- ']':46, '{':47, '}':48, '|':49, '/':50,
- ':':51, '"':52, '<':53, '>':54, ',':55,
- '.':56, '?':57, '\\':58, 'A':59, 'B':60,
- 'C':61, 'D':62, 'E':63, 'F':64, 'G':65,
- 'H':66, 'I':67, 'J':68, 'K':69, 'L':70,
- 'M':71, 'N':72, 'O':73, 'P':74, 'Q':75,
- 'R':76, 'S':77, 'T':78, 'U':79, 'V':80,
- 'W':81, 'X':82, 'Y':83, 'Z':84, '0':85,
- '1':86, '2':87, '3':88, '4':89, '5':90,
- '6':91, '7':92, '8':93, '9':94
- }
- XingMa_List = XingMa_Dict.keys()
- ID_XingMa_Dict = {}
- for key,id in XingMa_Dict.items():
- ID_XingMa_Dict[id] = key
- class XingMa_key:
- '''The class store'''
- def __init__(self, xm_key):
- try:
- if xm_key not in XingMa_List:
- error_m = u'%s is not in XingMa_Dict' % xm_key
- raise Exception ( error_m.encode('utf8') )
- except Exception, e:
- print e
- import traceback
- traceback.print_exc ()
- self._key = xm_key
- self._key_id = XingMa_Dict[xm_key]
-
- def get_key_id(self):
- return self._key_id
- def get_key(self):
- return self._key
- def __str__(self):
- return self._key
- def __int__(self):
- return self._key_id
- def Parse ( inputstr ):
-
- ids_input = []
- try:
- ids_input = map (XingMa_key,inputstr)
- except:
- pass
- return ids_input[:]
- def Deparse (id):
- '''deparse the id code of XingMa, id could be int or int in string form'''
- if id:
- id = int(id)
- if id in ID_XingMa_Dict:
- return ID_XingMa_Dict[id]
- else:
- return ''