§
    |ØjÕ"  ã                   óª  — d Z ddlmZmZmZmZmZmZ ddlm	Z	 ddl
mZmZ ddlmZ dZdedeed	f         d
edeeeeedz  f                  fd„Zdeed	f         d
edeeeeedz  eeef                  eeeeeedz  eef                  f         fd„Zdeed	f         d
edeeeeedz  f                  fd„Zddœdedeed	f         dedee	         fd„ZdS )zËStage 3: Statistical bigram scoring.

Note: ``from __future__ import annotations`` is intentionally omitted because
this module is compiled with mypyc, which does not support PEP 563 string
annotations.
é    )ÚBigramProfileÚ_get_model_normsÚget_enc_indexÚ
get_rowmaxÚscore_best_languageÚscore_with_profile©ÚDetectionResult)Úforced_encodingsÚscoring_floor)ÚEncodingInfoé@   ÚdataÚ
candidates.ÚprofileÚreturnNc                 óŽ   — g }|D ]?}t          | |j        |¬¦  «        \  }}|dk    r|                     |j        ||f¦  «         Œ@|S )zFScore every candidate fully (no pruning).  Returns (enc, score, lang).)r   ç        )r   ÚnameÚappend)r   r   r   ÚscoresÚencÚsÚlangs          ú‘/Users/tedpeters/Documents/Projects/Claude Projects/Misc Tools/notename-sheets/.venv/lib/python3.11/site-packages/chardet/pipeline/statistical.pyÚ
_score_allr      s\   € ð 35€FØð /ð /ˆÝ% d¨C¬H¸gÐFÑFÔF‰ˆˆ4ØˆsŠ7ˆ7Ø�MŠM˜3œ8 Q¨Ð-Ñ.Ô.Ð.øØ€Mó    c           
      ó¬  — t          ¦   «         }t          ¦   «         }t          ¦   «         }|j        }|j        }|j        }g }g }	| D ]ó}
|                     |
j        ¦  «        }|€Œ|
j        r9t          |¦  «        D ](\  }\  }}}| 
                    |
j        ||||f¦  «         Œ)Œ_t          |¦  «        D ]„\  }\  }}}||         }d}|D ]}|||         ||         z  z  }Œ|                     |¦  «        }|€t          d¦  «        }n|dk    r	|||z  z  }nd}|	 
                    |||
j        |||f¦  «         Œ…Œô|	                     d„ d¬¦  «         ||	fS )u~  Flatten candidate model variants for pruned scoring.

    Returns ``(mb_entries, sb_entries)`` where multi-byte entries are
    ``(enc, lang, table, key, variant_index)`` and single-byte entries are
    ``(upper_bound, variant_index, enc, lang, table, key)`` sorted by
    descending bound.  The upper bound multiplies each lead byte's total
    profile weight by the model's maximum weight for that lead byte â€” at
    most 256 terms versus one term per distinct bigram for a full score.
    ``variant_index`` is the variant's position in the encoding index, so
    exact score ties resolve to the same variant the full path keeps.
    Nr   Úinfr   c                 ó   — | d         S )Nr   © )Úes    r   ú<lambda>z!_split_variants.<locals>.<lambda>Z   s
   €  ! A¤$€ r   T©ÚkeyÚreverse)r   r   r   Úrow_freqÚnonzero_rowsÚ
input_normÚgetr   Úis_multibyte_cjkÚ	enumerater   ÚfloatÚsort)r   r   ÚindexÚnormsÚrowmaxr'   r(   r)   Ú
mb_entriesÚ
sb_entriesr   ÚvariantsÚvir   Útabler%   ÚrmÚub_dotÚb1Ú
model_normÚubs                        r   Ú_split_variantsr<   '   s¸  € õ$ ‰OŒO€EÝÑÔ€EÝ‰\Œ\€FØÔ€HØÔ'€LØÔ#€Jà@B€JØGI€JØð Dð DˆØ—9’9˜SœXÑ&Ô&ˆØÐØØÔð 	Ý*3°HÑ*=Ô*=ð Dð DÑ&�Ñ&�T˜5 #Ø×!Ò! 3¤8¨T°5¸#¸rÐ"BÑCÔCÐCÐCØÝ&/°Ñ&9Ô&9ð 	Dð 	DÑ"ˆBÑ"��u˜cØ˜”ˆBØˆFØ"ð 0ð 0�Ø˜"˜Rœ& 8¨B¤<Ñ/Ñ/��ØŸš 3™œˆJØÐ!å˜5‘\”\��Ø˜cÒ!Ð!Ø˜z¨JÑ6Ñ7��ð �Ø×Ò˜r 2 s¤x°°u¸cÐBÑCÔCÐCÐCð	Dð  ‡O‚O˜˜°€OÑ5Ô5Ð5Ø�zÐ!Ð!r   c           
      óú  ‡‡‡‡‡‡‡— t          ¦   «         }t          | |¦  «        \  }}i Ši Ši ŠdŠdŠdŠdt          dt          dt          dz  dt          ddf
ˆˆˆˆˆˆfd	„}|D ]%\  }}}}	}
 ||t          |||	¦  «        ||
¦  «         Œ&|D ]>\  }}
}}}}	t          ‰‰¦  «        }||k     r n ||t          |||	¦  «        ||
¦  «         Œ?t          ‰‰¦  «        Šˆfd
„‰                     ¦   «         D ¦   «         }t          |¦  «        }|rc| D ]`}|j	        |vrŒt          |                     |j	        g ¦  «        ¦  «        D ]+\  }
\  }}}	 ||j	        t          |||	¦  «        ||
¦  «         Œ,Œaˆˆfd„| D ¦   «         S )uc  Score candidates, skipping single-byte variants that provably cannot matter.

    Multi-byte variants are always scored fully â€” the orchestrator may later
    boost their confidence based on structural coverage, so no raw-score
    bound can rule them out.  Single-byte variants are scored in descending
    upper-bound order (see :func:`_split_variants`) and skipped once their
    bound falls below the pruning contract's ``scoring_floor``: such
    variants can affect neither the winner, nor position 1, nor any
    candidate a rank correction can examine.

    Encodings that ``postprocess_results`` inspects regardless of rank
    (the common Western Latin trio for niche-Latin demotion, KOI8-T for the
    KOI8-R promotion) are force-scored when their trigger could fire.
    Because confusion resolution can promote position 1 or any candidate
    within the band into position 0 before those triggers are evaluated,
    the trigger check covers every encoding near the top, not just the
    statistical winner.

    Returns (enc, score, lang) tuples for encodings scoring above zero, in
    candidate order.
    Ú r   Úenc_namer   r   Nr5   r   c                 óÌ   •— ‰                      | ¦  «        }|�||k     s||k    r|‰|          k    rd S |‰| <   |‰| <   |‰| <   | ‰	k    r|Šd S |‰k    r‰Š
|Š| Š	d S |‰
k    r|Š
d S d S )N)r*   )r?   r   r   r5   ÚprevÚ	best_langÚ
best_scoreÚbest_viÚtop1Útop1_encÚtop2s        €€€€€€r   Úrecordz_score_pruned.<locals>.recordƒ   s§   ø€ à�~Š~˜hÑ'Ô'ˆØÐ  T¢ ¨a°4ªi¨i¸BÀ'È(ÔBSÒ<SÐ<Sð ˆFØ ˆ
�8ÑØ"ˆ	�(ÑØˆ�ÑØ�xÒÐØˆDˆDˆDØ�ŠXˆXØˆDØˆDØˆHˆHˆHØ�ŠXˆXØˆDˆDˆDð ˆXr   c                 ó&   •— g | ]\  }}|‰k    ¯|‘ŒS r!   r!   )Ú.0r"   r   Útrigger_floors      €r   ú
<listcomp>z!_score_pruned.<locals>.<listcomp>ª   s'   ø€ ÐGÐGÐG‘d�a˜°A¸Ò4FÐ4F�Ð4FÐ4FÐ4Fr   c                 óŽ   •— g | ]A}‰                      |j        d ¦  «        d k    ¯!|j        ‰|j                 ‰|j                 f‘ŒBS )r   )r*   r   )rJ   r   rB   rC   s     €€r   rL   z!_score_pruned.<locals>.<listcomp>µ   sU   ø€ ð ð ð àØ�>Š>˜#œ( CÑ(Ô(¨3Ò.Ð.ð 
Œ�:˜cœhÔ'¨°3´8Ô)<Ð=à.Ð.Ð.r   )r   r<   Ústrr-   Úintr   r   Úitemsr   r   r,   r*   )r   r   r/   r2   r3   rH   r?   r   r6   r%   r5   r;   Ú	thresholdÚnear_topÚforcedr   rB   rC   rD   rE   rF   rG   rK   s                   @@@@@@@r   Ú_score_prunedrT   ^   sR  øøøøøøø€ õ2 ‰OŒO€EÝ,¨Z¸ÑAÔAÑ€J�
à#%€JØ')€IØ €Gð €HØ€DØ€Dð�ð ¥ð ­c°D©jð ½cð Àdð ð ð ð ð ð ð ð ð ð ð ð& +5ð Lð LÑ&ˆ�$˜˜s BØˆˆxÕ+¨G°U¸CÑ@Ô@À$ÈÑKÔKÐKÐKà.8ð 	Lð 	LÑ*ˆˆB�˜$  sõ " $¨Ñ-Ô-ˆ	Ø�	Š>ˆ>ð ˆEØˆˆxÕ+¨G°U¸CÑ@Ô@À$ÈÑKÔKÐKÐKõ " $¨Ñ-Ô-€MØGÐGÐGÐG˜j×.Ò.Ñ0Ô0ÐGÑGÔG€HÝ˜hÑ'Ô'€FØð TØð 	Tð 	TˆCØŒx˜vÐ%Ð%Øõ +4°E·I²I¸c¼hÈÑ4KÔ4KÑ*LÔ*Lð Tð TÑ&�Ñ&�T˜5 #Ø��s”xÕ!3°G¸UÀCÑ!HÔ!HÈ$ÐPRÑSÔSÐSÐSðTðð ð ð ð àðñ ô ð r   F)Úfull_rankingrU   c                ó  — | r|sg S t          | ¦  «        }|j        dk    rg S |st          |j        ¦  «        t          k     rt          | ||¦  «        }nt          ||¦  «        }|                     d„ d¬¦  «         d„ |D ¦   «         S )a•  Score all candidates and return results sorted by confidence descending.

    :param data: The raw byte data to score.
    :param candidates: Encoding candidates to evaluate.
    :param full_ranking: When ``True``, score every candidate fully so the
        returned list is complete (needed by ``detect_all``).  When ``False``
        (the default), single-byte candidates that provably cannot affect the
        top of the ranking may be skipped; the winner, position 1, and all
        candidates within the confusion band of the top score are identical
        to the full ranking.
    :returns: A list of :class:`DetectionResult` sorted by confidence.
    r   c                 ó   — | d         S )Né   r!   )Úxs    r   r#   z"score_candidates.<locals>.<lambda>Ú   s
   € ˜a œd€ r   Tr$   c                 ó:   — g | ]\  }}}t          |||¬ ¦  «        ‘ŒS ))ÚencodingÚ
confidenceÚlanguager	   )rJ   r   r   r   s       r   rL   z$score_candidates.<locals>.<listcomp>Û   s=   € ð ð ð áˆD�!�Tõ 	 °!¸dÐCÑCÔCðð ð r   )r   r)   ÚlenÚnonzeroÚ_MIN_NONZERO_FOR_PRESCREENr   rT   r.   )r   r   rU   r   r   s        r   Úscore_candidatesra   ¼   s°   € ð$ ð �zð Øˆ	å˜DÑ!Ô!€GØÔ˜SÒ Ð Øˆ	àð 4•s˜7œ?Ñ+Ô+Õ.HÒHÐHÝ˜D *¨gÑ6Ô6ˆˆå˜z¨7Ñ3Ô3ˆà
‡K‚K�N�N¨D€KÑ1Ô1Ð1ðð à#ðñ ô ð r   )Ú__doc__Úchardet.modelsr   r   r   r   r   r   Úchardet.pipeliner
   Úchardet.pipeline.postprocessr   r   Úchardet.registryr   r`   ÚbytesÚtupleÚlistrN   r-   r   rO   r<   rT   Úboolra   r!   r   r   ú<module>rk      s.  ððð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð -Ð ,Ð ,Ð ,Ð ,Ð ,Ø HÐ HÐ HÐ HÐ HÐ HÐ HÐ HØ )Ð )Ð )Ð )Ð )Ð )ð  Ð ðØ
ðà�l CÐ'Ô(ðð ðð 
ˆ%��U˜C $™JÐ&Ô
'Ô(ð	ð ð ð ð4"Ø�l CÐ'Ô(ð4"àð4"ð Øˆˆs�C˜$‘J  s¨CÐ/Ô	0Ô1Øˆˆu�c˜3  d¡
¨E°3Ð6Ô	7Ô8ð:ôð4"ð 4"ð 4"ð 4"ðn[Ø�l CÐ'Ô(ð[àð[ð 
ˆ%��U˜C $™JÐ&Ô
'Ô(ð[ð [ð [ð [ðD ð	"ð "ð "Ø
ð"à�l CÐ'Ô(ð"ð ð	"ð
 
ˆ/Ôð"ð "ð "ð "ð "ð "r   