コード例 #1
0
        internal AIMLTagHandler GetTagHandlerU(User user, SubQuery query, Request request, Result result, XmlNode node, bool liText)
        {
            AIMLTagHandler tagHandlerU   = getBespokeTags(user, query, request, result, node);
            string         nodeNameLower = StaticAIMLUtils.ToLower(node.LocalName);
            AltBot         targetBot     = query.TargetBot;

            if (Equals(null, tagHandlerU))
            {
                switch (nodeNameLower)
                {
                case "template":
                case "answer":     //CML
                    tagHandlerU = new template(targetBot, user, query, request, result, node);
                    break;

                case "aiml":
                case "cml":     //CML
                    tagHandlerU = new aiml(targetBot, user, query, request, result, node);
                    break;

                case "aimlexec":
                case "eval":
                    tagHandlerU = new aimlexec(targetBot, user, query, request, result, node);
                    break;

                case "vars":
                case "root":
                case "predicates":     //CML
                    tagHandlerU = new root(targetBot, user, query, request, result, node, (() => query.TargetSettings));
                    break;

                case "properties":
                case "bots":
                    tagHandlerU = new root(targetBot, user, query, request, result, node,
                                           (() => request.TargetBot.GlobalSettings));
                    break;

                case "substitutions":
                    tagHandlerU = new root(targetBot, user, query, request, result, node,
                                           (() => request.TargetBot.InputSubstitutions));
                    break;

                case "topic":
                case "conversation":     //CML
                    tagHandlerU = new topic(targetBot, user, query, request, result, node);
                    break;

                case "category":
                case "conv":     //CML
                    tagHandlerU = new category(targetBot, user, query, request, result, node);
                    break;

                case "and":
                    tagHandlerU = new and(targetBot, user, query, request, result, node);
                    break;

                case "or":
                    tagHandlerU = new or(targetBot, user, query, request, result, node);
                    break;

                case "optional":
                    tagHandlerU = new optional(targetBot, user, query, request, result, node);
                    break;

                case "isa":
                    tagHandlerU = new isa(targetBot, user, query, request, result, node);
                    break;

                case "bot":
                    tagHandlerU = new bot(targetBot, user, query, request, result, node);
                    break;

                case "condition":
                case "options":     //cml
                    tagHandlerU = new condition_aima(targetBot, user, query, request, result, node);
                    break;

                case "li":
                    if (liText)
                    {
                        tagHandlerU = new liif(targetBot, user, query, request, result, node);
                    }
                    break;

                case "if":
                    tagHandlerU = new liif(targetBot, user, query, request, result, node);
                    break;

                case "personf":
                    tagHandlerU = new format(targetBot, user, query, request, result, node,
                                             new Func <string, string>(HttpUtility.UrlEncode),
                                             null);
                    break;

                case "date":
                    tagHandlerU = new date(targetBot, user, query, request, result, node);
                    break;

                case "formal":
                    tagHandlerU = new formal(targetBot, user, query, request, result, node);
                    break;

                case "gender":
                    tagHandlerU = new gender(targetBot, user, query, request, result, node);
                    break;

                case "get":
                    tagHandlerU = new get(targetBot, user, query, request, result, node);
                    break;

                case "gossip":
                    tagHandlerU = new gossip(targetBot, user, query, request, result, node);
                    break;

                case "get_ip":
                case "id":
                    tagHandlerU = new id(targetBot, user, query, request, result, node);
                    break;

                case "inputreq":
                    tagHandlerU = new inputreq(targetBot, user, query, request, result, node);
                    break;

                case "request":
                    tagHandlerU = new input(targetBot, user, query, request, result, node, 1);
                    break;

                case "input":
                    tagHandlerU = new input(targetBot, user, query, request, result, node, 1);
                    break;

                case "justthat":     // <input index="2"/>
                    tagHandlerU = new input(targetBot, user, query, request, result, node, 2);
                    break;

                case "beforethat":     // <input index="3"/>
                    tagHandlerU = new input(targetBot, user, query, request, result, node, 3);
                    break;

#if !(__MonoCS__)
                case "javascript":
                    tagHandlerU = new javascript(targetBot, user, query, request, result, node);
                    break;
#endif
                case "learn":
                case "load":
                case "noload":     // the commented version of <load>
                    tagHandlerU = new learn(targetBot, user, query, request, result, node);
                    break;

                case "lowercase":
                    tagHandlerU = new lowercase(targetBot, user, query, request, result, node);
                    break;

                case "person":
                    tagHandlerU = new substitute(targetBot, user, query, request, result, node);
                    break;

                case "person2":
                    tagHandlerU = new substitute(targetBot, user, query, request, result, node);
                    break;

                case "random":
                    tagHandlerU = new random(targetBot, user, query, request, result, node);
                    break;

                case "sentence":
                    tagHandlerU = new sentence(targetBot, user, query, request, result, node);
                    break;

                case "set":
                    tagHandlerU = new set(targetBot, user, query, request, result, node);
                    break;

                case "size":
                case "getsize":
                    tagHandlerU = new size(targetBot, user, query, request, result, node);
                    break;

                case "sr":
                    tagHandlerU = new sr(targetBot, user, query, request, result, node);
                    break;

                case "srai_odd":
                    tagHandlerU = new srai_odd(targetBot, user, query, request, result, node);
                    break;

                case "star":
                    tagHandlerU = new star(targetBot, user, query, request, result, node);
                    break;

                case "system":
                    tagHandlerU = new system(targetBot, user, query, request, result, node);
                    break;

                case "that":     //default <that index="1,1"/>
                    tagHandlerU = new that(targetBot, user, query, request, result, node, 1);
                    break;

                case "justbeforethat":     //treated as <that index="2,1"/>
                    tagHandlerU = new that(targetBot, user, query, request, result, node, 2);
                    break;

                case "response":     //treated as <that index="1,1"/>
                    tagHandlerU = new that(targetBot, user, query, request, result, node, 2);
                    break;

                case "thatstar":
                    tagHandlerU = new thatstar(targetBot, user, query, request, result, node);
                    break;

                case "think":
                    tagHandlerU = new think(targetBot, user, query, request, result, node);
                    break;

                case "topicstar":
                    tagHandlerU = new topicstar(targetBot, user, query, request, result, node);
                    break;

                case "uppercase":
                    tagHandlerU = new uppercase(targetBot, user, query, request, result, node);
                    break;

                case "version":
                case "getversion":
                    tagHandlerU = new version(targetBot, user, query, request, result, node);
                    break;

                case "cycsystem":
                    tagHandlerU = new cycsystem(targetBot, user, query, request, result, node);
                    break;

                case "cycretract":
                    tagHandlerU = new cycretract(targetBot, user, query, request, result, node);
                    break;

                case "cycassert":
                    tagHandlerU = new cycassert(targetBot, user, query, request, result, node);
                    break;

                case "cycterm":
                    tagHandlerU = new cycterm(targetBot, user, query, request, result, node);
                    break;

                case "cycquery":
                    tagHandlerU = new cycquery(targetBot, user, query, request, result, node);
                    break;

                case "cyccondition":
                    tagHandlerU = new cyccondition(targetBot, user, query, request, result, node);
                    break;

                case "cycphrase":
                    tagHandlerU = new cycphrase(targetBot, user, query, request, result, node);
                    break;

                case "cycparaphrase":
                    tagHandlerU = new cycphrase(targetBot, user, query, request, result, node);
                    break;

                case "guard":
                    tagHandlerU = new guard(targetBot, user, query, request, result, node);
                    break;

                case "guardstar":
                    tagHandlerU = new guardstar(targetBot, user, query, request, result, node);
                    break;

                case "cycrandom":
                    tagHandlerU = new cycrandom(targetBot, user, query, request, result, node);
                    break;

                case "tscore":
                    tagHandlerU = new tscore(targetBot, user, query, request, result, node);
                    break;

                case "space":
                    tagHandlerU = new space(targetBot, user, query, request, result, node);
                    break;

                case "markov":
                    tagHandlerU = new markov(targetBot, user, query, request, result, node);
                    break;

                case "soundcode":
                    tagHandlerU = new soundcode(targetBot, user, query, request, result, node);
                    break;

                // MSM
                case "msm":
                    tagHandlerU = new msm(targetBot, user, query, request, result, node);
                    break;

                case "processmsm":
                    tagHandlerU = new process_msm(targetBot, user, query, request, result, node);
                    break;

                case "setstate":
                    tagHandlerU = new setstate(targetBot, user, query, request, result, node);
                    break;

                case "state":
                    tagHandlerU = new state(targetBot, user, query, request, result, node);
                    break;

                case "transition":
                    tagHandlerU = new transition(targetBot, user, query, request, result, node);
                    break;

                case "setevidence":
                    tagHandlerU = new setevidence(targetBot, user, query, request, result, node);
                    break;

                case "evidenceassoc":
                    tagHandlerU = new evidence_assoc(targetBot, user, query, request, result, node);
                    break;

                case "evidencepattern":
                    tagHandlerU = new evidence_pattern(targetBot, user, query, request, result, node);
                    break;

                case "evidencestate":
                    tagHandlerU = new evidencestate(targetBot, user, query, request, result, node);
                    break;

                case "dependentmachine":
                    tagHandlerU = new dependentmachine(targetBot, user, query, request, result, node);
                    break;

                case "responsetopic":
                    tagHandlerU = new response_topic(targetBot, user, query, request, result, node);
                    break;

                case "push":
                    tagHandlerU = new push(targetBot, user, query, request, result, node);
                    break;

                case "pop":
                    tagHandlerU = new pop(targetBot, user, query, request, result, node);
                    break;

                case "peekstack":
                    tagHandlerU = new peekstack(targetBot, user, query, request, result, node);
                    break;

                case "lex":
                    tagHandlerU = new lex(targetBot, user, query, request, result, node);
                    break;

                case "lexset":
                    tagHandlerU = new lexset(targetBot, user, query, request, result, node);
                    break;

                case "lexis":
                    tagHandlerU = new lexis(targetBot, user, query, request, result, node);
                    break;

                case "dbpush":
                    tagHandlerU = new dbpush(targetBot, user, query, request, result, node);
                    break;

                case "dbquery":
                    tagHandlerU = new dbquery(targetBot, user, query, request, result, node);
                    break;

                case "dbupdate":
                    tagHandlerU = new dbupdate(targetBot, user, query, request, result, node);
                    break;

                case "dbdelete":
                    tagHandlerU = new dbdelete(targetBot, user, query, request, result, node);
                    break;

                case "dbload":
                    tagHandlerU = new dbload(targetBot, user, query, request, result, node);
                    break;


                case "regex":
                    tagHandlerU = new regex(targetBot, user, query, request, result, node);
                    break;

                case "bind":     // <bind>#$isa</bind>
                    tagHandlerU = new bind(targetBot, user, query, request, result, node);
                    break;

                case "#text":
                    if (!liText)
                    {
                        return(null);
                    }
                    return(new verbatum(node.Value, targetBot, user, query, request, result, node));

                case "#comment":
                    return(new verbatum(node.OuterXml, targetBot, user, query, request, result, node));

                case "br":
                    return(new verbatum("\n", targetBot, user, query, request, result, node));

                case "pre":
                    return(new verbatum(StaticXMLUtils.InnerXmlText(node), targetBot, user, query, request, result, node));

                case "p":
                    return(new verbatum("\n\n", targetBot, user, query, request, result, node));

                case "meta":
                    return(new verbatum(node.OuterXml, targetBot, user, query, request, result, node));

                default:
                    break;
                }
            }
            if (tagHandlerU != null)
            {
                return(tagHandlerU);
            }
            if (StaticAIMLUtils.IsHtmlTag(node.Name))
            {
                return(new recursiveVerbatum(node, targetBot, user, query, request, result, node, true));
            }
            if (tagHandlerU == null)
            {
                // "bot", "favorite", "fav"
                foreach (KeyValuePair <string, string> prefix in new[]
                {
                    new KeyValuePair <string, string>("get_", "get"),
                    new KeyValuePair <string, string>("set_", "set"),
                    new KeyValuePair <string, string>("bot_", "bot"),
                    new KeyValuePair <string, string>("favorite_", "bot"),
                    new KeyValuePair <string, string>("favorite", "bot"),
                    new KeyValuePair <string, string>("fav_", "bot"),
                    new KeyValuePair <string, string>("fav", "bot"),

                    new KeyValuePair <string, string>("get", "get"),
                    new KeyValuePair <string, string>("set", "set"),
                    new KeyValuePair <string, string>("bot", "bot"),
                })
                {
                    if (nodeNameLower.StartsWith(prefix.Key) && node.Name.Length > prefix.Key.Length)
                    {
                        string               name    = node.Name.Substring(prefix.Key.Length);
                        XmlNode              pn      = node.ParentNode;
                        LineInfoElementImpl  newnode = StaticXMLUtils.CopyNode(prefix.Value, node, false);
                        XmlAttributeLineInfo atr     = (XmlAttributeLineInfo)newnode.OwnerDocument.CreateAttribute("name");
                        atr.ReadOnly = false;
                        atr.Value    = name;
                        newnode.Attributes.Append(atr);
                        if (node.Name.ToLower() != newnode.Name.ToLower())
                        {
                            writeToLog("AIMLLOADER: converted " + node.OuterXml + " -> " + newnode.OuterXml);
                            return(targetBot.GetTagHandler(newnode, query, request, result, user, liText));
                        }
                        writeToLog("AIMLLOADER: ! convert " + node.OuterXml + " -> " + newnode.OuterXml);
                    }
                }
            }
            if (tagHandlerU != null)
            {
                return(tagHandlerU);
            }
            if (nodeNameLower == "name")
            {
                return(new bot(targetBot, user, query, request, result, node));
            }

            tagHandlerU = new lazyClosure(targetBot, user, query, request, result, node);
            writeToLog("AIMLLOADER:  lazyClosure: " + node.OuterXml);
            return(tagHandlerU);
        }
コード例 #2
0
ファイル: Bot.cs プロジェクト: rickasheye/JosephineSource
        // Token: 0x0600008F RID: 143 RVA: 0x00005AE0 File Offset: 0x00004AE0
        private string processNode(XmlNode node, SubQuery query, Request request, Result result, User user)
        {
            if (request.StartedOn.AddMilliseconds(request.bot.TimeOut) < DateTime.Now)
            {
                request.bot.writeToLog(string.Concat(new string[]
                {
                    "WARNING! Request timeout. User: "******" raw input: \"",
                    request.rawInput,
                    "\" processing template: \"",
                    query.Template,
                    "\""
                }));
                request.hasTimedOut = true;
                return(string.Empty);
            }
            string text = node.Name.ToLower();

            if (text == "template")
            {
                StringBuilder stringBuilder = new StringBuilder();
                if (node.HasChildNodes)
                {
                    foreach (object obj in node.ChildNodes)
                    {
                        XmlNode node2 = (XmlNode)obj;
                        stringBuilder.Append(this.processNode(node2, query, request, result, user));
                    }
                }
                return(stringBuilder.ToString());
            }
            AIMLTagHandler aimltagHandler = null;

            aimltagHandler = this.getBespokeTags(user, query, request, result, node);
            if (object.Equals(null, aimltagHandler))
            {
                string key;
                switch (key = text)
                {
                case "bot":
                    aimltagHandler = new bot(this, user, query, request, result, node);
                    goto IL_53F;

                case "condition":
                    aimltagHandler = new condition(this, user, query, request, result, node);
                    goto IL_53F;

                case "date":
                    aimltagHandler = new date(this, user, query, request, result, node);
                    goto IL_53F;

                case "formal":
                    aimltagHandler = new formal(this, user, query, request, result, node);
                    goto IL_53F;

                case "gender":
                    aimltagHandler = new gender(this, user, query, request, result, node);
                    goto IL_53F;

                case "get":
                    aimltagHandler = new get(this, user, query, request, result, node);
                    goto IL_53F;

                case "gossip":
                    aimltagHandler = new gossip(this, user, query, request, result, node);
                    goto IL_53F;

                case "id":
                    aimltagHandler = new id(this, user, query, request, result, node);
                    goto IL_53F;

                case "input":
                    aimltagHandler = new input(this, user, query, request, result, node);
                    goto IL_53F;

                case "javascript":
                    aimltagHandler = new javascript(this, user, query, request, result, node);
                    goto IL_53F;

                case "learn":
                    aimltagHandler = new learn(this, user, query, request, result, node);
                    goto IL_53F;

                case "lowercase":
                    aimltagHandler = new lowercase(this, user, query, request, result, node);
                    goto IL_53F;

                case "person":
                    aimltagHandler = new person(this, user, query, request, result, node);
                    goto IL_53F;

                case "person2":
                    aimltagHandler = new person2(this, user, query, request, result, node);
                    goto IL_53F;

                case "random":
                    aimltagHandler = new random(this, user, query, request, result, node);
                    goto IL_53F;

                case "sentence":
                    aimltagHandler = new sentence(this, user, query, request, result, node);
                    goto IL_53F;

                case "set":
                    aimltagHandler = new set(this, user, query, request, result, node);
                    goto IL_53F;

                case "size":
                    aimltagHandler = new size(this, user, query, request, result, node);
                    goto IL_53F;

                case "sr":
                    aimltagHandler = new sr(this, user, query, request, result, node);
                    goto IL_53F;

                case "srai":
                    aimltagHandler = new srai(this, user, query, request, result, node);
                    goto IL_53F;

                case "star":
                    aimltagHandler = new star(this, user, query, request, result, node);
                    goto IL_53F;

                case "system":
                    aimltagHandler = new system(this, user, query, request, result, node);
                    goto IL_53F;

                case "that":
                    aimltagHandler = new that(this, user, query, request, result, node);
                    goto IL_53F;

                case "thatstar":
                    aimltagHandler = new thatstar(this, user, query, request, result, node);
                    goto IL_53F;

                case "think":
                    aimltagHandler = new think(this, user, query, request, result, node);
                    goto IL_53F;

                case "topicstar":
                    aimltagHandler = new topicstar(this, user, query, request, result, node);
                    goto IL_53F;

                case "uppercase":
                    aimltagHandler = new uppercase(this, user, query, request, result, node);
                    goto IL_53F;

                case "version":
                    aimltagHandler = new version(this, user, query, request, result, node);
                    goto IL_53F;
                }
                aimltagHandler = null;
            }
IL_53F:
            if (object.Equals(null, aimltagHandler))
            {
                return(node.InnerText);
            }
            if (aimltagHandler.isRecursive)
            {
                if (node.HasChildNodes)
                {
                    foreach (object obj2 in node.ChildNodes)
                    {
                        XmlNode xmlNode = (XmlNode)obj2;
                        if (xmlNode.NodeType != XmlNodeType.Text)
                        {
                            xmlNode.InnerXml = this.processNode(xmlNode, query, request, result, user);
                        }
                    }
                }
                return(aimltagHandler.Transform());
            }
            string  str   = aimltagHandler.Transform();
            XmlNode node3 = AIMLTagHandler.getNode("<node>" + str + "</node>");

            if (node3.HasChildNodes)
            {
                StringBuilder stringBuilder2 = new StringBuilder();
                foreach (object obj3 in node3.ChildNodes)
                {
                    XmlNode node4 = (XmlNode)obj3;
                    stringBuilder2.Append(this.processNode(node4, query, request, result, user));
                }
                return(stringBuilder2.ToString());
            }
            return(node3.InnerXml);
        }