PageRenderTime 84ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/python/engine/PinYin/JianPin.py

http://scim-python.googlecode.com/
Python | 77 lines | 49 code | 3 blank | 25 comment | 4 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. from ZhengJu import *
  27. import scim
  28. import os
  29. from scim import KeyCode
  30. from scim import KeyMask
  31. from scim import Property
  32. from QuanPin import QuanPinEngine
  33. import traceback
  34. import sys
  35. from PYDict import *
  36. from gettext import dgettext
  37. from QuanPin import strip
  38. _ = lambda a : dgettext ("scim-python", a)
  39. class JianPinEngine(QuanPinEngine):
  40. def __init__ (self, factory, config, encoding, id):
  41. QuanPinEngine.__init__(self, factory, config, encoding, id)
  42. def split(self, strs):
  43. if strip(strs) in PINYIN_LIST \
  44. or strip(strs) in PINYIN_PARTIAL_LIST \
  45. or strip(strs) in SHENGMU_LIST \
  46. or strs == "'":
  47. yield (strs, "")
  48. else:
  49. for i in range(len(strs), 0, -1):
  50. if strs[:i][-1] == "'":
  51. continue
  52. if strip(strs[:i]) in PINYIN_LIST or strip(strs[:i]) in SHENGMU_LIST:
  53. yield ( strs[:i], strs[i:] )
  54. if strip(strs[:i-1]) in PINYIN_LIST and strip(strs[:i])[-1] in SHENGMU_LIST and self.is_valid_head(strs[i-1:]):
  55. yield ( strs[:i-1], strs[i-1:])
  56. break
  57. class JianPinFactory (IMEngineFactory):
  58. def __init__ (self, config):
  59. IMEngineFactory.__init__ (self, config)
  60. self.name = _(u"JianPin")
  61. self.uuid = "908ce256-ddd8-44b7-b6c0-5833024bd445"
  62. self.authors = u"Yu Fan <yufanyufan@gmail.com>"
  63. self.icon_file = "/usr/share/scim/icons/scim-python.png"
  64. self.credits = u"GPL"
  65. self.help = _(u"Help For JianPin")
  66. self.set_languages ("zh")
  67. self._config = config
  68. def create_instance (self, encoding, id):
  69. engine = JianPinEngine (self, self._config, encoding, id)
  70. return engine
  71. def reload_config (self, config):
  72. pass