consoleaimlhtmlconverter.cpp

来自「AIML的实现」· C++ 代码 · 共 712 行 · 第 1/2 页

CPP
712
字号
					} 					else if(argument == "-botSchema" ||				            argument == "-bs")					{						m_currentArgument = BOT_SCHEMA;						}					else if(argument == "-commonSchema" || 						    argument == "-cs")					{						m_currentArgument = COMMON_SCHEMA;					}					else if(argument == "-configurationDirectory" || 							argument == "-cd")					{						m_currentArgument = CONFIGURATION;					}					else if(argument == "-aimlDirectory" || 						    argument == "-ad")					{						m_currentArgument = AIML;						}					else if(argument == "-help" || 						    argument == "-h" || 							argument == "/?" ||							argument == "--help")					{						/*						 * Display help and exit						 */						printUsage();						exit(0);					}					else					{						cout << 							"[Illegal argument of " +							string(args[i]) +							" found]" 							<< endl;					}				}				else				{					/*					 * We already encountered the switch, 					 * now we just need to set the argument					 */					if(m_currentArgument == AIML)					{						m_aimlDirectory = argument;					}					else if(m_currentArgument == AIML_SCHEMA)					{						m_aimlSchemaPath = argument;					}					else if(m_currentArgument == BOT_SCHEMA)					{						m_botConfigurationSchemaPath = argument;					}					else if(m_currentArgument == COMMON_SCHEMA)					{						m_commonTypesSchemaPath = argument;					}					else if(m_currentArgument == CONFIGURATION)					{						m_configurationDirectory = argument;					}					else					{						cout << "Programmer error "							    "this should not be reached"							 << endl;					}					m_currentArgument = NO_ARG;				}			}		}				/**		 * Returns the configuration		 * directory that has been set.		 *		 * \return The configuration directory		 * where needed configuration files 		 * are stored.		 */		string getConfigurationDirectory() const		{			return m_configurationDirectory;		}				/**		 * Returns the AIML		 * directory that has been set.		 *		 * \return The AIML directory		 * where aiml files are stored.		 */		string getAimlDirectory() const		{			return m_aimlDirectory;		}		/**		 * Returns the AIML schema		 * path that has been set.		 *		 * \return The AIML schema 		 * path that has been set.		 */		string getAimlSchemaPath() const		{			return m_aimlSchemaPath;		}		/**		 * Returns the common types 		 * schema path that has been set.		 *		 * \return The common types 		 * schema path that has been set.		 */		string getCommonTypesSchemaPath() const		{			return m_commonTypesSchemaPath;		}		/**		 * Returns the bot configuration		 * schema path that has been set.		 *		 * \return the bot configuration		 * schema path that has been set.		 */		string getBotConfigurationSchemaPath() const		{			return m_botConfigurationSchemaPath;		}				/** 		 * Enumeration of possible switches you		 * can give rebecca		 */		enum arguments{ NO_ARG, AIML, AIML_SCHEMA, 			            COMMON_SCHEMA, BOT_SCHEMA, 						CONFIGURATION};		/**		 * The current argument state.		 */		arguments m_currentArgument;		/**		 * The location of RebeccaAIML's		 * configuration directory.  		 *		 * If this is not set, it will default 		 * to the current working directory		 * + "../../conf".  This is where		 * needed configuration files are		 * stored.		 */		string m_configurationDirectory;				/**		 * The location of a AIML directory.		 *		 * If this is not set, it will default		 * to the current working directory 		 * + "../../aiml/annotated_alice".		 */		string m_aimlDirectory;				/**		 * The path to the aiml xsd file.		 * 		 * If this is not set, it will default         * to the current working directory + 		 * "../../resources/schema/AIML.xsd"		 */		string m_aimlSchemaPath;		/**		 * The path to the the common types		 * schema file.		 * 		 * If this is not set, it will default         * to the current working directory + 		 * "../resources/schema/common-types.xsd"		 */		string m_commonTypesSchemaPath;				/**		 * The path to the bot configuration		 * schema file.		 * 		 * If this is not set, it will default         * to the current working directory + 		 * "../resources/schema/bot-configuration.xsd"		 */		string m_botConfigurationSchemaPath;};/** * 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	{ 		if(argc < 3)		{   			/*			 * Incorrect number of arguments was given.			 * Print usage and exit the program			 */			printUsage();			exit(1);		}		//else        /*          * We have arugments given, extract them         */        Arguments arguments(argc, args);		/*		 * 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.		 */		consoleAIMLHtmlConverterCallBacks callback;		/* Give the address to Rebecca for usesage.		 * Rebecca DOES NOT delete it.  		 */		builder.setCallBacks(&callback);				/*		 * Add our custom Tag library that overrides all		 * the AIML tags.  This library overrides and changes 		 * the functionality to be the html converter.		 */		builder.addCustomTagLibrary("customHtmlTagLayer");		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(arguments.getAimlSchemaPath().c_str());		builder.setCommonTypesSchema(arguments.getCommonTypesSchemaPath().c_str());		builder.setBotConfigurationSchema(arguments.getBotConfigurationSchemaPath().c_str());		/* 		 * 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.		 */		string substitutions_xml = arguments.getConfigurationDirectory() + "/substitutions.xml";		builder.parseSubstitutionFile(substitutions_xml.c_str());				string sentence_splitters_xml = arguments.getConfigurationDirectory() + "/sentence-splitters.xml";		builder.parseSentenceSplitterFile(sentence_splitters_xml.c_str());				string properties_xml = arguments.getConfigurationDirectory() + "/properties.xml";		builder.parsePropertiesFile(properties_xml.c_str());				/*		 * Add the entire directory.  Every file that has the 		 * extension ".aiml" will be added to the internal queue 		 * for latter processing.		 */		builder.addDirectory(arguments.getAimlDirectory().c_str());		/*		 * No other files to add to the internal queue.  		 * So, let's create the AIML graph, the internal 		 * data structures.		 */		builder.createGraph();	}	/* 	 * 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;}

⌨️ 快捷键说明

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