Chat BOT Sample

ok, as some of you know i am working on a chat bot. Problem is i am a visual learner in some cases, and i am so stuck on the string comparing and such i am going to do something i don't normally do because i don't like to. I am asking for anyone who has made a chat bot based on two text files for answers/keywords to supply me, if willing, with the source code so i can study it.

No code will be used or claimed as my own, its to aid me to learn the concepts of different methods, thank you to all who took the time to read this.

You're missing my point. AIML is a way of cribbing statments with responses. In the same way you wouldn't write a browser application with HTML, you would still use C++ to write your chatbot application.

If you don't want to use AIML at all, OK. But it still may be worth taking a look. I believe, there is a lot free AIML data (kind of knowledge moduls) out there, covering all sorts of converstaion topics.

I thought this is what you wanted. You take the AIML files, and extract the data & put it into any format you chose. But it's just an idea after all.

Ok so basically you need to search a file for a certain string, get its index number (be it 1, 2, 3 etc) and search another file for responses with that index?

You'll need to come up with a file format, say:

%1%3

Hello;
Good Day;
Hi;

%2%4

Good;
Great;
Grand;
Splendid;

First number is its index, second is the number of entries. Apon reading the number of entries you could generate a random number, and choose that response.

Look into strtok for breaking up the users input. So basically:

Code:

Get user input.
Open the responses file.
Loop for each word in the users input
{
Read in each word in the file
if any of them match the word we're currently checking
{
push the index number onto a vector
}
}
while we're not at the last vector element
{
Keep a counter of how many instances found for each number
}
Find the index number we isolated in the responses file
read the number of entries for that index
Generate a random number between 1 and the number
while we're not on the correct response
{
read another response
}
Display it.

int indicies[256]; // Holds the instances of each index number for which a matching string/response entered
memset(reinterpret_cast<void *>(indicies), 0, sizeof(indicies)); // Set it to 0
rhead response; // Holds information about the response strings

if (std::strncmp(pInputToken, pszBuffer) == 0) // if the current word matches the one in the file
{
indicies[response.index]++; // Increment our instance count for the current index
}
}
}
pToken = std::strtok(pszInput, NULL); // Get a new word
fResponses.seekg(0, std::ios::beg); // Back to the start
}

fResponses.seekg(0, std::ios::beg); // Back to the start
while (fResponses.eof() == 0)
{
fResponses.getline(pszBuffer, 127, ';');
if (strchr(pszBuffer, '%')) // If this is a response header
{
if (atoi(pszBuffer[1]) == response.index) // if the best fit index is equal to the one we just extracted
{
response.entries = atoi(pszBuffer[3]); // Same as above
break;
}
}
}