![]() The only real intelligence in it is involved in the creation of suitably vague response templates. So “I” becomes “you”, “your” becomes “my”, etc.Īs you can see, ELIZA is an extremely simple program. We iterate through the list of tokens and, if the token exists in our reflections dictionary, we replace it with the value from the dictionary. First, we make the statement lowercase, then we tokenize it by splitting on whitespace characters. There is nothing too complicated going on in it. ![]() Double asterisks (**) can be used to explode dictionaries into keyword arguments. A list or a tuple can be exploded into positional arguments using a single asterisk. Format expects a series of positional arguments corresponding to the number of format placeholders –, etc. When we use the list comprehension to generate a list of reflected match groups, we explode the list with the asterisk (*) character before passing it to the string’s format method. There is one syntactic oddity to note here. Then we interpolate the match groups from the regular expression into the response string, calling the reflect function on each match group first. If we find a match, we choose a response template randomly from the list of possible responses associated with the matching pattern. We iterate through the regular expressions in the psychobabble array, trying to match each one with the user’s statement, from which we have stripped the final punctuation. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |