o H_$@sddlmZmZmZddlmZmZmZddlm Z m Z m Z ddl m Z mZmZddlmZmZmZGdddeZGdd d eZGd d d eZGd d d eZGdddeZGdddeZGdddeZdS))EUCTW_CHAR_TO_FREQ_ORDEREUCTW_TABLE_SIZE EUCTW_TYPICAL_DISTRIBUTION_RATIO)EUCKR_CHAR_TO_FREQ_ORDEREUCKR_TABLE_SIZE EUCKR_TYPICAL_DISTRIBUTION_RATIO)GB2312_CHAR_TO_FREQ_ORDERGB2312_TABLE_SIZE!GB2312_TYPICAL_DISTRIBUTION_RATIO)BIG5_CHAR_TO_FREQ_ORDERBIG5_TABLE_SIZEBIG5_TYPICAL_DISTRIBUTION_RATIO)JIS_CHAR_TO_FREQ_ORDERJIS_TABLE_SIZEJIS_TYPICAL_DISTRIBUTION_RATIOc@sLeZdZdZdZdZdZddZddZd d Z d d Z d dZ ddZ dS)CharDistributionAnalysisigGz?g{Gz?cCs0d|_d|_d|_d|_d|_d|_|dSN)_char_to_freq_order _table_sizetypical_distribution_ratio_done _total_chars _freq_charsresetselfr:/usr/lib/python3/dist-packages/chardet/chardistribution.py__init__.s z!CharDistributionAnalysis.__init__cCsd|_d|_d|_dS)zreset analyser, clear any stateFN)rrrrrrrr=s zCharDistributionAnalysis.resetcCsd|dkr ||}nd}|dkr,|jd7_||jkr.d|j|kr0|jd7_dSdSdSdS)z"feed a character with known lengthr riN) get_orderrrrr)rcharchar_lenorderrrrfeedFs  zCharDistributionAnalysis.feedcCsT|jdks |j|jkr|jS|j|jkr'|j|j|j|j}||jkr'|S|jS)z(return confidence based on existing datar )rrMINIMUM_DATA_THRESHOLDSURE_NOrSURE_YES)rrrrrget_confidenceTs  z'CharDistributionAnalysis.get_confidencecCs |j|jkSr)rENOUGH_DATA_THRESHOLDrrrrgot_enough_datads z(CharDistributionAnalysis.got_enough_datacCsdS)Nr"r)rbyte_strrrrr#isz"CharDistributionAnalysis.get_orderN) __name__ __module__ __qualname__r-r*r)r(rrr'r,r.r#rrrrr(s  rc$eZdZfddZddZZS)EUCTWDistributionAnalysisc$tt|t|_t|_t|_dSr) superr4rrrrrrrr __class__rrrr z"EUCTWDistributionAnalysis.__init__cC,|d}|dkrd|d|ddSdS)Nr ^rr"rrr/ first_charrrrr#xz#EUCTWDistributionAnalysis.get_orderr0r1r2rr# __classcell__rrr7rr4q r4cr3)EUCKRDistributionAnalysiscr5r) r6rDrrrrrrrrr7rrrr9z"EUCKRDistributionAnalysis.__init__cCr:)Nr r<rr=r"rr>rrrr#r@z#EUCKRDistributionAnalysis.get_orderrArrr7rrDrCrDcr3)GB2312DistributionAnalysiscr5r) r6rFrrrr rr rrr7rrrr9z#GB2312DistributionAnalysis.__init__cCs:|d|d}}|dkr|dkrd|d|dSdS)Nr rrEr=r<r"rrr/r? second_charrrrr#sz$GB2312DistributionAnalysis.get_orderrArrr7rrFrCrFcr3)Big5DistributionAnalysiscr5r) r6rIrr rr rr rrr7rrrr9z!Big5DistributionAnalysis.__init__cCsR|d|d}}|dkr'|dkrd|d|ddSd|d|dSdS) Nr rr=?@r"rrGrrrr#s z"Big5DistributionAnalysis.get_orderrArrr7rrIrCrIcr3)SJISDistributionAnalysiscr5r) r6rNrrrrrrrrr7rrrr9z!SJISDistributionAnalysis.__init__cCsr|d|d}}|dkr|dkrd|d}n|dkr)|dkr)d|dd}nd S||d }|d kr7d }|S) Nr rr"rMr)rr/r?rHr&rrrr#s z"SJISDistributionAnalysis.get_orderrArrr7rrNrCrNcr3)EUCJPDistributionAnalysiscr5r) r6rVrrrrrrrrr7rrrr9z"EUCJPDistributionAnalysis.__init__cCs,|d}|dkrd|d|ddSdS)Nr r<r=rr"r)rr/r$rrrr#r@z#EUCJPDistributionAnalysis.get_orderrArrr7rrVrCrVN) euctwfreqrrr euckrfreqrrr gb2312freqrr r big5freqr r r jisfreqrrrobjectrr4rDrFrIrNrVrrrrsI