ó
ù`]c           @  sû   d  Z  d d l m Z m Z d d l m Z d d l m Z m Z d d l	 m
 Z
 m Z e j d e f d „  ƒ  Yƒ Z e j d e f d	 „  ƒ  Yƒ Z e j d
 e f d „  ƒ  Yƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   u   Language Modelsiÿÿÿÿ(   t   divisiont   unicode_literals(   t   compat(   t   LanguageModelt	   Smoothing(   t	   KneserNeyt
   WittenBellt   MLEc           B  s   e  Z d  Z d d „ Z RS(   ub   Class for providing MLE ngram model scores.

    Inherits initialization from BaseNgramModel.
    c         C  s   |  j  | ƒ j | ƒ S(   uÄ   Returns the MLE score for a word given a context.

        Args:
        - word is expcected to be a string
        - context is expected to be something reasonably convertible to a tuple
        (   t   context_countst   freq(   t   selft   wordt   context(    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyt   unmasked_score   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   (    (    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR      s   t   Lidstonec           B  s#   e  Z d  Z d „  Z d d „ Z RS(   u«   Provides Lidstone-smoothed scores.

    In addition to initialization arguments from BaseNgramModel also requires
    a number by which to increase the counts, gamma.
    c         O  s&   t  t |  ƒ j | | Ž  | |  _ d  S(   N(   t   superR   t   __init__t   gamma(   R
   R   t   argst   kwargs(    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR   )   s    c         C  sH   |  j  | ƒ } | | } | j ƒ  } | |  j | t |  j ƒ |  j S(   ut   Add-one smoothing: Lidstone or Laplace.

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

        (   R   t   NR   t   lent   vocab(   R
   R   R   t   countst
   word_countt
   norm_count(    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR   -   s    
N(   R   R   R   R   R   R   (    (    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR   !   s   	t   Laplacec           B  s   e  Z d  Z d „  Z RS(   uw   Implements Laplace (add one) smoothing.

    Initialization identical to BaseNgramModel because gamma is always 1.
    c         O  s    t  t |  ƒ j d | | Ž d  S(   Ni   (   R   R   R   (   R
   R   R   (    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR   @   s    (   R   R   R   R   (    (    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR   9   s   t   InterpolatedLanguageModelc           B  s#   e  Z d  Z d „  Z d d „ Z RS(   uu   Logic common to all interpolated language models.

    The idea to abstract this comes from Chen & Goodman 1995.
    c         K  s_   t  | t ƒ s t ‚ | j d i  ƒ } t t |  ƒ j | |  | |  j |  j |  |  _	 d  S(   Nu   params(
   t
   issubclassR   t   AssertionErrort   popR   R   R   R   R   t	   estimator(   R
   t   smoothing_clst   orderR   t   params(    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR   J   s    c         C  sM   | s |  j  j | ƒ S|  j  j | | ƒ \ } } | | |  j | | d ƒ S(   Ni   (   R#   t   unigram_scoret   alpha_gammaR   (   R
   R   R   t   alphaR   (    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR   P   s    N(   R   R   R   R   R   R   (    (    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR   D   s   	t   WittenBellInterpolatedc           B  s   e  Z d  Z d „  Z RS(   u.   Interpolated version of Witten-Bell smoothing.c         K  s    t  t |  ƒ j t | |  d  S(   N(   R   R*   R   R   (   R
   R%   R   (    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR   Z   s    (   R   R   R   R   (    (    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR*   W   s   t   KneserNeyInterpolatedc           B  s   e  Z d  Z d d „ Z RS(   u-   Interpolated version of Kneser-Ney smoothing.gš™™™™™¹?c         K  s-   t  t |  ƒ j t | d i | d 6| d  S(   NR&   u   discount(   R   R+   R   R   (   R
   R%   t   discountR   (    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR   a   s    (   R   R   R   R   (    (    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyR+   ^   s   N(   R   t
   __future__R    R   t   nltkR   t   nltk.lm.apiR   R   t   nltk.lm.smoothingR   R   t   python_2_unicode_compatibleR   R   R   R   R*   R+   (    (    (    s-   lib/python2.7/site-packages/nltk/lm/models.pyt   <module>   s   			
