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

📄 graphhandler.cpp

📁 AIML的实现
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * 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 *///Stl includes#include <iostream>using namespace std;//Xerces includes#include <xercesc/parsers/SAXParser.hpp>XERCES_CPP_NAMESPACE_USE;//Rebecca includes#include <rebecca/impl/Exceptions.h>#include <rebecca/impl/GraphBuilderInternal.h>#include <rebecca/impl/GraphHandler.h>#include <rebecca/impl/utils/Transcode.h>#include <rebecca/impl/utils/Logging.h>#include <rebecca/framework/Category.h>#include <rebecca/framework/Topic.h>#include <rebecca/framework/AIML.h>#include <rebecca/framework/Tag.h>#include <rebecca/framework/Pattern.h>#include <rebecca/framework/PatternSideThat.h>#include <rebecca/framework/TemplateSideThat.h>#include <rebecca/framework/Srai.h>#include <rebecca/framework/Star.h>#include <rebecca/framework/Set.h>#include <rebecca/framework/Get.h>#include <rebecca/framework/Think.h>#include <rebecca/framework/PlainWord.h>#include <rebecca/framework/Random.h>#include <rebecca/framework/Li.h>#include <rebecca/framework/Condition.h>#include <rebecca/framework/NonImplemented.h>#include <rebecca/framework/Input.h>#include <rebecca/framework/ThatStar.h>#include <rebecca/framework/TopicStar.h>#include <rebecca/framework/Person.h>#include <rebecca/framework/Person2.h>#include <rebecca/framework/Gender.h>#include <rebecca/framework/Formal.h>#include <rebecca/framework/UpperCase.h>#include <rebecca/framework/LowerCase.h>#include <rebecca/framework/Sentence.h>#include <rebecca/framework/Bot.h>#include <rebecca/framework/Date.h>#include <rebecca/framework/Id.h>#include <rebecca/framework/Size.h>#include <rebecca/framework/Version.h>#include <rebecca/framework/System.h>#include <rebecca/framework/Gossip.h>#include <rebecca/framework/CustomTags.h>#include <rebecca/framework/Learn.h>using namespace rebecca::impl::utils;namespace rebecca{namespace impl{void GraphHandler::endDocument(){	LOG_BOT_METHOD("void GraphHandler::endDocument()");}GraphHandler::GraphHandler(NodeMapper &root, GraphBuilderInternal &builder) 	: m_rootNodeMapper(root),	  m_builder(builder),	  m_size(0){	LOG_BOT_METHOD("GraphHandler::GraphHandler()");/* Commented out.  Not fast enough to justify use		init();*/}shared_ptr<Tag> GraphHandler::createTagClass(const String &className) {		///@todo put this into the adt	map<String, CustomTagWithDelete> &customTags = m_builder.getCustomTagsMapRef();	typedef map<String, CustomTagWithDelete>::iterator I;	for(I it = customTags.begin(); it != customTags.end(); ++it)	{		shared_ptr<Tag> tag = (it->second).m_customTags->createTagClass(className.c_str(), m_builder);		if(tag.get() != 0)		{			return tag;		}	}	if(className == "category") //1	{		m_templateSideThat = false;		++m_size;		m_builder.setSize(m_size);		return shared_ptr<Tag>(new Category(m_builder));	}	else if(className == "pattern") //2	{		return shared_ptr<Tag>(new Pattern);	}	else if(className == "template") //3	{		m_templateSideThat = true;		return shared_ptr<Tag>(new Template);	}	else if(className == "topic") //4	{		return shared_ptr<Tag>(new Topic(m_builder));	}	else if(className == "srai") //5	{		return shared_ptr<Tag>(new Srai(m_builder));	}	else if(className == "that") //6	{		if(m_templateSideThat)		{			return shared_ptr<Tag>(new TemplateSideThat(m_builder));		}		else 		{			return shared_ptr<Tag>(new PatternSideThat(m_builder));		}	}	else if(className == "star") //7	{		return shared_ptr<Tag>(new Star(m_builder));	}	else if(className == "set") //8	{		return shared_ptr<Tag>(new Set(m_builder));	}	else if(className == "get") //9	{		return shared_ptr<Tag>(new Get(m_builder));	}	else if(className == "think") //10	{		return shared_ptr<Tag>(new Think);	}	else if(className == "person") //11	{		return shared_ptr<Tag>(new Person(m_builder));	}	else if(className == "bot") //12	{		return shared_ptr<Tag>(new Bot(m_builder));	}	else if(className == "condition") //13	{		return shared_ptr<Tag>(new Condition(m_builder));	}	else if(className == "li") //14	{		return shared_ptr<Tag>(new Li); 	} 	else if(className == "random") //15	{		return shared_ptr<Tag>(new Random);	}	else if(className == "sr") //16	{		shared_ptr<Tag> nonImplemented(new NonImplemented);		shared_ptr<Tag> srai(new Srai(m_builder));		shared_ptr<Tag> star(new Star(m_builder));		srai->handleInnerTag(star);		nonImplemented->handleInnerTag(srai);		return nonImplemented;	}	else if(className == "input") //17	{		return shared_ptr<Input>(new Input(m_builder));	}	else if(className == "thatstar") //18	{		return shared_ptr<ThatStar>(new ThatStar(m_builder));	}	else if(className == "topicstar") //19	{		return shared_ptr<TopicStar>(new TopicStar(m_builder));	}	else if(className == "person2") //20	{		return shared_ptr<Tag>(new Person2(m_builder));	}	else if(className == "gender") //21	{		return shared_ptr<Tag>(new Gender(m_builder));	}	else if(className == "lowercase") //22	{		return shared_ptr<Tag>(new LowerCase);	}	else if(className == "uppercase") //23	{		return shared_ptr<Tag>(new UpperCase);	}	else if(className == "sentence") //24	{		return shared_ptr<Tag>(new Sentence);	}	else if(className == "formal") //25	{		return shared_ptr<Tag>(new Formal);	}	else if(className == "date") //26	{		return shared_ptr<Tag>(new Date);	}	else if(className == "id") //27	{		return shared_ptr<Tag>(new Id(m_builder));	}	else if(className == "size") //28	{		return shared_ptr<Tag>(new Size(m_builder));	}	else if(className == "version") //29	{		return shared_ptr<Tag>(new Version(m_builder));	}	else if(className == "system") //30	{		return shared_ptr<Tag>(new System);	}	else if(className == "gossip") //31	{		return shared_ptr<Tag>(new Gossip(m_builder));	}	else if(className == "aiml") //32	{		return shared_ptr<Tag>(new AIML(m_builder));	}	else if(className == "learn") //33	{		return shared_ptr<Tag>(new Learn(m_builder));	}	else	{		//This tag is not implemented.  More than likely a		//bogus tag such as HTML:(something).  Just return		//a non implemented tag that just takes the text 		//inbetween and returns it.  This way if you have a 		//tag such as <html:em>some text<html:em>  the 		//unimplemented tag will return "some text"		logging("Unimplemeneted tag found.  Name is:" + className);		return shared_ptr<Tag>(new PlainWord);	}}void GraphHandler::characters(const XMLCh * const chars,                               const unsigned int length){	LOG_BOT_METHOD("void GraphHandler::characters(const XMLCh * const chars,"		                                         "const unsigned int length)");	try	{		Transcode someChars(chars);		m_currentStartElement->addCharacters(someChars.getStringPimpl());	}	catch(nullString &)	{		//Do nothing		logging("caught nullString on someChars.getChar()");	}}void GraphHandler::startElement(const XMLCh* const name, AttributeList& attributes){	LOG_BOT_METHOD("void GraphHandler::startElement(const XMLCh* const name, AttributeList& attributes)");		Transcode attributeName;	Transcode attributeType;	Transcode attributeValue;	Transcode message;		try 	{		message.translate(name);				logging("<" + message.getString() + ">");		const String messageString(message.getChar());		m_currentStartElement = createTagClass(messageString);		m_tagStack.push(m_currentStartElement);	}	catch(nullString &)

⌨️ 快捷键说明

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