# -*- coding: utf-8 -*- # vim: set ts=4: # # Name: EnglishHelper # # Copyright: Copyright (c) 2008 Loya Liu # # $Id$ # # Author: loya.liu@gmail.com (Loya Liu) # __author__ = "loya.liu@gmail.com (Loya Liu)" from FunInputClient import Word as Word try: import enchant __ENCHANT_EXIST__=True except: __ENCHANT_EXIST__=False class EnglishHelper: def __init__(self): if __ENCHANT_EXIST__: self._dict=enchant.Dict('en_US') else: self._dict=None def check(self,word): if self._dict: return self._dict.check(word) return True def search(self,word): if self._dict: sl=self._dict.suggest(word) if sl: return [ Word(x,x,-1,0,0,0) for x in sl ] return [] def main_test(): h=EnglishHelper() print h.check('test') print h.check('djkk') wl=h.search('tes') for x in wl: print x.toString() if __name__ == '__main__': main_test()