ó
ù`]c           @  sÈ   d  d l  m Z d  d l Z d  d l Z d  d l m Z i d d 6d d 6d d	 6d d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   print_functionN(   t   inputs   you ares   i ams   you weres   i wast   yout   is   i'ms	   you woulds   i'ds   you haves   i'ves   you wills   i'llt   yourt   mys   I ams   I wass   I haves   you'ves   I wills   you'llt   minet   yourst   met   Chatc           B  sD   e  Z i  d  „ Z d „  Z d „  Z d „  Z d „  Z d d „ Z RS(   c         C  sS   g  | D]' \ } } t  j | t  j ƒ | f ^ q |  _ | |  _ |  j ƒ  |  _ d S(   sÃ  
        Initialize the chatbot.  Pairs is a list of patterns and responses.  Each
        pattern is a regular expression matching the user's statement or question,
        e.g. r'I like (.*)'.  For each such pattern a list of possible responses
        is given, e.g. ['Why do you like %1', 'Did you ever dislike %1'].  Material
        which is matched by parenthesized sections of the patterns (e.g. .*) is mapped to
        the numbered positions in the responses, e.g. %1.

        :type pairs: list of tuple
        :param pairs: The patterns and responses
        :type reflections: dict
        :param reflections: A mapping between first and second person expressions
        :rtype: None
        N(   t   ret   compilet
   IGNORECASEt   _pairst   _reflectionst   _compile_reflectionst   _regex(   t   selft   pairst   reflectionst   xt   y(    (    s-   lib/python2.7/site-packages/nltk/chat/util.pyt   __init__'   s    7	c         C  sR   t  |  j j ƒ  d t d t ƒ} t j d j d j t	 t j
 | ƒ ƒ ƒ t j ƒ S(   Nt   keyt   reverses	   \b({0})\bt   |(   t   sortedR   t   keyst   lent   TrueR
   R   t   formatt   joint   mapt   escapeR   (   R   t   sorted_refl(    (    s-   lib/python2.7/site-packages/nltk/chat/util.pyR   ;   s    !c           s"   ˆ  j  j ‡  f d †  | j ƒ  ƒ S(   sÑ   
        Substitute words in the string, according to the specified reflections,
        e.g. "I'm" -> "you are"

        :type str: str
        :param str: The string to be mapped
        :rtype: str
        c           s!   ˆ  j  |  j |  j ƒ  |  j ƒ  !S(   N(   R   t   stringt   startt   end(   t   mo(   R   (    s-   lib/python2.7/site-packages/nltk/chat/util.pyt   <lambda>L   t    (   R   t   subt   lower(   R   t   str(    (   R   s-   lib/python2.7/site-packages/nltk/chat/util.pyt   _substituteA   s    
	c         C  s|   | j  d ƒ } xf | d k rw t | | d | d !ƒ } | |  |  j | j | ƒ ƒ | | d } | j  d ƒ } q W| S(   Nt   %i    i   i   (   t   findt   intR,   t   group(   R   t   responset   matcht   post   num(    (    s-   lib/python2.7/site-packages/nltk/chat/util.pyt
   _wildcardsO   s    ,c         C  sš   x“ |  j  D]ˆ \ } } | j | ƒ } | r
 t j | ƒ } |  j | | ƒ } | d d k rm | d  d } n  | d d k rŽ | d  d } n  | Sq
 Wd S(   s   
        Generate a response to the user input.

        :type str: str
        :param str: The string to be mapped
        :rtype: str
        iþÿÿÿs   ?.t   .s   ??t   ?N(   R   R2   t   randomt   choiceR5   (   R   R+   t   patternR1   R2   t   resp(    (    s-   lib/python2.7/site-packages/nltk/chat/util.pyt   respond[   s    
t   quitc         C  sŽ   d } x | | k r‰ | } y t  d ƒ } Wn t k
 rH t | ƒ n X| r	 x | d d k ro | d  } qR Wt |  j | ƒ ƒ q	 q	 Wd  S(   NR(   t   >iÿÿÿÿs   !.(   R   t   EOFErrort   printR<   (   R   R=   t
   user_input(    (    s-   lib/python2.7/site-packages/nltk/chat/util.pyt   converseu   s    (   t   __name__t
   __module__R   R   R,   R5   R<   RB   (    (    (    s-   lib/python2.7/site-packages/nltk/chat/util.pyR	   &   s   				(	   t
   __future__R    R
   R8   t	   six.movesR   R   t   objectR	   (    (    (    s-   lib/python2.7/site-packages/nltk/chat/util.pyt   <module>
   s*   
