Thread: Chat BOT Sample

  1. #1
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

    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.

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  3. #3
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    i want to stay with c++.

  4. #4
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105
    You like spam? hmmm taste good!

  5. #5
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    >i want to stay with c++

    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.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  6. #6
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    What exactly do you need done? If you explain it in more detail I (or someone else) may be able to whip some code up for you

  7. #7
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Sorry for my ignorance davros:

    what i need is a program that takes two text files, reads them in, takes a string from the user, searches the first text file for a match between whats in the file and a word(s) in the user input.

    It then responds accordingly based on the second file.

    Say you have in file one

    1 Hello
    2 How Are

    and in file two:

    1 Hello there
    2 I'm fine thanks!

    The user enters:

    Hello

    so the output is

    Hello there.

  8. #8
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    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.

  9. #9
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    that rlly helps to see someone elses algorithm, ok for loopingfor every word in input i would use a forloop w/ constant, ie

    const string Words_Entered = strlen(input);

    for ( ; Words_entered > 0; --Words_Entered)
    {
    }

    Just threw that in don't know if its accurate

  10. #10
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

    I'm back

    I must really love you...
    This probably won't work, but I needed to kill some time before hockey It should give you an idea of how my algorithm would work.

    PHP Code:
    #include <string>
    #include <cstdlib>
    #include <fstream>
    #include <iostream>

    struct rhead
    {
        
    int index;
        
    int entries;
    };

    // ...

    GetAStringFromTheUser(pszInput);

    // ...

    srand(time(NULL));
    std::ifstream fResponses("responses.dat"ios::in);

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

    char *pToken std::strtok(pszInput" ");
    while (
    pToken != NULL)
    {
        
    char pszBuffer[128];
        while (
    fResponses.eof() == 0)
        {
            
    fResponses.getline(pszBuffer127';'); // Read up to a semicolon
            
    if (strchr(pszBuffer'%')) // If this isn't a response
            
    {
                
    response.index atoi(pszBuffer[1]); // Current index eg %2%3;
                
    response.entries atoi(pszBuffer[3]); // Entries, see above

            
    } else {

                if (
    std::strncmp(pInputTokenpszBuffer) == 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(pszInputNULL);    // Get a new word
        
    fResponses.seekg(0std::ios::beg);    // Back to the start
    }

    int    largestIndexVal 0;

    for (
    int i 0256i++)    // Find the largest instance count for our indicies
    {
        if (
    indicies[i] > largestIndexVal)
        {
            
    response.index i;
            
    largestIndexVal indicies[i];
        }
    };

    fResponses.seekg(0std::ios::beg);    // Back to the start
    while (fResponses.eof() == 0)
    {
        
    fResponses.getline(pszBuffer127';');
        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;
            }
        }
    }

    if (
    fResponses.eof())    // Ahh! We couldn't find the index!
    {
        
    SomethingHasGoneTerriblyWrong();
        
    EndTheProgramOrAlertTheUser();
    } else {

        
    int randomResponse = (+ (rand() % response.entries));    // Generate a random number
        
    while (randomResponse--)
        {
            
    fResponses.getline(pszBuffer127';');    // read randomReponse times
        
    }
        
    DisplayTheStringOrDoSomethingElseWithIt(pszBuffer);    // Uhh, yeah the php tags messed the end up a little bit, we should have a closing bracket here...
    }; 
    Last edited by Eibro; 11-01-2002 at 03:10 PM.

  11. #11
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    easy on the "L" word there, dude :P

    Thnx i'll look this over tonight

  12. #12
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    It says theres an error, but not WHAT error.....odd...

    Code:
    --------------------Configuration: Marvin - Win32 Debug--------------------
    Compiling...
    Error spawning cl.exe
    
    Marvin.obj - 1 error(s), 0 warning(s)

  13. #13
    Registered User
    Join Date
    Jan 2002
    Posts
    77
    alright i got a lot of different problems than what you got ride or die...

    Code:
    --------------------Configuration: test5 - Win32 Debug--------------------
    Compiling...
    test5.cpp
    c:\documents and settings\default\test5.cpp(14) : error C2065: 'pszInput' : undeclared identifier
    c:\documents and settings\default\test5.cpp(14) : error C2501: 'GetAStringFromTheUser' : missing storage-class or type specifiers
    c:\documents and settings\default\test5.cpp(18) : error C2065: 'time' : undeclared identifier
    c:\documents and settings\default\test5.cpp(18) : error C2501: 'srand' : missing storage-class or type specifiers
    c:\documents and settings\default\test5.cpp(18) : error C2373: 'srand' : redefinition; different type modifiers
            c:\program files\microsoft visual studio\vc98\include\stdlib.h(308) : see declaration of 'srand'
    c:\documents and settings\default\test5.cpp(19) : error C2653: 'ios' : is not a class or namespace name
    c:\documents and settings\default\test5.cpp(19) : error C2065: 'in' : undeclared identifier
    c:\documents and settings\default\test5.cpp(22) : error C2501: 'memset' : missing storage-class or type specifiers
    c:\documents and settings\default\test5.cpp(22) : error C2373: 'memset' : redefinition; different type modifiers
            c:\program files\microsoft visual studio\vc98\include\string.h(103) : see declaration of 'memset'
    c:\documents and settings\default\test5.cpp(22) : error C2078: too many initializers
    c:\documents and settings\default\test5.cpp(25) : error C2039: 'strtok' : is not a member of 'std'
    c:\documents and settings\default\test5.cpp(26) : error C2143: syntax error : missing ';' before 'while'
    c:\documents and settings\default\test5.cpp(27) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\default\test5.cpp(27) : error C2447: missing function header (old-style formal list?)
    c:\documents and settings\default\test5.cpp(51) : error C2143: syntax error : missing ';' before 'for'
    c:\documents and settings\default\test5.cpp(51) : error C2143: syntax error : missing ')' before ';'
    c:\documents and settings\default\test5.cpp(51) : error C2143: syntax error : missing ';' before '<'
    c:\documents and settings\default\test5.cpp(51) : error C2501: 'i' : missing storage-class or type specifiers
    c:\documents and settings\default\test5.cpp(51) : error C2143: syntax error : missing ';' before '<'
    c:\documents and settings\default\test5.cpp(51) : error C2143: syntax error : missing ';' before '++'
    c:\documents and settings\default\test5.cpp(51) : error C2501: 'i' : missing storage-class or type specifiers
    c:\documents and settings\default\test5.cpp(51) : error C2086: 'i' : redefinition
    c:\documents and settings\default\test5.cpp(51) : error C2143: syntax error : missing ';' before '++'
    c:\documents and settings\default\test5.cpp(51) : error C2059: syntax error : ')'
    c:\documents and settings\default\test5.cpp(52) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\default\test5.cpp(52) : error C2447: missing function header (old-style formal list?)
    c:\documents and settings\default\test5.cpp(60) : error C2143: syntax error : missing ';' before '.'
    c:\documents and settings\default\test5.cpp(60) : error C2501: 'fResponses' : missing storage-class or type specifiers
    c:\documents and settings\default\test5.cpp(60) : error C2371: 'fResponses' : redefinition; different basic types
            c:\documents and settings\default\test5.cpp(19) : see declaration of 'fResponses'
    c:\documents and settings\default\test5.cpp(60) : error C2143: syntax error : missing ';' before '.'
    c:\documents and settings\default\test5.cpp(61) : error C2143: syntax error : missing ';' before 'while'
    c:\documents and settings\default\test5.cpp(62) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\default\test5.cpp(62) : error C2447: missing function header (old-style formal list?)
    c:\documents and settings\default\test5.cpp(74) : error C2143: syntax error : missing ';' before 'if'
    c:\documents and settings\default\test5.cpp(75) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\default\test5.cpp(75) : error C2447: missing function header (old-style formal list?)
    c:\documents and settings\default\test5.cpp(78) : error C2143: syntax error : missing ';' before 'else'
    c:\documents and settings\default\test5.cpp(78) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\default\test5.cpp(78) : error C2447: missing function header (old-style formal list?)
    Error executing cl.exe.
    
    test5.exe - 39 error(s), 0 warning(s)
    Hooked On Phonics Didn't Work For Me!

  14. #14
    Registered User
    Join Date
    Jan 2002
    Posts
    77
    ooopss didnt notice it at first but there is no .h's on any of the includes

    now i only get one error

    fatal error; cannot open include file cstdlib.h
    Hooked On Phonics Didn't Work For Me!

  15. #15
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    >> ooopss didnt notice it at first but there is no .h's on any of the includes

    That was deliberate.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Chat Bot Help!!
    By arealfind08 in forum C Programming
    Replies: 1
    Last Post: 03-09-2009, 06:52 AM
  2. Chat bot brain ideas
    By cogeek in forum C++ Programming
    Replies: 14
    Last Post: 10-02-2004, 12:26 AM
  3. Chat Bot: Multiple headers problem
    By RoD in forum C++ Programming
    Replies: 4
    Last Post: 03-26-2003, 06:07 PM
  4. Msvc Aim Chat Bot ???
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 09-19-2001, 08:46 AM
  5. Chat bot for AIM
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 09-08-2001, 02:10 PM