
    g0                         d dl Z d dlZi ddddddddd	d
ddddddddddddddddddddddZ G d d      Zy)    Nzi amzyou arezi waszyou wereiyouzi'mzi'dz	you wouldzi'vezyou havezi'llzyou willmyyourzI amzI waszyou'vezI havezyou'llzI willyoursminemec                   6    e Zd Zi fdZd Zd Zd Zd ZddZy)	Chatc                     |D cg c]+  \  }}t        j                  |t         j                        |f- c}}| _        || _        | j                         | _        yc c}}w )a  
        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)recompile
IGNORECASE_pairs_reflections_compile_reflections_regex)selfpairsreflectionsxys        C/var/www/openai/venv/lib/python3.12/site-packages/nltk/chat/util.py__init__zChat.__init__#   sR      HMMuVa

1bmm4a8uM'//1 Ns   0Ac           
          t        | j                  t        d      }t        j                  dj                  dj                  t        t        j                  |                  t        j                        S )NT)keyreversez\b({})\b|)
sortedr   lenr   r   formatjoinmapescaper   )r   sorted_refls     r   r   zChat._compile_reflections7   sO    T..CFzzsxxBII{(CDEr}}
 	
    c                 ^      j                   j                   fd|j                               S )z
        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                 t    j                   | j                  | j                         | j                             S )N)r   stringstartend)mor   s    r   <lambda>z"Chat._substitute.<locals>.<lambda>H   s'    t((288:)IJr&   )r   sublower)r   strs   ` r   _substitutezChat._substitute=   s%     {{JCIIK
 	
r&   c                     |j                  d      }|dk\  rZt        ||dz   |dz          }|d | | j                  |j                  |            z   ||dz   d  z   }|j                  d      }|dk\  rZ|S )N%r         )findintr1   group)r   responsematchposnums        r   
_wildcardszChat._wildcardsK   s    mmC QhhsQwq12C#""5;;s#345379%& 
 --$C Qh r&   c                     | j                   D ]c  \  }}|j                  |      }|st        j                  |      }| j	                  ||      }|dd dk(  r|dd dz   }|dd dk(  r|dd dz   }|c S  y)z
        Generate a response to the user input.

        :type str: str
        :param str: The string to be mapped
        :rtype: str
        Nz?..z???)r   r:   randomchoicer=   )r   r0   patternr9   r:   resps         r   respondzChat.respondW   s     "&GXMM#&E }}X.tU3 9$9s?D9$9s?D "-r&   c                     d}||k7  rE|}	 t        d      }|r.|d   dv r|d d }|d   dv rt        | j                  |             ||k7  rDy y # t        $ r t        |       Y Nw xY w)N >z!.)inputEOFErrorprintrF   )r   quit
user_inputs      r   conversezChat.converseq   s    
D J""3Z
  n,!+CRJ !n,dll:./ D   "j!"s   A A%$A%N)rN   )	__name__
__module____qualname__r   r   r1   r=   rF   rP    r&   r   r   r   "   s#    *, 2(


40r&   r   )rB   r   r   r   rT   r&   r   <module>rU      s     	
IZ  
9	
 
; J J 	& v  h h D V 
4  	%!(Z0 Z0r&   