本文整理汇总了C++中Match::getNode方法的典型用法代码示例。如果您正苦于以下问题:C++ Match::getNode方法的具体用法?C++ Match::getNode怎么用?C++ Match::getNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Match
的用法示例。
在下文中一共展示了Match::getNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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");
//.........这里部分代码省略.........