void Eliza::preProcessResponse() { if(is_template(m_sResponse)) { findSymbol(m_sResponse); if(m_sKeyWord == m_sInput) { m_sSuffix = m_sInput; } else if(!m_bMemoryRecall){ extract_suffix(); } else { m_bMemoryRecall = 0; } if(m_sSuffix.length() == 0) { while(is_template(m_sResponse) && response_list.size() > 1) { response_list.erase(response_list.begin()); m_sResponse = response_list[0]; } if(is_template(m_sResponse)) { response_list = topicChanger; select_response(); } } if(m_sSuffix.length() > 0 && m_sSymbol != "%") { transpose_sentence(m_sSuffix); correct_sentence(m_sSuffix); trimRight(m_sSuffix, ' '); m_sSuffix.insert(0, " "); } replace(m_sResponse, m_sSymbol, m_sSuffix); } if(m_sUserName != "USER") { replace(m_sResponse, "USER", m_sUserName); } }
// this function makes sure that the bot doesn't // repeats itself too much during the conversation inline void Eliza::handle_repetition() { while(bot_is_repeating()) { if(response_list.size() > 1) { response_list.erase(response_list.begin()); } else { break; } select_response(); preProcessResponse(); } if(bot_is_repeating()) { if(memory.size() > 0) { remind_prev_subject(); } else { response_list = topicChanger; } select_response(); preProcessResponse(); } vResponseLog.push_back(m_sResponse); }
void Eliza::start() { time_t ltime; time(<ime); logfile.open("log.txt", std::ios::out | std::ios::app); if(logfile.fail()) { throw std::string("can't save conversation log"); } logfile << "\n\nConversation log - " << ctime(<ime) << std::endl; response_list = signOn; select_response(); print_response(); save_log("ELIZA"); }
void CBot::handle_repetition() { if(response_list.size() > 0) { response_list.erase(response_list.begin()); } if(no_response()) { save_input(); set_input(m_sEvent); find_match(); restore_input(); } select_response(); }
void CBot::respond() { save_prev_response(); set_event("BOT UNDERSTAND**"); if(null_input()) { handle_event("NULL INPUT**"); } else if(null_input_repetition()) { handle_event("NULL INPUT REPETITION**"); } else if(user_repeat()) { handle_user_repetition(); } else { find_match(); } if(user_want_to_quit()) { m_bQuitProgram = 1; } if(!bot_understand()) { handle_event("BOT DON'T UNDERSTAND**"); } if(response_list.size() > 0) { select_response(); preprocess_response(); if(bot_repeat()) { handle_repetition(); } print_response(); } }
string ofxEliza::start(string _logFile){ time_t ltime; time(<ime); logfile.open( ofToDataPath(_logFile).c_str(), std::ios::out | std::ios::app); if(logfile.fail()) { throw std::string("can't save conversation log"); } logfile << "\n\nConversation log - " << ctime(<ime) << std::endl; response_list = signOn; select_response(); if(m_sResponse.length() > 0) { std::cout << m_sResponse; } saveLog("ELIZA"); return m_sResponse; }
string ofxEliza::ask(string _inputString){ // gets input from the user save_prev_input(); m_sInput = _inputString; saveLog("USER"); // Finds and display a response // to the current input of the user. // removes punctuation from the input // and do some more preprocessing if(m_sInput.length() > 0) { tok.cleanString(m_sInput, " ?!,;"); trimRight(m_sInput, '.'); UpperCase(m_sInput); m_sInput.insert(0, " "); m_sInput.append(" "); } save_prev_responses(); save_prev_response(); if(null_input()) { handle_null_input(); } else if(user_repeat()) { handle_user_repetition(); } else if(short_input()) { handle_short_input(); } else { reset_repeat_count(); reset_short_input_count(); find_response(); } select_response(); preProcessResponse(); handle_repetition(); saveLog("ELIZA"); return m_sResponse; }
// these function finds and display a response // to the current input of the user. void Eliza::respond() { preProcessInput(); save_prev_responses(); save_prev_response(); if(null_input()) { handle_null_input(); } else if(user_repeat()) { handle_user_repetition(); } else { reset_repeat_count(); find_response(); } select_response(); preProcessResponse(); check_quit_message(); handle_repetition(); print_response(); save_log("ELIZA"); }
void CBot::signon() { handle_event("SIGNON**"); select_response(); print_response(); }