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);
            }
        }
Esempio n. 2
0
 public static bool IsNullOrEmpty(Object unifiable)
 {
     return(StaticAIMLUtils.IsNullOrEmpty(unifiable));
 }