Ejemplo n.º 1
0
 /// <summary>
 /// The method that does the actual Processing of the text.
 /// </summary>
 /// <returns>The resulting Processed text</returns>
 protected override Unifiable Format(Unifiable templateNodeInnerText)
 {
     if (CheckNode("person2"))
     {
         if (!IsNullOrEmpty(templateNodeInnerText))
         {
             // non atomic version of the node
             return(ApplySubstitutions.Substitute(substs.Person2Substitutions, templateNodeInnerText));
         }
         else
         {
             writeToLogWarn("SHOULD NEVER GET HERE!");
             // atomic version of the node
             templateNodeInnerText = GetStarContent();
             bool starFailed = IsNull(templateNodeInnerText);
             if (starFailed)
             {
                 QueryHasFailed = true;
                 return(UnifiableEmpty);
             }
             if (!IsNullOrEmpty(templateNodeInnerText))
             {
                 return(((AIMLTagHandler)this).Recurse());
             }
             else
             {
                 return(Unifiable.Empty);
             }
         }
     }
     return(Unifiable.Empty);
 }
Ejemplo n.º 2
0
 protected override string ProcessChange()
 {
     if (this.templateNode.Name.ToLower() == "person")
     {
         if (this.templateNode.InnerText.Length > 0)
         {
             // non atomic version of the node
             return(ApplySubstitutions.Substitute(this.Bot, this.Bot.PersonSubstitutions, this.templateNode.InnerText));
         }
         else
         {
             // atomic version of the node
             XmlNode starNode      = GetNode("<star/>");
             StarTag recursiveStar = new StarTag(this.Bot, this.User, this.Request, this.Result, starNode);
             this.templateNode.InnerText = recursiveStar.Transform();
             if (this.templateNode.InnerText.Length > 0)
             {
                 return(this.ProcessChange());
             }
             else
             {
                 return(string.Empty);
             }
         }
     }
     return(string.Empty);
 }
Ejemplo n.º 3
0
        static public string ToEnglish(string sentenceIn, ISettingsDictionary OutputSubstitutions)
        {
            var writeToLog = (OutputDelegate)null;

            if (sentenceIn == null)
            {
                return(null);
            }
            sentenceIn = sentenceIn.Trim();
            if (sentenceIn == "")
            {
                return("");
            }
            var    sentence      = "";
            string xmlsentenceIn = ToEnglishT(sentenceIn);

            if (xmlsentenceIn == "")
            {
                return("");
            }
            sentence = ApplySubstitutions.Substitute(OutputSubstitutions, xmlsentenceIn);
            if (sentenceIn != sentence)
            {
                if (writeToLog != null)
                {
                    writeToLog("SUBTS: " + sentenceIn + " -> " + sentence);
                }
            }
            sentence = AltBot.CleanupCyc(sentence);
            sentence = ApplySubstitutions.Substitute(OutputSubstitutions, sentence);
            return(sentence.Trim());
        }
Ejemplo n.º 4
0
 protected override Unifiable Format(Unifiable text)
 {
     if (!IsNullOrEmpty(templateNodeInnerText))
     {
         // non atomic version of the node
         return(ApplySubstitutions.Substitute(GetDictionary(), templateNodeInnerText));
     }
     else
     {
         //Need an atomic version
         // atomic version of the node
         XmlNode starNode      = getNode("<star/>");
         star    recursiveStar = new star(Proc, user, query, request, result, starNode);
         templateNode.InnerText = recursiveStar.Transform();
         if (templateNode.InnerText.Length > 0)
         {
             return(ProcessChangeU());
         }
         else
         {
             return(Unifiable.Empty);
         }
     }
     return(Unifiable.Empty);
 }
Ejemplo n.º 5
0
 protected override Unifiable Format(Unifiable unifiable)
 {
     if (templateNode.ParentNode.Name == "srai")
     {
         var vv = ApplySubstitutions.Substitute(substs.Person2Substitutions, unifiable);
         return(vv);
     }
     return(unifiable);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// The subclass only needs to Process the non atomic inner text
 /// </summary>
 /// <param name="text"></param>
 /// <returns></returns>
 protected override Unifiable Format(Unifiable text)
 {
     if (!IsNullOrEmpty(text))
     {
         // non atomic version of the node
         return(ApplySubstitutions.Substitute(GetDictionary(), text));
     }
     return(Unifiable.Empty);
 }
Ejemplo n.º 7
0
        // Token: 0x06000016 RID: 22 RVA: 0x000024C8 File Offset: 0x000014C8
        protected override string ProcessChange()
        {
            if (!(this.templateNode.Name.ToLower() == "person2"))
            {
                return(string.Empty);
            }
            if (this.templateNode.InnerText.Length > 0)
            {
                return(ApplySubstitutions.Substitute(this.bot, this.bot.Person2Substitutions, this.templateNode.InnerText));
            }
            XmlNode node = AIMLTagHandler.getNode("<star/>");
            star    star = new star(this.bot, this.user, this.query, this.request, this.result, node);

            this.templateNode.InnerText = star.Transform();
            if (this.templateNode.InnerText.Length > 0)
            {
                return(this.ProcessChange());
            }
            return(string.Empty);
        }
Ejemplo n.º 8
0
        /// <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));
        }