ó
ù`]c           @   sO   d  Z  d d l m Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(	   s…   Smoothing algorithms for language modeling.

According to Chen & Goodman 1995 these should work with both Backoff and
Interpolation.
iÿÿÿÿ(   t	   Smoothingc         C   s   t  d „  |  j ƒ  Dƒ ƒ S(   Nc         s   s!   |  ] } | d  k r d Vq d S(   i    g      ð?N(    (   t   .0t   c(    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pys	   <genexpr>   s    (   t   sumt   values(   t
   dictionary(    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyt   _count_non_zero_vals   s    t
   WittenBellc           B   s>   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s   Witten-Bell smoothing.gš™™™™™¹?c         K   s    t  t |  ƒ j | | | Œ d  S(   N(   t   superR   t   __init__(   t   selft
   vocabularyt   countert   discountt   kwargs(    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyR	      s    c         C   s-   |  j  | ƒ } d | |  j | | ƒ | f S(   Ng      ð?(   t   gammat   alpha(   R
   t   wordt   contextR   (    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyt   alpha_gamma   s    c         C   s   |  j  j j | ƒ S(   N(   t   countst   unigramst   freq(   R
   R   (    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyt   unigram_score   s    c         C   s   |  j  | j | ƒ S(   N(   R   R   (   R
   R   R   (    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyR   "   s    c         C   s6   t  |  j | ƒ } | | |  j t | ƒ d j ƒ  S(   Ni   (   R   R   t   lent   N(   R
   R   t   n_plus(    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyR   %   s    (   t   __name__t
   __module__t   __doc__R	   R   R   R   R   (    (    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyR      s   			t	   KneserNeyc           B   s>   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s   Kneser-Ney Smoothing.gš™™™™™¹?c         K   s)   t  t |  ƒ j | | | Œ | |  _ d  S(   N(   R   R   R	   R   (   R
   R   R   R   R   (    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyR	   -   s    c         C   s   d t  |  j ƒ S(   Ng      ð?(   R   t   vocab(   R
   R   (    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyR   1   s    c         C   s,   |  j  | } |  j | | ƒ |  j | ƒ f S(   N(   R   R   R   (   R
   R   R   t   prefix_counts(    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyR   4   s    c         C   s"   t  | | |  j d ƒ | j ƒ  S(   Ng        (   t   maxR   R   (   R
   R   R    (    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyR   8   s    c         C   s   |  j  t | ƒ | j ƒ  S(   N(   R   R   R   (   R
   R    (    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyR   ;   s    (   R   R   R   R	   R   R   R   R   (    (    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyR   *   s   			N(   R   t   nltk.lm.apiR    R   R   R   (    (    (    s0   lib/python2.7/site-packages/nltk/lm/smoothing.pyt   <module>   s   	