ó <¿CVc@sÈddlmZddlZddlZddlmZidd6dd6dd 6dd 6d d 6d d6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6Zdefd„ƒYZdS(iÿÿÿÿ(tprint_functionN(tcompatsyou aresi amsyou weresi wastyoutisi'ms you wouldsi'dsyou havesi'vesyou willsi'lltyourtmysI amsI wassI havesyou'vesI willsyou'lltminetyourstmetChatcBsDeZid„Zd„Zd„Zd„Zd„Zdd„ZRS(cCsSg|D]'\}}tj|tjƒ|f^q|_||_|jƒ|_dS(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(tretcompilet IGNORECASEt_pairst _reflectionst_compile_reflectionst_regex(tselftpairst reflectionstxty((s`/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/chat/util.pyt__init__$s7 cCsRt|jjƒdtdtƒ}tjdjdjt tj |ƒƒƒtj ƒS(Ntkeytreverses \b({0})\bt|( tsortedRtkeystlentTrueR R tformattjointmaptescapeR (Rt sorted_refl((s`/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/chat/util.pyR9s cs"ˆjj‡fd†|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 cs!ˆj|j|jƒ|jƒ!S(N(Rtstringtstarttend(tmo(R(s`/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/chat/util.pytIs(Rtsubtlower(Rtstr((Rs`/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/chat/util.pyt _substitute?s cCs||jdƒ}xf|dkrwt||d|d!ƒ}|| |j|j|ƒƒ||d}|jdƒ}qW|S(Nt%iii(tfindtintR+tgroup(Rtresponsetmatchtpostnum((s`/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/chat/util.pyt _wildcardsMscCsšx“|jD]ˆ\}}|j|ƒ}|r tj|ƒ}|j||ƒ}|ddkrm|d d}n|ddkrŽ|d d}n|Sq WdS(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 R1trandomtchoiceR4(RR*tpatternR0R1tresp((s`/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/chat/util.pytrespondWs tquitcCs‘d}x„||krŒ|}ytjdƒ}Wntk rKt|ƒnX|r x|ddkrr|d }qUWt|j|ƒƒq q WdS(Ntt>iÿÿÿÿs!.(Rt raw_inputtEOFErrortprintR;(RR<tinput((s`/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/chat/util.pytconverseos (t__name__t __module__RRR+R4R;RC(((s`/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/chat/util.pyR #s     ( t __future__RR R7tnltkRRtobjectR (((s`/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/chat/util.pyt s*