<s> from . charsetprober import CharSetProber <EOL> from . constants import eNotMe , eDetecting <EOL> from . compat import wrap_ord <EOL> FINAL_KAF = <NUM_LIT> <EOL> NORMAL_KAF = <NUM_LIT> <EOL> FINAL_MEM = <NUM_LIT> <EOL> NORMAL_MEM = <NUM_LIT> <EOL> FINAL_NUN = <NUM_LIT> <EOL> NORMAL_NUN = <NUM_LIT> <EOL> FINAL_PE = <NUM_LIT> <EOL> NORMAL_PE = <NUM_LIT> <EOL> FINAL_TSADI = <NUM_LIT> <EOL> NORMAL_TSADI = <NUM_LIT> <EOL> MIN_FINAL_CHAR_DISTANCE = <NUM_LIT:5> <EOL> MIN_MODEL_DISTANCE = <NUM_LIT> <EOL> VISUAL_HEBREW_NAME = "<STR_LIT>" <EOL> LOGICAL_HEBREW_NAME = "<STR_LIT>" <EOL> class HebrewProber ( CharSetProber ) : <EOL> def __init__ ( self ) : <EOL> CharSetProber . __init__ ( self ) <EOL> self . _mLogicalProber = None <EOL> self . _mVisualProber = None <EOL> self . reset ( ) <EOL> def reset ( self ) : <EOL> self . _mFinalCharLogicalScore = <NUM_LIT:0> <EOL> self . _mFinalCharVisualScore = <NUM_LIT:0> <EOL> self . _mPrev = '<STR_LIT:U+0020>' <EOL> self . _mBeforePrev = '<STR_LIT:U+0020>' <EOL> def set_model_probers ( self , logicalProber , visualProber ) : <EOL> self . _mLogicalProber = logicalProber <EOL> self . _mVisualProber = visualProber <EOL> def is_final ( self , c ) : <EOL> return wrap_ord ( c ) in [ FINAL_KAF , FINAL_MEM , FINAL_NUN , FINAL_PE , <EOL> FINAL_TSADI ] <EOL> def is_non_final ( self , c ) : <EOL> return wrap_ord ( c ) in [ NORMAL_KAF , NORMAL_MEM , NORMAL_NUN , NORMAL_PE ] <EOL> def feed ( self , aBuf ) : <EOL> if self . get_state ( ) == eNotMe : <EOL> return eNotMe <EOL> aBuf = self . filter_high_bit_only ( aBuf ) <EOL> for cur in aBuf : <EOL> if cur == '<STR_LIT:U+0020>' : <EOL> if self . _mBeforePrev != '<STR_LIT:U+0020>' : <EOL> if self . is_final ( self . _mPrev ) : <EOL> self . _mFinalCharLogicalScore += <NUM_LIT:1> <EOL> elif self . is_non_final ( self . _mPrev ) : <EOL> self . _mFinalCharVisualScore += <NUM_LIT:1> <EOL> else : <EOL> if ( ( self . _mBeforePrev == '<STR_LIT:U+0020>' ) and <EOL> ( self . is_final ( self . _mPrev ) ) and ( cur != '<STR_LIT:U+0020>' ) ) : <EOL> self . _mFinalCharVisualScore += <NUM_LIT:1> <EOL> self . _mBeforePrev = self . _mPrev <EOL> self . _mPrev = cur <EOL> return eDetecting <EOL> def get_charset_name ( self ) : <EOL> finalsub = self . _mFinalCharLogicalScore - self . _mFinalCharVisualScore <EOL> if finalsub >= MIN_FINAL_CHAR_DISTANCE : <EOL> return LOGICAL_HEBREW_NAME <EOL> if finalsub <= - MIN_FINAL_CHAR_DISTANCE : <EOL> return VISUAL_HEBREW_NAME <EOL> modelsub = ( self . _mLogicalProber . get_confidence ( ) <EOL> - self . _mVisualProber . get_confidence ( ) ) <EOL> if modelsub > MIN_MODEL_DISTANCE : <EOL> return LOGICAL_HEBREW_NAME <EOL> if modelsub < - MIN_MODEL_DISTANCE : <EOL> return VISUAL_HEBREW_NAME <EOL> if finalsub < <NUM_LIT:0.0> : <EOL> return VISUAL_HEBREW_NAME <EOL> return LOGICAL_HEBREW_NAME <EOL> def get_state ( self ) : <EOL> if ( self . _mLogicalProber . get_state ( ) == eNotMe ) and ( self . _mVisualProber . get_state ( ) == eNotMe ) : <EOL> return eNotMe <EOL> return eDetecting </s>
