-
Small Chatbot problem
Hi there. I wish to create a simple chatbot program, and I got the jist of making a VERY simple one, however, I would like the bot to spit back the input for a few set input when answering, and I am a little unsure how to make that happen.
For example, when the sentence starts with "Do you like"
in: "Do you like (text) ?
out: "No, I do not like (text).
A little help would be very much appreciated. Thank you.
-
I would create a map of sentence fragments where the keys/values are input/output text. You might want this map to be read from a file so you can add/change the responses easily without recompiling the program.
-
You need a regular expression, that pattern matches on the whole string, with grabbing parenthesis on what you want grabbed and repeated. Something like this:
/^Do you like (.*)?$/
A function that matches on that should return the part that matches the parenthesis. The details of how to write the call depend on the regular expression tool or library used. You should find one for a project like this.
I would also discourage the use of C++ for this. A scripting language like python is more suitable, and has a standard regular expression library. You can also use an existing engine, and just write the AI rules. For example, Pandorabots provides web hostring for such chatbots written using AIML.
-
Also, C++11 have support for regular expressions just fine: <regex> - C++ Reference.
Dunno about the other bits.