o
    5d%                     @   s   d dl mZmZmZ d dlmZmZmZ d dlm	Z	m
Z
mZ d dlmZmZmZ d dlmZmZmZ d dlmZ G dd dZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )   )BIG5_CHAR_TO_FREQ_ORDERBIG5_TABLE_SIZEBIG5_TYPICAL_DISTRIBUTION_RATIO)EUCKR_CHAR_TO_FREQ_ORDEREUCKR_TABLE_SIZE EUCKR_TYPICAL_DISTRIBUTION_RATIO)EUCTW_CHAR_TO_FREQ_ORDEREUCTW_TABLE_SIZE EUCTW_TYPICAL_DISTRIBUTION_RATIO)GB2312_CHAR_TO_FREQ_ORDERGB2312_TABLE_SIZE!GB2312_TYPICAL_DISTRIBUTION_RATIO)JIS_CHAR_TO_FREQ_ORDERJIS_TABLE_SIZEJIS_TYPICAL_DISTRIBUTION_RATIO)JOHAB_TO_EUCKR_ORDER_TABLEc                   @   sL   e Zd ZdZdZdZdZdd Zdd Zd	d
 Z	dd Z
dd Zdd ZdS )CharDistributionAnalysisi   gGz?g{Gz?   c                 C   s2   t  | _d | _d | _d | _d | _d | _|   d S N)tuple_char_to_freq_order_table_sizetypical_distribution_ratio_done_total_chars_freq_charsresetself r   {C:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\pip/_vendor/chardet/chardistribution.py__init__>   s   z!CharDistributionAnalysis.__init__c                 C   s   d| _ d| _d| _dS )zreset analyser, clear any stateF    N)r   r   r   r   r   r   r    r   M   s   
zCharDistributionAnalysis.resetc                 C   sd   |dkr
|  |}nd}|dkr,|  jd7  _|| jk r.d| j| kr0|  jd7  _dS dS dS dS )z"feed a character with known length   r"   r   i   N)	get_orderr   r   r   r   )r   charchar_lenorderr   r   r    feedV   s   
zCharDistributionAnalysis.feedc                 C   sT   | j dks| j| jkr| jS | j | jkr'| j| j | j | j  }|| jk r'|S | jS )z(return confidence based on existing datar"   )r   r   MINIMUM_DATA_THRESHOLDSURE_NOr   SURE_YES)r   rr   r   r    get_confidenced   s   
z'CharDistributionAnalysis.get_confidencec                 C   s   | j | jkS r   )r   ENOUGH_DATA_THRESHOLDr   r   r   r    got_enough_datau   s   z(CharDistributionAnalysis.got_enough_datac                 C   s   dS )Nr$   r   )r   _r   r   r    r%   z   s   z"CharDistributionAnalysis.get_orderN)__name__
__module____qualname__r/   r,   r+   r*   r!   r   r)   r.   r0   r%   r   r   r   r    r   8   s    	r   c                       $   e Zd Z fddZdd Z  ZS )EUCTWDistributionAnalysisc                        t    t| _t| _t| _d S r   )superr!   r   r   r	   r   r
   r   r   	__class__r   r    r!         

z"EUCTWDistributionAnalysis.__init__c                 C   ,   |d }|dkrd|d  |d  d S dS )Nr"      ^   r      r$   r   r   byte_str
first_charr   r   r    r%         z#EUCTWDistributionAnalysis.get_orderr2   r3   r4   r!   r%   __classcell__r   r   r9   r    r6          r6   c                       r5   )EUCKRDistributionAnalysisc                    r7   r   r8   r!   r   r   r   r   r   r   r   r9   r   r    r!      r;   z"EUCKRDistributionAnalysis.__init__c                 C   r<   )Nr"      r>   r   r?   r$   r   r@   r   r   r    r%      rC   z#EUCKRDistributionAnalysis.get_orderrD   r   r   r9   r    rG      rF   rG   c                       r5   )JOHABDistributionAnalysisc                    r7   r   rH   r   r9   r   r    r!      r;   z"JOHABDistributionAnalysis.__init__c                 C   sB   |d }d|  krdk rn dS |d |d  }t |dS dS )Nr"            r   r$   )r   get)r   rA   rB   coder   r   r    r%      s   z#JOHABDistributionAnalysis.get_orderrD   r   r   r9   r    rJ      rF   rJ   c                       r5   )GB2312DistributionAnalysisc                    r7   r   )r8   r!   r   r   r   r   r   r   r   r9   r   r    r!      r;   z#GB2312DistributionAnalysis.__init__c                 C   s:   |d |d }}|dkr|dkrd|d  | d S dS )Nr"   r   rI   r?   r>   r$   r   r   rA   rB   second_charr   r   r    r%      s   z$GB2312DistributionAnalysis.get_orderrD   r   r   r9   r    rP      rF   rP   c                       r5   )Big5DistributionAnalysisc                    r7   r   )r8   r!   r   r   r   r   r   r   r   r9   r   r    r!      r;   z!Big5DistributionAnalysis.__init__c                 C   sR   |d |d }}|dkr'|dkrd|d  | d d S d|d  | d S dS )	Nr"   r      r?      ?   @   r$   r   rQ   r   r   r    r%      s   z"Big5DistributionAnalysis.get_orderrD   r   r   r9   r    rS      rF   rS   c                       r5   )SJISDistributionAnalysisc                    r7   r   r8   r!   r   r   r   r   r   r   r   r9   r   r    r!      r;   z!SJISDistributionAnalysis.__init__c                 C   s   |d |d }}d|  krdkrn nd|d  }nd|  kr&dkr2n d	S d|d d  }nd	S || d
 }|dkr@d	}|S )Nr"   r                     r$   rW      r   )r   rA   rB   rR   r(   r   r   r    r%      s   z"SJISDistributionAnalysis.get_orderrD   r   r   r9   r    rX      rF   rX   c                       r5   )EUCJPDistributionAnalysisc                    r7   r   rY   r   r9   r   r    r!      r;   z"EUCJPDistributionAnalysis.__init__c                 C   s,   |d }|dkrd|d  |d  d S dS )Nr"      r>   r?   r   r$   r   )r   rA   r&   r   r   r    r%      rC   z#EUCJPDistributionAnalysis.get_orderrD   r   r   r9   r    ra      rF   ra   N)big5freqr   r   r   	euckrfreqr   r   r   	euctwfreqr   r	   r
   
gb2312freqr   r   r   jisfreqr   r   r   	johabfreqr   r   r6   rG   rJ   rP   rS   rX   ra   r   r   r   r    <module>   s   J