PageRenderTime 72ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 26ms app.codeStats 0ms

/python/engine/PinYin/JianPin.py

http://scim-python.googlecode.com/
Python | 77 lines | 49 code | 3 blank | 25 comment | 7 complexity | c41e79ce86ef2cd732e83a33a073bbe5 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2# vim: set noet ts=4:
 3#
 4# scim-python
 5#
 6# Copyright (c) 2007-2008 Yu Fan <yufanyufan@gmail.com>
 7#
 8#
 9# This library is free software; you can redistribute it and/or
10# modify it under the terms of the GNU Lesser General Public
11# License as published by the Free Software Foundation; either
12# version 2 of the License, or (at your option) any later version.
13#
14# This library is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU Lesser General Public License for more details.
18#
19# You should have received a copy of the GNU Lesser General Public
20# License along with this program; if not, write to the
21# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22# Boston, MA  02111-1307  USA
23#
24# $Id: $
25#
26
27from ZhengJu import *
28import scim
29import os
30from scim import KeyCode
31from scim import KeyMask
32from scim import Property
33from QuanPin import QuanPinEngine
34
35import traceback
36import sys
37from PYDict import *
38from gettext import dgettext
39from QuanPin import strip
40_ = lambda a : dgettext ("scim-python", a)
41class JianPinEngine(QuanPinEngine):
42	def __init__ (self, factory, config, encoding, id):
43		QuanPinEngine.__init__(self, factory, config, encoding, id)
44
45	def split(self, strs):
46		if strip(strs) in PINYIN_LIST \
47			or strip(strs) in PINYIN_PARTIAL_LIST	\
48			or strip(strs) in SHENGMU_LIST \
49			or strs == "'":
50			yield (strs,  "")
51		else:
52			for i in range(len(strs), 0, -1):
53				if strs[:i][-1] == "'":
54					continue
55				if strip(strs[:i]) in PINYIN_LIST or strip(strs[:i]) in SHENGMU_LIST:
56					yield ( strs[:i], strs[i:] )
57					if strip(strs[:i-1]) in PINYIN_LIST and strip(strs[:i])[-1] in SHENGMU_LIST and self.is_valid_head(strs[i-1:]):
58						yield ( strs[:i-1], strs[i-1:])
59					break
60 
61class JianPinFactory (IMEngineFactory):
62	def __init__ (self, config):
63		IMEngineFactory.__init__ (self, config)
64		self.name 		= _(u"JianPin")
65		self.uuid 		= "908ce256-ddd8-44b7-b6c0-5833024bd445"
66		self.authors	= u"Yu Fan <yufanyufan@gmail.com>"
67		self.icon_file 	= "/usr/share/scim/icons/scim-python.png"
68		self.credits 	= u"GPL"
69		self.help		= _(u"Help For JianPin")
70		self.set_languages ("zh")
71		self._config	= config
72	def create_instance (self, encoding, id):
73		engine =  JianPinEngine (self, self._config, encoding, id)
74		return engine
75
76	def reload_config (self, config):
77		pass