§
    'ê[f'  ã                   ó  — d Z ddlmZmZ ddlmZmZmZ  G d„ de¦  «        Z G d„ de¦  «        Z	 G d„ d	e	¦  «        Z
 G d
„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        ZdS )zLanguage Modelsé    )ÚLanguageModelÚ	Smoothing)ÚAbsoluteDiscountingÚ	KneserNeyÚ
WittenBellc                   ó   — e Zd ZdZdd„ZdS )ÚMLEzbClass for providing MLE ngram model scores.

    Inherits initialization from BaseNgramModel.
    Nc                 óR   — |                       |¦  «                             |¦  «        S )zÃReturns the MLE score for a word given a context.

        Args:
        - word is expected to be a string
        - context is expected to be something reasonably convertible to a tuple
        )Úcontext_countsÚfreq)ÚselfÚwordÚcontexts      úB/var/www/piapp/venv/lib/python3.11/site-packages/nltk/lm/models.pyÚunmasked_scorezMLE.unmasked_score   s&   € ð ×"Ò" 7Ñ+Ô+×0Ò0°Ñ6Ô6Ð6ó    ©N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   © r   r   r	   r	      s2   € € € € € ðð ð
7ð 7ð 7ð 7ð 7ð 7r   r	   c                   ó*   ‡ — e Zd ZdZˆ fd„Zdd„Zˆ xZS )ÚLidstonez«Provides Lidstone-smoothed scores.

    In addition to initialization arguments from BaseNgramModel also requires
    a number by which to increase the counts, gamma.
    c                 óH   •—  t          ¦   «         j        |i |¤Ž || _        d S r   )ÚsuperÚ__init__Úgamma)r   r   ÚargsÚkwargsÚ	__class__s       €r   r   zLidstone.__init__%   ó*   ø€ Ø�‰ŒÔ˜$Ð) &Ð)Ð)Ð)ØˆŒ
ˆ
ˆ
r   Nc                 ó¸   — |                       |¦  «        }||         }|                     ¦   «         }|| j        z   |t          | j        ¦  «        | j        z  z   z  S )ztAdd-one smoothing: Lidstone or Laplace.

        To see what kind, look at `gamma` attribute on the class.

        )r   ÚNr   ÚlenÚvocab©r   r   r   ÚcountsÚ
word_countÚ
norm_counts         r   r   zLidstone.unmasked_score)   sS   € ð ×$Ò$ WÑ-Ô-ˆØ˜D”\ˆ
Ø—X’X‘Z”Zˆ
Ø˜TœZÑ'¨J½¸T¼Z¹¼È4Ì:Ñ9UÑ,UÑVÐVr   r   ©r   r   r   r   r   r   Ú__classcell__©r!   s   @r   r   r      s^   ø€ € € € € ðð ðð ð ð ð ð	Wð 	Wð 	Wð 	Wð 	Wð 	Wð 	Wð 	Wr   r   c                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚLaplacezwImplements Laplace (add one) smoothing.

    Initialization identical to BaseNgramModel because gamma is always 1.
    c                 óB   •—  t          ¦   «         j        dg|¢R i |¤Ž d S )Né   )r   r   )r   r   r    r!   s      €r   r   zLaplace.__init__;   s0   ø€ Ø�‰ŒÔ˜Ð,˜TÐ,Ð,Ð, VÐ,Ð,Ð,Ð,Ð,r   ©r   r   r   r   r   r,   r-   s   @r   r/   r/   5   sB   ø€ € € € € ðð ð
-ð -ð -ð -ð -ð -ð -ð -ð -r   r/   c                   ó,   ‡ — e Zd ZdZdˆ fd„	Zdd„Zˆ xZS )ÚStupidBackoffa8  Provides StupidBackoff scores.

    In addition to initialization arguments from BaseNgramModel also requires
    a parameter alpha with which we scale the lower order probabilities.
    Note that this is not a true probability distribution as scores for ngrams
    of the same order do not sum up to unity.
    çš™™™™™Ù?c                 óH   •—  t          ¦   «         j        |i |¤Ž || _        d S r   )r   r   Úalpha)r   r7   r   r    r!   s       €r   r   zStupidBackoff.__init__H   r"   r   Nc                 ó  — |s| j         j                             |¦  «        S |                      |¦  «        }||         }|                     ¦   «         }|dk    r||z  S | j        |                      ||dd …         ¦  «        z  S )Nr   r1   )r(   Úunigramsr   r   r$   r7   r   r'   s         r   r   zStupidBackoff.unmasked_scoreL   s…   € Øð 	3à”;Ô'×,Ò,¨TÑ2Ô2Ð2Ø×$Ò$ WÑ-Ô-ˆØ˜D”\ˆ
Ø—X’X‘Z”Zˆ
Ø˜Š>ˆ>Ø 
Ñ*Ð*à”: × 3Ò 3°D¸'À!À"À"¼+Ñ FÔ FÑFÐFr   )r5   r   r+   r-   s   @r   r4   r4   ?   sc   ø€ € € € € ðð ðð ð ð ð ð ð
Gð 
Gð 
Gð 
Gð 
Gð 
Gð 
Gð 
Gr   r4   c                   ó*   ‡ — e Zd ZdZˆ fd„Zdd„Zˆ xZS )ÚInterpolatedLanguageModelz¡Logic common to all interpolated language models.

    The idea to abstract this comes from Chen & Goodman 1995.
    Do not instantiate this class directly!
    c                 óš   •— |                      di ¦  «        } t          ¦   «         j        |fi |¤Ž  || j        | j        fi |¤Ž| _        d S )NÚparams)Úpopr   r   r&   r(   Ú	estimator)r   Úsmoothing_clsÚorderr    r=   r!   s        €r   r   z"InterpolatedLanguageModel.__init__`   sX   ø€ Ø—’˜H bÑ)Ô)ˆØ�‰ŒÔ˜Ð)Ð) &Ð)Ð)Ð)Ø&˜ t¤z°4´;ÐIÐIÀ&ÐIÐIˆŒˆˆr   Nc                 óä   — |s| j                              |¦  «        S | j        |         sd\  }}n| j                              ||¦  «        \  }}|||                      ||dd …         ¦  «        z  z   S )N)r   r1   r1   )r?   Úunigram_scorer(   Úalpha_gammar   )r   r   r   r7   r   s        r   r   z(InterpolatedLanguageModel.unmasked_scoree   s€   € Øð 	6à”>×/Ò/°Ñ5Ô5Ð5ØŒ{˜7Ô#ð 	Eð  ‰LˆE�5�5àœ>×5Ò5°d¸GÑDÔD‰LˆE�5Ø�u˜t×2Ò2°4¸ÀÀÀ¼ÑEÔEÑEÑEÐEr   r   r+   r-   s   @r   r;   r;   Y   sc   ø€ € € € € ðð ðJð Jð Jð Jð Jð
Fð Fð Fð Fð Fð Fð Fð Fr   r;   c                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚWittenBellInterpolatedz.Interpolated version of Witten-Bell smoothing.c                 óH   •—  t          ¦   «         j        t          |fi |¤Ž d S r   )r   r   r   )r   rA   r    r!   s      €r   r   zWittenBellInterpolated.__init__v   s*   ø€ Ø�‰ŒÔ� UÐ5Ð5¨fÐ5Ð5Ð5Ð5Ð5r   r2   r-   s   @r   rF   rF   s   s>   ø€ € € € € Ø8Ð8ð6ð 6ð 6ð 6ð 6ð 6ð 6ð 6ð 6r   rF   c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )ÚAbsoluteDiscountingInterpolatedz9Interpolated version of smoothing with absolute discount.ç      è?c                 óP   •—  t          ¦   «         j        t          |fdd|ii|¤Ž d S )Nr=   Údiscount)r   r   r   ©r   rA   rL   r    r!   s       €r   r   z(AbsoluteDiscountingInterpolated.__init__}   sG   ø€ Ø�‰ŒÔÝ ð	
ð 	
Ø0:¸HÐ/Eð	
ØIOð	
ð 	
ð 	
ð 	
ð 	
r   )rJ   r2   r-   s   @r   rI   rI   z   sC   ø€ € € € € ØCÐCð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
r   rI   c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )ÚKneserNeyInterpolatedz-Interpolated version of Kneser-Ney smoothing.çš™™™™™¹?c                 óŽ   •— d|cxk    rdk    sn t          d¦  «        ‚ t          ¦   «         j        t          |fd||dœi|¤Ž d S )Nr   r1   zCDiscount must be between 0 and 1 for probabilities to sum to unity.r=   )rL   rA   )Ú
ValueErrorr   r   r   rM   s       €r   r   zKneserNeyInterpolated.__init__†   s€   ø€ Ø�XÐ"Ð"Ò"Ð" Ò"Ð"Ð"Ð"ÝØUñô ð ð 	�‰ŒÔÝ�uð	
ð 	
Ø2:ÀUÐ%KÐ%Kð	
ØOUð	
ð 	
ð 	
ð 	
ð 	
r   )rP   r2   r-   s   @r   rO   rO   ƒ   sC   ø€ € € € € Ø7Ð7ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
r   rO   N)r   Únltk.lm.apir   r   Únltk.lm.smoothingr   r   r   r	   r   r/   r4   r;   rF   rI   rO   r   r   r   ú<module>rU      s¸  ðð Ð à 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ Hð7ð 7ð 7ð 7ð 7ˆ-ñ 7ô 7ð 7ð Wð Wð Wð Wð Wˆ}ñ Wô Wð Wð.-ð -ð -ð -ð -ˆhñ -ô -ð -ðGð Gð Gð Gð G�Mñ Gô Gð Gð4Fð Fð Fð Fð F ñ Fô Fð Fð46ð 6ð 6ð 6ð 6Ð6ñ 6ô 6ð 6ð
ð 
ð 
ð 
ð 
Ð&?ñ 
ô 
ð 
ð

ð 

ð 

ð 

ð 

Ð5ñ 

ô 

ð 

ð 

ð 

r   