The Do It Yourself Chatbot Project
The system presented here is often referred to as an "ELIZA" type Chatbot, in reference to the famous computer program by Joseph Weizenbaum.
Although a lot has happened in the world of artificial intelligence and natural language processing since Weizenbaum created ELIZA in 1966, the core techniques in that work can be seen in many of the most successful Chatbot implementations of today. The flagship of these conversation simulating techniques is that of reformulating statements made by the user and echoing them back as questions. If a user says "Nobody likes me." an ELIZA type system might respond with "Why do you say that nobody likes you?" or "How does it make you feel that nobody likes you?" It is easy to see how a large number of such phrases could be devised that would create appropriate responses to many inputs. One particular aspect of this method to note is that before turning the statement into a question, the program swaps the word "me" entered by the user, for the word "you."
In addition to the direct echoing described above, Chatbots are frequently programmed to respond to certain key words as triggers. If the user input contains the term "science fiction" the program might respond "Who is your favorite science fiction author?" In such a trigger mode, the program does not take into consideration any context, but takes a calculated risk that a well constructed response will be at least somewhat appropriate.
As a last ditch effort, or what I refer to as a graceful fail, a proper Chatbot will have an arsenal of generic responses and subject changers that keep the conversation going. Examples might be "I see, please tell me more." or "Do you have any hobbies?"
To setup (or program) your Chatbot you will arrange a list of user statements and systems responses. The statements and responses are coded using a pattern matching technique known as regular expressions which facilitate quite handily the ELIZA type transformations described above.
The basic functioning of the shell program goes like this:
Although this system is very simple, and intended primarily as a jumping-off point for developing your own systems, it is possible to build quite a substantial verbal response robot using only the shell as presented here.