void DatabaseManager::deleteRecordRange(const StringPimpl &key, const StringPimpl &range) { Dbc *cursor = NULL; try { Dbt dbKey((void *)key.c_str(), key.size() + 1); Dbt dbData((void *) range.c_str(), range.size() + 1); m_pimpl->checkTSSInit(); m_pimpl->m_database->cursor(&(**m_pimpl->m_transaction), &cursor, m_pimpl->m_cursorFlags); int ret = cursor->get(&dbKey, &dbData, DB_GET_BOTH_RANGE); while(ret != DB_NOTFOUND) { cursor->del(0); ret = cursor->get(&dbKey, &dbData, DB_NEXT); } cursor->close(); } catch (DbException &e) { std::cerr << "Error in addRecord: " << e.what() << e.get_errno() << std::endl; if(cursor != NULL) { cursor->close(); } } }
void ThatStar::setAttribute(const StringPimpl &name, const StringPimpl &value) throw(InternalProgrammerErrorException &) { LOG_BOT_METHOD("void ThatStar::setAttribute(const StringPimpl &name, const StringPimpl &value)"); String nameString(name.c_str()); String valueString(value.c_str()); logging("<Input> name:" + nameString); logging("<Input> value:" + valueString); try { if(nameString == "index" && (!valueString.empty())) { m_pimpl->m_index = lexical_cast<int>(valueString); } } catch(bad_lexical_cast &) { String msg("Index string is not numeric"); msg += valueString; m_pimpl->m_builder.getCallBacks().thatStarTagNumericConversionError(msg.c_str()); logging("Error, the cast to a numeric value failed"); } }
void DatabaseManager::printEntireDB() { Dbc *cursor = NULL; try { Dbt dbKey; Dbt dbData; m_pimpl->checkTSSInit(); m_pimpl->m_database->cursor(&(**m_pimpl->m_transaction), &cursor, m_pimpl->m_cursorFlags); int ret = cursor->get(&dbKey, &dbData, DB_SET_RANGE); while(ret != DB_NOTFOUND) { StringPimpl dataString = StringPimpl((char *) dbData.get_data()); StringPimpl keyString = StringPimpl((char *) dbKey.get_data()); cout << "key :" << keyString.c_str() << endl << "data:" << dataString.c_str() << endl << endl; ret = cursor->get(&dbKey, &dbData, DB_NEXT); } cursor->close(); } catch (DbException &e) { std::cerr << "Error in deleteRecordRange: " << e.what() << e.get_errno() << std::endl; if(cursor != NULL) { cursor->close(); } } }
void TestCasesHandler::TestCase::setAttribute(const StringPimpl &name, const StringPimpl &value) throw(InternalProgrammerErrorException &) { string nameString(name.c_str()); string valueString(value.c_str()); if(nameString == "name") { m_handler.outputln("Test Case name: " + valueString); } else { cout << "Error, wrong attribute" << endl; } }
void Bot::setAttribute(const StringPimpl &name, const StringPimpl &value) throw(InternalProgrammerErrorException &) { LOG_BOT_METHOD("void Bot::setAttribute(const StringPimpl &name, const StringPimpl &value)"); String nameString(name.c_str()); String valueString(value.c_str()); logging("<Input> name:" + nameString); logging("<Input> value:" + valueString); if(nameString == "name" && (!valueString.empty())) { m_pimpl->m_botPredicateName = valueString; } }
bool DatabaseManager::getRecord(const StringPimpl &key, StringPimpl &data, bool caseSensitive) { Dbt dbKey, dbData; StringPimpl caseInsensitive; if(!caseSensitive) { caseInsensitive = key; caseInsensitive.transformToUpperCase(); dbKey.set_data((void *)caseInsensitive.c_str()); dbKey.set_size((caseInsensitive.size() + 1) * sizeof(char)); } else { dbKey.set_data((void *)key.c_str()); dbKey.set_size((key.size() + 1) * sizeof(char)); } Dbc *cursor = NULL; try { m_pimpl->checkTSSInit(); m_pimpl->m_database->cursor(&(**m_pimpl->m_transaction), &cursor, m_pimpl->m_cursorFlags); int ret = cursor->get(&dbKey, &dbData, DB_SET); cursor->close(); if(ret != DB_NOTFOUND) { data = StringPimpl((char *) dbData.get_data()); return true; } else { return false; } } catch (DbException &e) { std::cerr << "Error in getDatabaseRecord transaction: " << e.what() << e.get_errno() << std::endl; if(cursor != NULL) { cursor->close(); } return false; } }
/** * After each AIML file is parsed, this method is called. * * @param fileName The name of the file just parsed. */ void filePostLoad(const StringPimpl &fileName, const StringPimpl &userId, const StringPimpl &botId, const StringPimpl &endUserId) { cout << "[Done loading " << fileName.c_str() << "]" << endl; }
/** * A AIML "That" tag has a non number in its index attribute. * * This method will only be called during loadtime, GraphBuilder::createGraph(). * * @param message The human readable message. */ virtual void thatTagNumericConversionError(const StringPimpl &message, const StringPimpl &userId, const StringPimpl &botId, const StringPimpl &endUserId) { cout << "thatTagNumericConversionError:" << message.c_str() << endl; }
/** * Sends you a message about a XMLParseFatalError. * * Either with AIML files or RebeccaAIML configuration * files. * * @param message The human readable message. */ virtual void XMLParseFatalError(const StringPimpl &message, const StringPimpl &userId, const StringPimpl &botId, const StringPimpl &endUserId) { cout << message.c_str() << endl; }
/** * This is called for each AIML * "Gossip" tag. * * I am just printing out the gossip. * You can do other things like store it * in a file and then reload the file at * startup as a type of persistance. */ void storeGossip(const StringPimpl &gossip, const StringPimpl &userId, const StringPimpl &botId, const StringPimpl &endUserId) { cout << "[Gossip: " << gossip.c_str() << " ]" << endl; }
bool DatabaseManager::recordExists(const StringPimpl &key) { Dbt dbKey, dbData; dbKey.set_data((void *)key.c_str()); dbKey.set_size((key.size() + 1) * sizeof(char)); Dbc *cursor = NULL; try { m_pimpl->checkTSSInit(); m_pimpl->m_database->cursor(&(**m_pimpl->m_transaction), &cursor, m_pimpl->m_cursorFlags); int ret = cursor->get(&dbKey, &dbData, DB_SET); cursor->close(); if(ret != DB_NOTFOUND) { return true; } else { return false; } } catch (DbException &e) { std::cerr << "Error in databse recordExists" << e.what() << e.get_errno() << std::endl; if(cursor != NULL) { cursor->close(); } return false; } }
/** * When the "srai" AIML tag is called, the text * is sent to this method. * * Usually refered to as symbolic reduction, you * can see what text is being re-fed back into the * AIML GraphBuilder::getResponse() by AIML its self. * * @param symbol The text which is being sent back * into GraphBuilder::getResponse(). */ void symbolicReduction(const StringPimpl &symbol, const StringPimpl &userId, const StringPimpl &botId, const StringPimpl &endUserId) { cout << "Symbolic reduction: " << symbol.c_str() << endl; }
void Person::addCharacters(const StringPimpl &characters) throw(InternalProgrammerErrorException &) { LOG_BOT_METHOD("void Person::addCharacters(const StringPimpl &characters)"); logging("<Input> characters:" + String(characters.c_str())); m_pimpl->m_atomic = false; InnerTemplateListImpl::addCharacters(characters); }
void AIML::setAttribute(const StringPimpl &name, const StringPimpl &value) throw(InternalProgrammerErrorException &) { LOG_BOT_METHOD("void AIML::setAttribute(const StringPimpl &name, const StringPimpl &value)"); String nameString(name.c_str()); String valueString(value.c_str()); logging("<Input> name: " + nameString + "value: " + valueString); if(nameString == "version") { ///@todo use something else instead of this or just leave it out. // m_parser.setAIMLVersion(valueString); } else { //Ignore all the rest for right now. I don't care about any other attributes. } }
StringPimpl::StringPimpl(const StringPimpl& stringPimpl) : m_pimpl(0) { try { init(stringPimpl.c_str()); } catch(std::exception &e) { throw ExceptionImpl(e.what()); } }
void DatabaseManager::addRecord(const StringPimpl &key, const StringPimpl &value) { //Set up the key Dbt dbKey; dbKey.set_data((void *)key.c_str()); dbKey.set_size((key.size() + 1) * sizeof(char)); //Set up the data to insert Dbt dbData; dbData.set_data((void *)value.c_str()); dbData.set_size((value.size() + 1) * sizeof(char)); try { m_pimpl->checkTSSInit(); int ret = m_pimpl->m_database->put(&(**m_pimpl->m_transaction), &dbKey, &dbData, 0); } catch (DbException &e) { std::cerr << "Error in addRecord: " << e.what() << e.get_errno() << std::endl; } }
void Condition::setAttribute(const StringPimpl &name, const StringPimpl &value) throw(InternalProgrammerErrorException &) { LOG_BOT_METHOD("void Condition::setAttribute(const StringPimpl &name, const StringPimpl &value)"); String nameString(name.c_str()); String valueString(value.c_str()); if(nameString == "name") { m_pimpl->m_name = true; logging("Setting the m_predicateName to:" + nameString); m_pimpl->m_predicateName = valueString; } else if(nameString == "value") { m_pimpl->m_value = true; logging("Setting the m_aimlPattern to:" + valueString); m_pimpl->m_aimlPattern = valueString; } else { logging("Warning, empty name and/or empty value given or invalid values given"); } }
void AIMLEngine::userInput(const QString &text) { /* * Check the AIML engine is loaded and * that the user actually entered * something */ if((!text.isEmpty()) && m_aiml) { /* * Get the GraphBuilder concrete class that * was created inside of AimlFacade. * DO NOT try to delete GraphBuilder. Let * AimlFacade handle that when it falls out * of scope. */ GraphBuilder &builder = m_aiml->getGraphBuilder(); /* * Emit the internal bot information. Get * the bot response and emit all of that * information to anyone wishing to display * it. */ emit addText(""); emit addText(""); emit addText("Internal information:"); emit addText("====================="); //construct the match line and emit it. QString matchLine = text + " : " + builder.getThat().c_str() + QString(" : ") + builder.getTopic().c_str(); emit addText(matchLine); //Get the bot response StringPimpl response = builder.getResponse(text.toAscii().data()); emit addText("====================="); emit addText(""); //emit the bot response emit addBotText(response.c_str()); } }
bool DatabaseManager::recordRangeExists(const StringPimpl &key) { //Go through the range of the existence keys and //add them to the list Dbc *cursor = NULL; try { Dbt dbKey((void *)key.c_str(), key.size() + 1); Dbt dbData; m_pimpl->checkTSSInit(); m_pimpl->m_database->cursor(&(**m_pimpl->m_transaction), &cursor, m_pimpl->m_cursorFlags); int ret = cursor->get(&dbKey, &dbData, DB_SET_RANGE); while(ret != DB_NOTFOUND) { StringPimpl dataString = StringPimpl((char *) dbData.get_data()); StringPimpl keyString = StringPimpl((char *) dbKey.get_data()); if(!keyString.startsWith(key) || keyString == key) { //We are at the end of the range break; } else { cursor->close(); return true; } } cursor->close(); return false; } catch (DbException &e) { std::cerr << "Error in deleteRecordRange: " << e.what() << e.get_errno() << std::endl; if(cursor != NULL) { cursor->close(); } return false; } }
void TestCasesHandler::TestCaseInput::addCharacters(const StringPimpl &characters) throw(InternalProgrammerErrorException &) { string characterString(characters.c_str()); typedef tokenizer<char_separator<char> > tokenize; typedef tokenizer<char_separator<char> >::const_iterator CI; char_separator<char> sep("\n"); tokenize expectedAnswerTokens(characterString, sep); if(expectedAnswerTokens.begin() != expectedAnswerTokens.end()) { for(CI it = expectedAnswerTokens.begin(); it != expectedAnswerTokens.end(); ++it) { m_characters += " " + trim_copy(*it); } } else { m_characters += trim_copy(characterString); } }
void DatabaseManager::deleteRecordRange(const StringPimpl &key) { Dbc *cursor = NULL; try { Dbt dbKey((void *)key.c_str(), key.size() + 1); Dbt dbData; m_pimpl->checkTSSInit(); m_pimpl->m_database->cursor(&(**m_pimpl->m_transaction), &cursor, m_pimpl->m_cursorFlags); int ret = cursor->get(&dbKey, &dbData, DB_SET_RANGE); while(ret != DB_NOTFOUND) { StringPimpl dataString = StringPimpl((char *) dbData.get_data()); StringPimpl keyString = StringPimpl((char *) dbKey.get_data()); if(!keyString.startsWith(key)) { //We are at the end of the range break; } cursor->del(0); ret = cursor->get(&dbKey, &dbData, DB_NEXT); } cursor->close(); } catch (DbException &e) { std::cerr << "Error in deleteRecordRange: " << e.what() << e.get_errno() << std::endl; if(cursor != NULL) { cursor->close(); } } }
///@todo redo this without annoying tokenizer. Use a for loop void TemplateSideThat::setAttribute(const StringPimpl &name, const StringPimpl &value) throw(InternalProgrammerErrorException &) { if(name == "index" && (!value.empty())) { string valueString(value.c_str()); typedef tokenizer<char_separator<char> > tokenize; typedef tokenizer<char_separator<char> >::const_iterator CI; char_separator<char> sep(","); tokenize pathTokens(valueString, sep); int i = 0; for(CI it = pathTokens.begin(); it != pathTokens.end(); ++it, ++i) { string s; if(i == 0) { try { //This is the first index which is a previous bot response s = *it; trim(s); m_pimpl->m_previousBotResponse = lexical_cast<int>(s); } catch(bad_lexical_cast &) { //User Error, the cast to a numeric value failed string msg("First index string is not a valid number, "); msg += s.c_str(); FrameworkFactory *factory = FrameworkFactory::getInstance(); IdentificationManager *ident = IdentificationManager::getInstance(); GraphBuilderFramework *builder = factory->getGraphBuilderFramework(); builder->getCallBacks().thatTagNumericConversionError(msg.c_str(), ident->getUserId(), ident->getBotId(), ident->getEndUserId()); } } else if(i == 1) { try { //This is the second index which is a sentence s = *it; trim(s); m_pimpl->m_sentence = lexical_cast<int>(s); } catch(bad_lexical_cast &) { string msg("Second index string is not a valid number, "); msg += s.c_str(); FrameworkFactory *factory = FrameworkFactory::getInstance(); IdentificationManager *ident = IdentificationManager::getInstance(); GraphBuilderFramework *builder = factory->getGraphBuilderFramework(); builder->getCallBacks().thatTagNumericConversionError(msg.c_str(), ident->getUserId(), ident->getBotId(), ident->getEndUserId()); //User Error, the cast to a numeric value failed } } else { //User error, the i index is past 2 FrameworkFactory *factory = FrameworkFactory::getInstance(); IdentificationManager *ident = IdentificationManager::getInstance(); GraphBuilderFramework *builder = factory->getGraphBuilderFramework(); builder->getCallBacks().thatTagNumericConversionError("The index is past 2", ident->getUserId(), ident->getBotId(), ident->getEndUserId()); } } } }
/** * Console version to query a AIML set. * * I use the annotated alice data set that's * provided as an example. * * Optionally, you can give this a * "-b baseDirectoryOfRebecca" flag. This * flag tells us where we have RebeccaAIML's * aiml files and conf files stored at. For * example if you have RebeccaAIML stored at * /opt/RebeccAIML you would call this program * as: * * console -b "/opt/RebeccaAIML/". This sample * will then look in /opt/RebeccaAIML/conf for * the configuration files and * /opt/RebeccaAIML/aiml/annotated_alice for * the annotated alice files. * */ int main (int argc, char* args[]) { try { //set our locale to english #ifdef _WIN32 locale::global(locale("ENG")); #endif /* * This is responsible for memory management of * GraphBuilder. */ NetworkAimlFacade aiml(argc, args); /* * Get the GraphBuilder concrete class that * was created inside of AimlFacade. * DO NOT try to delete GraphBuilder. Let * AimlFacade handle that when it falls out * of scope. */ NetworkGraphBuilder &builder = aiml.getNetworkGraphBuilder(); /* * Get the number of AIML categories loaded in total. */ int size = builder.getSize(); //Print out the number of categories loaded. cout << endl << endl; cout << "[Number of categories loaded: " << size << "]" << endl; cout << "[Type /exit to exit]" << endl << endl << endl; /* * Get the botName which should be Rebecca since that is * the name give in the configuration file properties.xml * which we parsed above. */ string botName = builder.getBotPredicate("name").c_str(); /* * Send a initial conversation of "connect" to * annotated alice and get the response. */ StringPimpl response = builder.getResponse("connect"); //Send the initial opening line of the bot cout << botName << " says: " << response.c_str() << endl; /* * The main loop to get the input * from the user until the user types '/exit' */ while(true) { string input; cout << "You say> "; //Get input from the user from the keyboard getline(cin, input); if(input == "/exit") { /* * The user wants to exit so break * out of the while(true) loop */ break; } else //The user gave an input to the bot { /* * Ahhh finally. We give the user input to Rebecca Aiml's loaded * AIML and get the response back. */ StringPimpl response = builder.getResponse(input.c_str()); cout << "=====================" << endl << endl; //Print out what Rebecca says. cout << botName << " says: " << response.c_str() << endl; } } } /* * All the exceptions are grouped here but you * might not want this since it's a bit harder * to determine where they came from. */ catch(NetworkException &e) { cout << "[NetworkException Found Terminating]" << endl; cout << "[" << e.what() << "]" << endl; return 1; } catch(Exception &e) { cout << "[An uknown exception occured, Terminating program]" << endl; cout << "[" << e.what() << "]"; return 1; } //Everything smooth. Exit normally. return 0; }
int main(int argc, char* argv[]) { Arguments arguments(argc, argv); //Initialize Pocketsphinx mic_data_t mic; continuous_init(arguments, mic); //Initialize Voice ISpVoice * pVoice = NULL; if (FAILED(::CoInitialize(NULL))) return FALSE; HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice); if (SUCCEEDED(hr)) std::cout << "Speech Initialized" << std::endl; //Initialize Rebecca AimlFacade aiml; GraphBuilder &builder = aiml.getGraphBuilder(); myCallBacks callback; builder.setCallBacks(&callback); rebecca_init(arguments, builder); //Main code try { /* * Send a initial conversation of "connect" to * annotated alice and get the response. */ StringPimpl response = builder.getResponse("connect"); /* * Get the botName which should be Rebecca since that is * the name give in the configuration file properties.xml * which we parsed above. */ string botName = builder.getBotPredicate("name").c_str(); //Send the initial opening line of the bot cout << botName << " says: " << response.c_str() << endl; hr = pVoice->Speak(s2ws(response.c_str()).c_str(), 0, NULL); pVoice->WaitUntilDone(15000); /* * The main loop to get the input * from the user until the user types '/exit' */ while (true) { //getUtterance(mic); //string input = string(mic.hyp); string input; getline(cin, input); if (input == "/exit" || input == "GOOD NIGHT") { /* * The user wants to exit so break * out of the while(true) loop */ continuous_exit(mic); pVoice->Release(); pVoice = NULL; ::CoUninitialize(); break; } else //The user gave an input to the bot { //Here we get some internal Rebecca information. cout << endl << "Internal information:" << endl << "=====================" << endl << input << " : " << builder.getThat().c_str() << " : " << builder.getTopic().c_str() << endl; /* * Ahhh finally. We give the user input to Rebecca Aiml's loaded * AIML and get the response back. */ StringPimpl response = builder.getResponse(input.c_str()); cout << "=====================" << endl << endl; //Print out what Rebecca says. cout << botName << " says: " << response.c_str() << endl; hr = pVoice->Speak(s2ws(response.c_str()).c_str(), 0, NULL); pVoice->WaitUntilDone(15000); } } } catch (Exception &e) { cout << "[An unknown exception occured, Terminating program]" << endl; cout << "[" << e.what() << "]"; return 1; } //Everything smooth. Exit normally. return 0; }
void PatternSideThat::addCharacters(const StringPimpl &characters) throw(InternalProgrammerErrorException &) { LOG_BOT_METHOD("void That::addCharacters(const StringPimpl &characters)"); logging("<Input> characters:" + String(characters.c_str())); m_pimpl->m_that = characters.c_str(); }
StringPimpl Condition::getString() const throw(InternalProgrammerErrorException &) { LOG_BOT_METHOD("StringPimpl Condition::getString() const"); if(this->isBlockCondition()) { logging("This is a block condition"); if(m_pimpl->m_builder.predicateMatch(m_pimpl->m_predicateName.c_str(), m_pimpl->m_aimlPattern.c_str())) { logging("Matched the aimlpattern to the predicate's pattern"); logging("Returning the string"); return getStringFromSentence(m_pimpl->m_sentence); } else { logging("Did not match the aimlpattern, returning empty string"); return StringPimpl(); } } else { logging("This is either a single or multi-predicate condition"); typedef ListSharedPtrInnerTemplate::const_iterator CI; for(CI it = m_pimpl->m_sentence.begin(); it != m_pimpl->m_sentence.end(); ++it) { if((*it)->instanceOf("Li")) { shared_ptr<Li> li = std::static_pointer_cast<Li>(*it); StringPimpl liPredicateName = li->getPredicateName(); StringPimpl liAimlPattern = li->getAimlPattern(); if(li->isDefaultListItem()) { logging("Encountered default list item. Returning its string"); String s = li->getString().c_str(); trim(s); return s.c_str(); } else if(this->isSinglePredicateCondition()) { logging("This is a single Predicate condition"); if(m_pimpl->m_builder.predicateMatch(m_pimpl->m_predicateName.c_str(), liAimlPattern.c_str())) { String s = (*it)->getString().c_str(); trim(s); return s.c_str(); } } else if(isMutliPredicateCondition()) { logging("This is a multi-predicate condition"); if(m_pimpl->m_builder.predicateMatch(liPredicateName.c_str(), liAimlPattern.c_str())) { String s = (*it)->getString().c_str(); trim(s); return s.c_str(); } } else { logging("Inernal programmer Error, the condition block code is corrupted."); throw InternalProgrammerErrorExceptionImpl("[StringPimpl Condition::getString()] Condition block code is corrupted."); return StringPimpl(); } } else if((*it)->instanceOf("PlainWord")) { //Check for plain word. If it is a plain word skip to the next continue; } else { //Not a plain word, something else. Throw a bad cast. logging("Internal programmer error. Bad cast, was expecting a Li"); throw InternalProgrammerErrorExceptionImpl("[StringPimpl Condition::getString() const]. Bad cast, was expecting a Li"); return StringPimpl(); } } logging("Nothing matched. Returning empty string"); return StringPimpl(); } }
void Condition::addCharacters(const StringPimpl &characters) throw(InternalProgrammerErrorException &) { logging("<Input> characters:" + String(characters.c_str())); add(shared_ptr<PlainWord>(new PlainWord(characters))); }
/** * Console version to query a AIML set. * * I use the annotated alice data set that's * provided as an example. */ int main (int argc, char* args[]) { try { /* * This is responsible for memory management of * GraphBuilder. */ AimlFacade aiml; /* * Get the GraphBuilder concrete class that * was created inside of AimlFacade. * DO NOT try to delete GraphBuilder. Let * AimlFacade handle that when it falls out * of scope. */ GraphBuilder &builder = aiml.getGraphBuilder(); /* * Create an instantiation of our custom * callbacks we created above. */ myCallBacks callback; /* Give the address to Rebecca for usesage. * Rebecca DOES NOT delete it. */ builder.setCallBacks(&callback); // builder.addCustomTagLibrary("customGraphvizTagLayer"); cout << "[Rebecca loading]" << endl; /* * Set the schemas for the AIML XML (AIML.xsd) * and for Rebecca's own configuration files. * The schema's have to be relative to where the files * you are going to parse are going to be at. */ builder.setAIMLSchema("../../resources/schema/AIML.xsd"); builder.setCommonTypesSchema("../resources/schema/common-types.xsd"); builder.setBotConfigurationSchema("../resources/schema/bot-configuration.xsd"); /* * Set that "yes" we do want to do XML validation on * both the AIML XML and Rebecca's own configuration * files. */ builder.setAIMLValidation(); builder.setBotConfigurationValidation(); /* * Parse Rebecca's configuration files to setup * Rebecca's ability to handle input subsitutions, * what a sentence splitter is, and what bot properties * she should have. */ builder.parseSubstitutionFile("../../conf/substitutions.xml"); builder.parseSentenceSplitterFile("../../conf/sentence-splitters.xml"); builder.parsePropertiesFile("../../conf/properties.xml"); /* * Add the entire directory. Every file that has the * extension ".aiml" will be added to the internal queue * for latter processing. */ // builder.addFile("../../aiml/annotated_alice/That.aiml"); builder.addDirectory("../../aiml/test"); // builder.addDirectory("../../aiml/testing"); // builder.addDirectory("../../aiml/basic_aiml"); // builder.addDirectory("../../aiml/aaa"); // builder.addFile("../../resources/testing/AIML.aiml"); //builder.addDirectory("../../aiml/custom_tags"); /* * No other files to add to the internal queue. * So, let's create the AIML graph, the internal * data structures. */ builder.createGraph(); //exit(0); /* * Get the number of AIML categories loaded in total. */ int size = builder.getSize(); //Print out the number of categories loaded. cout << endl << endl; cout << "[Rebecca now fully loaded]" << endl; cout << "[Number of categories loaded: " << size << "]" << endl; cout << "[Type /exit to exit]" << endl << endl << endl; /* * Get the botName which should be Rebecca since that is * the name give in the configuration file properties.xml * which we parsed above. */ string botName = builder.getBotPredicate("name").c_str(); /* * Send a initial conversation of "connect" to * annotated alice and get the response. */ StringPimpl response = builder.getResponse("connect"); //Send the initial opening line of the bot cout << botName << " says: " << response.c_str() << endl; /* * The main loop to get the input * from the user until the user types '/exit' */ while(true) { string input; cout << "You say> "; //Get input from the user from the keyboard getline(cin, input); if(input == "/exit") { /* * The user wants to exit so break * out of the while(true) loop */ break; } else //The user gave an input to the bot { //Here we get some internal Rebecca information. cout << endl << "Internal information:" << endl << "=====================" << endl << input << " : " << builder.getThat().c_str() << " : " << builder.getTopic().c_str() << endl; /* * Ahhh finally. We give the user input to Rebecca Aiml's loaded * AIML and get the response back. */ StringPimpl response = builder.getResponse(input.c_str()); cout << "=====================" << endl << endl; //Print out what Rebecca says. cout << botName << " says: " << response.c_str() << endl; } } } /* * All the exceptions are grouped here but you * might not want this since it's a bit harder * to determine where they came from. */ catch(DirectoryNotFoundException &e) { cout << "[A Directory Was Not Found Terminating]" << endl; cout << "[" << e.what() << "]" << endl; return 1; } catch(FileNotFoundException &e) { cout << "[A File Was Not Found Terminating]" << endl; cout << "[" << e.what() << "]" << endl; return 1; } catch(IllegalArgumentException &e) { cout << "[IllegalArgument Found Terminating]" << endl; cout << "[" << e.what() << "]" << endl; return 1; } catch(InitializationException &e) { cout << "[Initialization Exception Found Terminating]" << endl; cout << "[" << e.what() << "]" << endl; return 1; } catch(XMLErrorException &e) { cout << "[XMLError Exception Found Terminating]" << endl; cout << "[" << e.what() << "]" << endl; return 1; } catch(Exception &e) { cout << "[An uknown exception occured, Terminating program]" << endl; cout << "[" << e.what() << "]"; return 1; } //Everything smooth. Exit normally. return 0; }
void TestCasesHandler::Description::addCharacters(const StringPimpl &characters) throw(InternalProgrammerErrorException &) { string characterString(characters.c_str()); m_characters += trim_copy(characterString); }