⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcases.h

📁 AIML的实现
💻 H
字号:
#ifndef REBECCA_TESTCASES_H#define REBECCA_TESTCASES_H/* * RebeccaAIML, Artificial Intelligence Markup Language  * C++ api and engine. * * Copyright (C) 2005 Frank Hassanabad * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *///Rebecca includes#include <rebecca/CallBacks.h>#include <rebecca/adt/String.h>#include <rebecca/adt/Map.h>#include <rebecca/AimlFacade.h>//Xerces includes#include <xercesc/parsers/SAXParser.hpp>//Boost includes#include <boost/algorithm/string.hpp>#include <boost/algorithm/string_regex.hpp>//Std includes#include <iostream>namespace rebecca{namespace impl{XERCES_CPP_NAMESPACE_USEusing namespace boost;using namespace std;class TestCases{public:/** * My Custom CallBacks class. *  * This class inherits from Rebecca's  * CallBacks class and implements the  * callbacks for error reporting and  * informational reporting purposes. * * Although, I pain stakenly reimplemnt  * every single method, you don't have to. * Just pick and choose which ones you  * want to implement, and ignore the rest.   * All of the methods of CallBacks has a  * default do nothing implementation. */class myCallBacks : public CallBacks{	public:		/**		 * 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 char * const gossip) 		{ 			cout << "[Gossip: " << gossip << " ]" << endl;		}		/**		 * This is called for each AIML 		 * category that is loaded into 		 * memory.  		 *		 * Loadtime occurs whenver the call 		 * GraphBuilder::createGraph() is made.		 * For every 5000 categories loaded into		 * Rebecca's internal data structure 		 * this prints a output message about it.		 */		void categoryLoaded()		{			static int i = 0;			const int numberOfCategories = 5000;						/*			 * Clever way to say if "i" is a multiple 			 * of 5000 then print out the number of 			 * categories loaded so far.			 */			if(++i % numberOfCategories == 0)			{				cout << "[" << i << " categories loaded]" << endl;			}		}		/**		 * Before each AIML file is parsed this method is called.         *		 * \param fileName The name of the file about to be parsed.		 */		void filePreLoad(const char *const fileName)		{			cout << "[Loading      " << fileName << "]" << endl;		}				/**		 * After each AIML file is parsed, this method is called.         *		 * \param fileName The name of the file just parsed.		 */		void filePostLoad(const char *const fileName)		{			cout << "[Done loading " << fileName << "]" << endl;		}		/**		 * 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 char *const symbol)		{			cout << "Symbolic reduction: " << symbol << endl;		}		/**		 * A infinite symbolic reduction has occured and 		 * has been terminated.		 *		 * This method is called when symbolic reduction ends		 * up in a infinite loop and has been terminated.  This		 * is just to alert you to the fact.		 */		void infiniteSymbolicReduction()		{			cout << "[Infinite Symbolic reduction detected]" << endl;		}				/**		 * Sends you a message about a XMLParseError. 		 *		 * Either with AIML files or RebeccaAIML configuration		 * files.		 *		 * \param message The human readable message.		 */ 		virtual void XMLParseError(const char * const message) 		{ 			cout << message << endl;		} 		/**		 * Sends you a message about a XMLParseWarning. 		 *		 * Either with AIML files or RebeccaAIML configuration		 * files.		 *		 * \param message The human readable message.		 */ 		virtual void XMLParseWarning(const char * const message)		{ 			cout << message << 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 char * const message) 		{ 			cout << message << endl;		} 				/**		 * During runtime, the "thatStar" AIML tag's size is 		 * exceeded.		 *		 * Runtime is during a call to GraphBuilder::getResponse()		 */		virtual void thatStarTagSizeExceeded() 		{ 			cout << "[Warning thatStar Tag Size Exceeded]" << endl;		}				/**		 * During runtime, the "topicStar" AIML tag's size is 		 * exceeded.		 *		 * Runtime is during a call to GraphBuilder::getResponse()		 */		virtual void topicStarTagSizeExceeded() 		{ 			cout << "[Warning topicStar Tag Size Exceeded]" << endl;				}		/**		 * During runtime, the "star" AIML tag's size is 		 * exceeded.		 *		 * Runtime is during a call to GraphBuilder::getResponse()		 */		virtual void starTagSizeExceeded() 		{ 			cout << "[Warning star Tag Size Exceeded]" << endl;		}		/**		 * A AIML "Input" 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 inputTagNumericConversionError(const char * const message) 		{ 			cout << "inputTagNuermicConversionError:" << message << endl;				}		/**		 * During runtime, the "input" AIML tag's size is 		 * exceeded.		 *		 * Runtime is during a call to GraphBuilder::getResponse()		 */		virtual void inputTagSizeExceeded() 		{ 			cout << "[Warning input Tag Size Exceeded]" << endl;		} 		/**		 * A AIML "Star" 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 starTagNumericConversionError(const char * const message) 		{ 			cout << "starTagNuermicConversionError:" << message << endl;						} 		/**		 * During runtime, the "that" AIML tag's size is 		 * exceeded.		 *		 * Runtime is during a call to GraphBuilder::getResponse()		 */		virtual void thatTagSizeExceeded() 		{ 				}		/**		 * 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 char * const message) 		{ 			cout << "thatTagNumericConversionError:" << message << endl;		} 		/**		 * A AIML "TopicStar" 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 topicStarTagNumericConversionError(const char * const message) 		{ 					} 				/**		 * A AIML "thatStar" 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 thatStarTagNumericConversionError(const char * const message) { }};	TestCases(const String &outputFile = "outputOfTestRun.htm");	void setTestSchema(const String &schemaFile);	void setTestValidation(bool trueOrFalse = true);	void addTestFile(const String &testFile);	void addAimlFile(const String &aimlFile);	void addAimlDirectory(const String &aimlDirectory);	void createAimlGraph();	void conductTesting();	virtual ~TestCases();private:      /*	* Create an instantiation of our custom 	* callbacks we created above.	*/	myCallBacks m_callback;	String m_testFile;	String m_testSchema;	bool m_testValidation;	String m_outputFile;	MapStringBool m_filesGraphed;	AimlFacade m_aimlFacade;	GraphBuilder &m_builder;	bool m_aimlFileAdded;	bool m_testFileAdded;	bool m_aimlGraphCreated;	shared_ptr<SAXParser> m_testParser;	shared_ptr<DocumentHandler> m_testDocumentHandler;	shared_ptr<ErrorHandler> m_testErrorHandler;};} //end of impl namespace using rebecca::impl::TestCases;} //end of rebecca namespace#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -