当前位置: 首页>>代码示例>>C++>>正文


C++ Match::getPath方法代码示例

本文整理汇总了C++中Match::getPath方法的典型用法代码示例。如果您正苦于以下问题:C++ Match::getPath方法的具体用法?C++ Match::getPath怎么用?C++ Match::getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Match的用法示例。


在下文中一共展示了Match::getPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: match

Match *Kernel::match(const string &context, const string &input, const string &that, const string &topic) {
	Match *m = NULL;
	string path = context + " <pattern> " + input + " <that> " + that + " <topic> " + topic;
	getStream("Match")->Read(string("Input: " + path + "\n").c_str());
	m = match(root, root, CONTEXT, path, "", "");
	if (m != NULL) {
		m->setPath(m->getContextPattern() + " : " + m->getInputPattern() + " : " + m->getThatPattern() + " : " + m->getTopicPattern());
		getStream("Match")->Write(string("Match: " + m->getPath() + "\n").c_str());
	} else {
		getStream("Match")->Write("No match found\n");
	}
	return m;
}
开发者ID:zekoman,项目名称:tibiaauto,代码行数:13,代码来源:Kernel.cpp

示例2: respond

string Kernel::respond(const string &input, const string &id, Responder *r, int, bool srai, const string &prefix) {
	if (!srai) {
		recursionDepth = 0;
		timingResponse = timerMillis();
	}
	//	I want this to be configurable...
	if (++recursionDepth > maxRecursiveDepth) {
		predicates->addHistory("that", id, "");
		cerr << "AIML contains an infinite loop" << endl;
		cerr << "Input involved in loop: " << input << endl;
		return "";
	}
	string currentResponse = "", buffer = "";
	Match *m = NULL;
	if (!srai) {
		predicates->addHistory("input", id, input);
	}
	string sentence, inString = input;
	while (!(sentence = getSentence(inString)).empty()) {
		sentence = trim(sentence);
		string originalInput = sentence;
		if (sentence.length() < 1) {
			continue;
		}
		sentence = prefix + " " + Substituter::substitute(sentence);
		string context = predicates->getValue("context", id);
		context = Substituter::substitute(context);
		string that = predicates->getValue("that", id);
		if (!srai) {
			StringTokenizer stThat(that, ".?!");
			while (stThat.hasMoreTokens()) {
				string t = stThat.nextToken();
				t = trim(t);
				if (!t.empty()) {
					that = t;
					predicates->addHistory("that", id, that);
				}
			}
		}
		that = Substituter::substitute(that);
		string topic = predicates->getValue("topic", id);
		topic = Substituter::substitute(topic);
		if (that.empty()) {
			that = "*";
		}
		if (topic.empty()) {
			topic = "*";
		}
		if (context.empty()) {
			context = "*";
		}
	
		//--	DEBUGGING LINE
		string ktr = sentence + "\n";
		getStream("Kernel")->Read(ktr.c_str());
	
		m = match(context, sentence, that, topic);
		if (m == NULL) {
				cerr << "There is no match for input: " << sentence << endl;
		} else {
			cerr << endl;
			cerr << "INPUT: " << originalInput << endl;
			cerr << "MATCH PATH: " << m->getPath() << endl;
			cerr << "FILENAME: " << m->getNode()->getActualTemplate()->getFilename() << endl;
			
			string tmpl = "<template>" + m->getTemplate() + "</template>";
			strstream ss;
			ss << tmpl << endl;
			
			SaxParser *p = new SaxParser(new Parser());
			p->parse(ss);
			
			currentResponse = Kernel::process(m, ((Parser *)p->getListener())->getRoot(), r, id);
			
			predicates->setValue("beforethat", id, that);
			predicates->setValue("that", id, currentResponse);
			
			delete p;
		}
		if (m != NULL) {
			delete m;
			if (srai) {
				--recursionDepth;
				return currentResponse;
			} else {
				buffer += currentResponse + " ";
			}
		}
	}
	string result = Substituter::substitute(buffer, "output");
	--recursionDepth;
	if (!srai) {
		timingResponse = timerMillis() - timingResponse;
		cerr << "TIME: " << timingResponse << "ms" << endl;
	}
	//--	DEBUGGING LINE
	string ktw = result + "\n";
	getStream("Kernel")->Write(ktw.c_str());
	if (trimming) {
		return trim(result, " \t\r\n");
//.........这里部分代码省略.........
开发者ID:zekoman,项目名称:tibiaauto,代码行数:101,代码来源:Kernel.cpp


注:本文中的Match::getPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。