JL i0ddlZddlZiddddddddd d d d d dddddddddddddddddddZGddZy)Nzi amzyou arezi waszyou wereiyouzi'mzi'dz you wouldzi'vezyou havezi'llzyou willmyyourzI amzI waszyou'vezI havezyou'llzI willyoursminemec6eZdZifdZdZdZdZdZddZy) Chatc|Dcgc]+\}}tj|tj|f-c}}|_||_|j |_ycc}}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)recompile IGNORECASE_pairs _reflections_compile_reflections_regex)selfpairs reflectionsxys T/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/chat/util.py__init__z Chat.__init__#sN HMMVa 1bmm4a8M '//1 Ns0Ac t|jtd}tjdj dj ttj|tjS)NT)keyreversez\b({})\b|) sortedrlenr rformatjoinmapescaper)r sorted_refls rrzChat._compile_reflections7sOT..CF zz   sxxBII{(CD Er}}  c^jjfd|jS)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 ctj|j|j|jS)N)rstringstartend)mors rz"Chat._substitute..Hs)t((288:)IJr&)rsublower)rstrs` r _substitutezChat._substitute=s%{{ JCIIK  r&c|jd}|dk\rZt||dz|dz}|d||j|j|z||dzdz}|jd}|dk\rZ|S)N%r)findintr1group)rresponsematchposnums r _wildcardszChat._wildcardsKsmmC QhhsQwq12C#""5;;s#345379%&  --$CQhr&c|jD]c\}}|j|}|stj|}|j ||}|dddk(r|dddz}|dddk(r|dddz}|cSy)z Generate a response to the user input. :type str: str :param str: The string to be mapped :rtype: str Nz?..z???)rr:randomchoicer=)rr0patternr9r:resps rrespondz Chat.respondWs"&  GXMM#&E}}X.tU39$9s?D9$9s?D  r&cd}||k7rE|} td}|r.|ddvr |dd}|ddvr t|j|||k7rDyy#t$rt|YNwxYw)N>z!.)inputEOFErrorprintrF)rquit user_inputs rconversez Chat.converseqs D J ""3Z  n,!+CRJ!n,dll:./D  "j! "s AA%$A%N)rN) __name__ __module__ __qualname__rrr1r=rFrPr&rr r "s#*,2(   4 0r&r )rBr rr rTr&rrUs  I Z 9   ;   J  J &v h h D V 4  %! (Z0Z0r&