
    Ng0                         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dS )    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                   8    e Zd Zi fdZd Zd Zd Zd Zd	dZdS )
Chatc                 h    d |D             | _         || _        |                                 | _        dS )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
        c                 V    g | ]&\  }}t          j        |t           j                  |f'S  )recompile
IGNORECASE).0xys      J/var/www/html/ai-engine/env/lib/python3.11/site-packages/nltk/chat/util.py
<listcomp>z!Chat.__init__.<locals>.<listcomp>3   s/    MMMVa
1bm44a8MMM    N)_pairs_reflections_compile_reflections_regex)selfpairsreflectionss      r   __init__zChat.__init__#   s9      NMuMMM'//11r   c           
          t          | j        t          d          }t          j        d                    d                    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   sZ    T.CFFFzsxxBI{(C(CDDEEr}
 
 	
r   c                 d      j                              fd|                                          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                     j         | j        |                                 |                                                   S )N)r   stringstartend)mor   s    r   <lambda>z"Chat._substitute.<locals>.<lambda>H   s+    t(288::3H)IJ r   )r   sublower)r   strs   ` r   _substitutezChat._substitute=   s3     {JJJJCIIKK
 
 	
r   c                 .   |                     d          }|dk    ryt          ||dz   |dz                      }|d |         |                     |                    |                    z   ||dz   d          z   }|                     d          }|dk    y|S )N%r         )findintr5   group)r   responsematchposnums        r   
_wildcardszChat._wildcardsK   s    mmC  QhhhsQwq0122C#""5;;s#3#34453799%& 
 --$$C Qhh r   c                    | j         D ]\  }}|                    |          }|rdt          j        |          }|                     ||          }|dd         dk    r|dd         dz   }|dd         dk    r|dd         dz   }|c S dS )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choicerA   )r   r4   patternr=   r>   resps         r   respondzChat.respondW   s     "& 	 	GXMM#&&E  	}X..tU33 9$$9s?D9$$9s?D			 	r   quitc                    d}||k    r||}	 t          d          }n# t          $ r t          |           Y nw xY w|r@|d         dv r|d d         }|d         dv t          |                     |                     ||k    zd S d S )N >z!.)inputEOFErrorprintrJ   )r   rK   
user_inputs      r   conversezChat.converseq   s    
D  J""3ZZ

 " " "j!!!!!" 0 n,,!+CRCJ !n,,dll:../// D      s    88N)rK   )	__name__
__module____qualname__r   r   r5   rA   rJ   rT   r   r   r   r   r   "   s{        *, 2 2 2 2(
 
 

 
 

 
 
  40 0 0 0 0 0r   r   )rF   r   r   r   r   r   r   <module>rX      s    				
IZ  
9	
 
; J J 	& v  h h D V 
4  	%!(Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0r   