public AIMLTagHandler proccessResponse000(SubQuery query, Request request, Result result, XmlNode sOutput, Unifiable sGuard, out bool createdOutput, out bool templateSucceeded, AIMLTagHandler parentHandlerU, TemplateInfo templateInfo, bool copyChild, bool copyParent) { AltBot Proc = query.TargetBot; //query.LastTagHandler = handler; bool isTraced = request.IsTraced || request.IsTraced || !request.GraphsAcceptingUserInput || (templateInfo != null && templateInfo.IsTraced); //XmlNode guardNode = AIMLTagHandler.getNode(s.Guard.InnerXml); bool usedGuard = sGuard != null && sGuard.PatternNode != null; sOutput = sOutput ?? templateInfo.ClonedOutput; string output = sOutput.OuterXml; XmlNode templateNode = sOutput; bool childOriginal = true; result.Started = true; if (usedGuard) { output = "<template>" + sGuard.PatternNode.OuterXml + " GUARDBOM " + output + "</template>"; templateNode = StaticAIMLUtils.getNodeAndSetSibling(false, output, false, false, sOutput); childOriginal = false; } bool protectChild = copyChild || childOriginal; bool suspendingLimits = request.IsToplevelRequest || request.SuspendSearchLimits; AIMLTagHandler tagHandlerU = GetTagHandler(request.Requester, query, request, result, templateNode, parentHandlerU); string outputSentenceOut = processNode(templateNode, query, request, result, request.Requester, parentHandlerU, protectChild, copyParent, tagHandlerU, suspendingLimits, out templateSucceeded); templateSucceeded = !StaticAIMLUtils.IsFalse(outputSentenceOut); if (outputSentenceOut == null) { if (tagHandlerU == null) { writeToLog("tagHandler = null " + output); } else { bool success = false; if (tagHandlerU.QueryHasSuceeded) { success = true; } if (tagHandlerU.QueryHasFailed) { success = false; } if (success) { writeToLog("Very BaD " + output); } else { } templateSucceeded = false; createdOutput = false; return(tagHandlerU); } } outputSentenceOut = outputSentenceOut ?? ""; string left, outputSentence; if (!StaticAIMLUtils.SplitOff(outputSentenceOut, "GUARDBOM", out left, out outputSentence)) { left = null; outputSentence = outputSentenceOut; } if (sGuard == null || sGuard.PatternNode != null) { string o = Proc.ToEnglish(outputSentence); if (outputSentence.Trim().Length > 0) { templateSucceeded = true; } if (Proc.IsOutputSentence(o, outputSentence)) { if (isTraced) { string aIMLLoaderParentTextAndSourceInfo = ParentTextAndSourceInfo(templateNode); if (aIMLLoaderParentTextAndSourceInfo.Length > 300) { aIMLLoaderParentTextAndSourceInfo = TextFilter.ClipString( aIMLLoaderParentTextAndSourceInfo, 300); } writeToLog("AIMLTRACE '{0}' IsOutputSentence={1}", o, aIMLLoaderParentTextAndSourceInfo); } createdOutput = true; request.AddOutputSentences(templateInfo, o, result, request.TopLevelScore); } else { createdOutput = false; } // @TODO @HACK @BUG isTraced is a HORRID flag here! if (false && !createdOutput && isTraced && request.GraphsAcceptingUserInput) { if (templateInfo != null) { string fromStr = " from " + templateInfo.Graph; if (!StaticAIMLUtils.IsSilentTag(templateNode)) { writeToLog("SILENT '{0}' TEMPLATE={1}", o, ParentTextAndSourceInfo(templateNode) + fromStr); } request.DisableTemplateUntilFinished(templateInfo); } else { writeToLog("UNUSED '{0}' TEMPLATE={1}", o, ParentTextAndSourceInfo(templateNode)); } } return(tagHandlerU); } try { templateSucceeded = !StaticAIMLUtils.IsFalse(left); if (!templateSucceeded) { createdOutput = false; return(tagHandlerU); } string lang = StaticXMLUtils.GetAttribValue(sGuard.PatternNode, "lang", "cycl").ToLower(); try { Unifiable ss = Proc.SystemExecute(left, lang, request); if (StaticAIMLUtils.IsFalse(ss) || StaticAIMLUtils.IsNullOrEmpty(ss)) { if (isTraced) { writeToLog("GUARD FALSE '{0}' TEMPLATE={1}", request, ParentTextAndSourceInfo(templateNode)); } templateSucceeded = false; createdOutput = false; return(tagHandlerU); } else { templateSucceeded = true; } } catch (ChatSignal e) { throw; } catch (Exception e) { Proc.writeToLog(e); templateSucceeded = false; createdOutput = false; return(tagHandlerU); } //part the BOM string o = Proc.ToEnglish(outputSentence); if (Proc.IsOutputSentence(o, outputSentence)) { if (isTraced) { writeToLog(query.Graph + ": GUARD SUCCESS '{0}' TEMPLATE={1}", o, ParentTextAndSourceInfo(templateNode)); } templateSucceeded = true; createdOutput = true; request.AddOutputSentences(templateInfo, o, result, request.TopLevelScore); return(tagHandlerU); } else { writeToLog("GUARD SKIP '{0}' TEMPLATE={1}", outputSentence, ParentTextAndSourceInfo(templateNode)); } templateSucceeded = false; createdOutput = false; return(tagHandlerU); } catch (ChatSignal e) { throw; } catch (Exception ex) { Proc.writeToLog(ex); templateSucceeded = false; createdOutput = false; return(tagHandlerU); } }
/// <summary> /// The method that does the actual Processing of the text. /// </summary> /// <returns>The resulting Processed text</returns> protected override Unifiable ProcessChangeU() { if (templateNode.NodeType == XmlNodeType.Comment) { return(Succeed(templateNode.Value)); } if (templateNode.NodeType == XmlNodeType.Text) { string s = Trim(templateNode.InnerText); if (String.IsNullOrEmpty(s)) { return(Unifiable.Empty); } return(s); } string currentNodeName = templateNode.Name.ToLower(); if (currentNodeName == "substitutions") { var prevDict = request.TargetSettings; // Process each of these child "settings"? nodes try { request.TargetSettings = request.TargetBot.InputSubstitutions; SettingsDictionaryReal.loadSettingNode(request.TargetSettings, templateNode, SettingsPolicy.Default, request); } finally { request.TargetSettings = prevDict; } return(ProcessSucceed()); } if (currentNodeName == "genlmt") { string name = GetAttribValue(templateNode, "name,mt,to,super,into", null); string removeTo = GetAttribValue(templateNode, "remove", null); string from = GetAttribValue(templateNode, "graph,from", null); bool deleteLink = false; if (name == null) { name = Trim(templateNode.InnerText); } if (removeTo != null) { deleteLink = true; name = removeTo; } GraphMaster FROM = request.GetGraph(from); GraphMaster TO = request.GetGraph(name); if (FROM != null && TO != null) { if (deleteLink) { FROM.RemoveGenlMT(TO, writeToLog); } else { FROM.AddGenlMT(TO, writeToLog); } return(Succeed("GENLMT: " + FROM + " => " + name + " => " + TO)); } } if (currentNodeName == "sraigraph") { string name = GetAttribValue(templateNode, "name,mt,to,super,into", null); string from = GetAttribValue(templateNode, "graph,from", null); if (name == null) { name = Trim(templateNode.InnerText); } GraphMaster FROM = request.GetGraph(from); GraphMaster TO = request.GetGraph(name); if (FROM != null && TO != null) { FROM.Srai = name; return(Succeed("SRAI: " + FROM + " => " + name + " => right now " + TO)); } return(Failure("FROM '" + from + "'='" + FROM + "'" + " TO '" + name + "'='" + TO + "'")); } if (currentNodeName == "meta") { return(Succeed("UNUSED: " + templateNode.OuterXml)); } if (currentNodeName == "#comment") { return(Succeed("UNUSED: " + templateNode.OuterXml)); } if (currentNodeName == "item") { SettingsDictionaryReal.loadSettingNode(request.TargetSettings, templateNode, SettingsPolicy.Default, request); return(ProcessSucceed()); } if (currentNodeName == "bot") { SettingsDictionaryReal.loadSettingNode(request.TargetBot.Settings, templateNode, SettingsPolicy.Default, request); return(ProcessSucceed()); } string currentNodeOuterXml = templateNode.OuterXml; if (currentNodeOuterXml.Length > 280) { currentNodeOuterXml = TextFilter.ClipString(currentNodeOuterXml, 280); } writeToLog("ImmediateAiml: " + currentNodeOuterXml); /* * <TestCase name="connect"> * <Input>CONNECT</Input> * <ExpectedAnswer>Connected to test case AIML set.</ExpectedAnswer> * </TestCase> */ if (templateNode.NodeType == XmlNodeType.Comment) { return(ProcessSucceed()); } // pull from late bound sustituion dictionaries var sd = request.GetSubstitutions(currentNodeName, false); if (sd != null) { if (FinalResultValid) { return(FinalResult); } if (!Unifiable.IsIncomplete(FinalResult)) { return(FinalResult); } Func <Unifiable, Unifiable> Format = (v) => ApplySubstitutions.Substitute(sd, templateNodeInnerText); if (base.isRecursive && !ReadOnly) { FinalResult = Format(TransformAtomically(null, true)); return(finalResult.Value); } return(FinalResult = TransformAtomically(Format, false)); } if (AltBot.UnknownTagsAreBotVars) { var dict = Proc.GlobalSettings; if (dict.containsSettingCalled(currentNodeName)) { var v = dict.grabSetting(currentNodeName); if (!Unifiable.IsMissing(v)) { return(v); } } } var vs = Proc.EvalAiml(templateNode, request, request.writeToLog); StringBuilder sb = new StringBuilder(); int writeThrus = 0; int total = 0; OutputDelegate WriteLine = DLRConsole.SystemWriteLine; foreach (var node in vs) { total++; string nodeOuterXml = ToXmlValue(node); WriteLine(nodeOuterXml); string p = GetAttribValue(node, "PASSED", "FALSE"); if (p == "False") { writeThrus++; sb.Append("\n" + nodeOuterXml.Replace("\" ", "\"\n ") + "\n"); } WriteLine(""); } WriteLine(""); WriteLine(""); WriteLine("" + writeThrus); WriteLine(""); string ss = sb.ToString(); WriteLine(ss); WriteLine(""); WriteLine(""); WriteLine(""); return(Succeed("total is " + total)); }