<s> from __future__ import print_function <EOL> import abc <EOL> import sys <EOL> import codecs <EOL> from pprint import pprint <EOL> from . import resources <EOL> from . import datastore <EOL> PYTHON3 = ( sys . version [ <NUM_LIT:0> ] == '<STR_LIT:3>' ) <EOL> class Dictionary : <EOL> __metaclass__ = abc . ABCMeta <EOL> @ abc . abstractmethod <EOL> def add ( self , word ) : <EOL> return <EOL> @ abc . abstractmethod <EOL> def getWordsEndingWith ( self , sfx ) : <EOL> return <EOL> @ abc . abstractmethod <EOL> def hasWordsStartingWith ( self , pfx ) : <EOL> return <EOL> @ abc . abstractmethod <EOL> def getWordsStartingWith ( self , pfx ) : <EOL> return <EOL> @ abc . abstractmethod <EOL> def isWord ( self , word ) : <EOL> return <EOL> @ abc . abstractmethod <EOL> def getAllWords ( self ) : <EOL> return <EOL> @ abc . abstractmethod <EOL> def getDictionaryPath ( self ) : <EOL> return <EOL> def getSize ( self ) : <EOL> count = <NUM_LIT:0> <EOL> for word in self . getAllWordsIterable ( ) : <EOL> count += <NUM_LIT:1> <EOL> return count <EOL> def getAllWordsIterable ( self ) : <EOL> for word in self . getAllWords ( ) : <EOL> yield word <EOL> raise StopIteration <EOL> def loadWordFile ( self , pre_processor = None ) : <EOL> filename = self . getDictionaryPath ( ) <EOL> with codecs . open ( filename , '<STR_LIT:r>' , '<STR_LIT:utf-8>' ) as fp : <EOL> for word in fp . readlines ( ) : <EOL> if pre_processor : <EOL> self . add ( pre_processor ( word . strip ( ) ) ) <EOL> else : <EOL> self . add ( word . strip ( ) ) <EOL> return <EOL> class Agarathi ( Dictionary ) : <EOL> def __init__ ( self , dictionary_path , reverse = False ) : <EOL> self . dictionary_path = dictionary_path <EOL> self . Finalized = False <EOL> self . reverse = reverse <EOL> if reverse : <EOL> self . store = datastore . RTrie ( ) <EOL> else : <EOL> self . store = datastore . DTrie ( ) <EOL> return <EOL> def getWordsEndingWith ( self , sfx ) : <EOL> if not getattr ( self . store , '<STR_LIT>' ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> return self . store . getWordsEndingWith ( sfx ) <EOL> def getWordsStartingWith ( self , pfx , limit = float ( "<STR_LIT>" ) ) : <EOL> if not getattr ( self . store , '<STR_LIT>' ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> return self . store . getAllWordsPrefix ( pfx ) <EOL> def hasWordsStartingWith ( self , pfx ) : <EOL> if not getattr ( self . store , '<STR_LIT>' ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> return self . store . hasWordPrefix ( pfx ) <EOL> def add ( self , word ) : <EOL> if self . Finalized : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . store . add ( word ) <EOL> return <EOL> def isWord ( self , word ) : <EOL> return self . store . isWord ( word ) <EOL> def finalize ( self ) : <EOL> self . Finalized = True <EOL> def getDictionaryPath ( self ) : <EOL> return self . dictionary_path <EOL> def getAllWords ( self ) : <EOL> return self . store . getAllWords ( ) <EOL> def getAllWordsIterable ( self ) : <EOL> for word in self . store . getAllWordsIterable ( ) : <EOL> yield word <EOL> raise StopIteration <EOL> def _reverse_dict ( DictT ) : <EOL> def function_reverse_dict_type ( ) : <EOL> obj = DictT ( ) <EOL> obj . reverse = True <EOL> obj . store = datastore . RTrie ( ) <EOL> return obj <EOL> return function_reverse_dict_type <EOL> class EmptyAgarathi ( Agarathi ) : <EOL> def __init__ ( self ) : <EOL> Agarathi . __init__ ( self , dictionary_path = None ) <EOL> class TamilVU ( Agarathi ) : <EOL> def __init__ ( self ) : <EOL> Agarathi . __init__ ( self , resources . DICTIONARY_DATA_FILES [ '<STR_LIT>' ] ) <EOL> class EnglishLinux ( Agarathi ) : <EOL> def __init__ ( self ) : <EOL> Agarathi . __init__ ( self , resources . DICTIONARY_DATA_FILES [ '<STR_LIT>' ] ) <EOL> def isWord ( self , word ) : <EOL> return Agarathi . isWord ( self , word . lower ( ) ) <EOL> def add ( self , word ) : <EOL> return Agarathi . add ( self , word . lower ( ) ) <EOL> def reverse_TamilVU ( ) : <EOL> return _reverse_dict ( TamilVU ) ( ) <EOL> class Madurai ( Agarathi ) : <EOL> def __init__ ( self ) : <EOL> Agarathi . __init__ ( self , resources . DICTIONARY_DATA_FILES [ '<STR_LIT>' ] ) <EOL> def reverse_Madurai ( ) : <EOL> return _reverse_dict ( Madurai ) ( ) <EOL> class Wikipedia ( Agarathi ) : <EOL> def __init__ ( self ) : <EOL> Agarathi . __init__ ( self , resources . DICTIONARY_DATA_FILES [ '<STR_LIT>' ] ) <EOL> def reverse_Wikipedia ( ) : <EOL> return _reverse_dict ( Wikipedia ) ( ) <EOL> class DictionaryBuilder : <EOL> @ staticmethod <EOL> def create ( DType ) : <EOL> if not callable ( DType ) : <EOL> raise Exception ( u"<STR_LIT>" ) <EOL> obj = DType ( ) <EOL> obj . loadWordFile ( ) <EOL> return [ obj , obj . getSize ( ) ] <EOL> @ staticmethod <EOL> def createUsingWordList ( wlist ) : <EOL> obj = EmptyAgarathi ( ) <EOL> for w in wlist : <EOL> obj . add ( w ) <EOL> return obj , obj . getSize ( ) </s>
