Exemplo n.º 1
0
            public static Test FromXml(XmlNode node, AimlLoader loader)
            {
                // Search for XML attributes.
                XmlAttribute attribute;

                TemplateElementCollection?expected = null;
                List <TemplateNode>       children = new List <TemplateNode>();

                attribute = node.Attributes["name"];
                if (attribute == null)
                {
                    throw new AimlException("<test> tag must have a 'name' attribute.");
                }
                var name = attribute.Value;

                attribute = node.Attributes["expected"];
                if (attribute != null)
                {
                    expected = new TemplateElementCollection(attribute.Value);
                }

                // Search for properties in elements.
                foreach (XmlNode node2 in node.ChildNodes)
                {
                    if (node2.NodeType == XmlNodeType.Whitespace)
                    {
                        children.Add(new TemplateText(" "));
                    }
                    else if (node2.NodeType == XmlNodeType.Text || node2.NodeType == XmlNodeType.SignificantWhitespace)
                    {
                        children.Add(new TemplateText(node2.InnerText));
                    }
                    else if (node2.NodeType == XmlNodeType.Element)
                    {
                        if (node2.Name.Equals("name", StringComparison.InvariantCultureIgnoreCase))
                        {
                            throw new AimlException("<test> name may not be specified in a subtag.");
                        }
                        else if (node2.Name.Equals("expected", StringComparison.InvariantCultureIgnoreCase))
                        {
                            expected = TemplateElementCollection.FromXml(node2, loader);
                        }
                        else
                        {
                            children.Add(loader.ParseElement(node2));
                        }
                    }
                }

                if (expected == null)
                {
                    throw new AimlException("<test> tag must have an 'expected' property.");
                }

                return(new Test(name, expected, new TemplateElementCollection(children.ToArray())));
            }
Exemplo n.º 2
0
            public static Uniq FromXml(XmlNode node, AimlLoader loader)
            {
                List <Clause> clauses = new List <Clause>();

                // Search for XML attributes.
                XmlAttribute attribute;

                TemplateElementCollection subj = null;
                TemplateElementCollection pred = null;
                TemplateElementCollection obj  = null;

                attribute = node.Attributes["subj"];
                if (attribute != null)
                {
                    subj = new TemplateElementCollection(attribute.Value);
                }
                attribute = node.Attributes["pred"];
                if (attribute != null)
                {
                    pred = new TemplateElementCollection(attribute.Value);
                }
                attribute = node.Attributes["obj"];
                if (attribute != null)
                {
                    obj = new TemplateElementCollection(attribute.Value);
                }

                foreach (XmlNode node2 in node.ChildNodes)
                {
                    if (node2.NodeType == XmlNodeType.Element)
                    {
                        if (node2.Name.Equals("subj", StringComparison.InvariantCultureIgnoreCase))
                        {
                            subj = TemplateElementCollection.FromXml(node2, loader);
                        }
                        else if (node2.Name.Equals("pred", StringComparison.InvariantCultureIgnoreCase))
                        {
                            pred = TemplateElementCollection.FromXml(node2, loader);
                        }
                        else if (node2.Name.Equals("obj", StringComparison.InvariantCultureIgnoreCase))
                        {
                            obj = TemplateElementCollection.FromXml(node2, loader);
                        }
                    }
                }

                return(new Uniq(subj, pred, obj));
            }
Exemplo n.º 3
0
            public static Map FromXml(XmlNode node, AimlLoader loader)
            {
                // Search for XML attributes.
                XmlAttribute attribute;

                TemplateElementCollection name     = null;
                List <TemplateNode>       children = new List <TemplateNode>();

                attribute = node.Attributes["name"];
                if (attribute != null)
                {
                    name = new TemplateElementCollection(attribute.Value);
                }

                // Search for properties in elements.
                foreach (XmlNode node2 in node.ChildNodes)
                {
                    if (node2.NodeType == XmlNodeType.Whitespace)
                    {
                        children.Add(new TemplateText(" "));
                    }
                    else if (node2.NodeType == XmlNodeType.Text || node2.NodeType == XmlNodeType.SignificantWhitespace)
                    {
                        children.Add(new TemplateText(node2.InnerText));
                    }
                    else if (node2.NodeType == XmlNodeType.Element)
                    {
                        if (node2.Name.Equals("name", StringComparison.InvariantCultureIgnoreCase))
                        {
                            name = TemplateElementCollection.FromXml(node2, loader);
                        }
                        else
                        {
                            children.Add(loader.ParseElement(node2));
                        }
                    }
                }

                if (name == null)
                {
                    throw new AimlException("map tag is missing a name property.");
                }

                return(new Map(name, new TemplateElementCollection(children.ToArray())));
            }
Exemplo n.º 4
0
        public void ProcessCategory(PatternNode target, XmlNode node, string topicName, string filename)
        {
            XmlNode?patternNode = null, templateNode = null, thatNode = null, topicNode = null;

            foreach (XmlNode node2 in node.ChildNodes)
            {
                if (node2.Name.Equals("pattern", StringComparison.InvariantCultureIgnoreCase))
                {
                    patternNode = node2;
                }
                else if (node2.Name.Equals("template", StringComparison.InvariantCultureIgnoreCase))
                {
                    templateNode = node2;
                }
                else if (node2.Name.Equals("that", StringComparison.InvariantCultureIgnoreCase))
                {
                    thatNode = node2;
                }
                else if (node2.Name.Equals("topic", StringComparison.InvariantCultureIgnoreCase))
                {
                    topicNode = node2;
                }
            }
            if (patternNode == null)
            {
                throw new AimlException("Missing pattern tag in a node found in " + filename + ".");
            }
            if (templateNode == null)
            {
                throw new AimlException("Node missing a template, with pattern '" + patternNode.InnerXml + "' in file " + filename + ".");
            }
            if (string.IsNullOrWhiteSpace(patternNode.InnerXml))
            {
                this.bot.Log(LogLevel.Warning,
                             "Attempted to load a new category with an empty pattern, with template '" + templateNode.OuterXml + " in file " + filename + "."
                             );
            }

            // Parse the template.
            var templateContent = TemplateElementCollection.FromXml(templateNode, this);

            target.AddChild(this.GeneratePath(patternNode, thatNode, topicNode, topicName, false), new Template(this.bot, templateNode, templateContent, filename));
            ++bot.Size;
        }
Exemplo n.º 5
0
 private void ProcessXml(XmlNode node, RequestProcess process)
 {
     for (int i = 0; i < node.ChildNodes.Count; ++i)
     {
         XmlNode node2 = node.ChildNodes[i];
         if (node2.NodeType == XmlNodeType.Element)
         {
             if (node2.Name.Equals("eval", StringComparison.InvariantCultureIgnoreCase))
             {
                 TemplateElementCollection tags = TemplateElementCollection.FromXml(node2, process.Bot.AimlLoader);
                 node2.ParentNode.ReplaceChild(node.OwnerDocument.CreateTextNode(tags.Evaluate(process)), node2);
             }
             else
             {
                 this.ProcessXml(node2, process);
             }
         }
     }
 }
Exemplo n.º 6
0
            public static Select FromXml(XmlNode node, AimlLoader loader)
            {
                List <Clause> clauses = new List <Clause>();

                // Search for XML attributes.
                XmlAttribute attribute;

                TemplateElementCollection variables = null;

                attribute = node.Attributes["vars"];
                if (attribute != null)
                {
                    variables = new TemplateElementCollection(attribute.Value);
                }

                foreach (XmlNode node2 in node.ChildNodes)
                {
                    if (node2.NodeType == XmlNodeType.Element)
                    {
                        if (node2.Name.Equals("vars", StringComparison.InvariantCultureIgnoreCase))
                        {
                            variables = TemplateElementCollection.FromXml(node2, loader);
                        }
                        else if (node2.Name.Equals("q", StringComparison.InvariantCultureIgnoreCase))
                        {
                            clauses.Add(Clause.FromXml(node2, true, loader));
                        }
                        else if (node2.Name.Equals("notq", StringComparison.InvariantCultureIgnoreCase))
                        {
                            clauses.Add(Clause.FromXml(node2, false, loader));
                        }
                    }
                }

                return(new Select(variables, clauses.ToArray()));
            }
Exemplo n.º 7
0
 public static Gossip FromXml(XmlNode node, AimlLoader loader)
 {
     return(new Gossip(TemplateElementCollection.FromXml(node, loader)));
 }
Exemplo n.º 8
0
 public static Explode FromXml(XmlNode node, AimlLoader loader)
 {
     return(new Explode(TemplateElementCollection.FromXml(node, loader)));
 }
Exemplo n.º 9
0
 public static TemplateNode.Random.li Parse(XmlNode node, AimlLoader loader)
 {
     return(new li(TemplateElementCollection.FromXml(node, loader)));
 }
Exemplo n.º 10
0
 public static Think FromXml(XmlNode node, AimlLoader loader)
 {
     return(new Think(TemplateElementCollection.FromXml(node, loader)));
 }
Exemplo n.º 11
0
 public static Person2 FromXml(XmlNode node, AimlLoader loader)
 {
     return(new Person2(TemplateElementCollection.FromXml(node, loader)));
 }
Exemplo n.º 12
0
 public static Normalize FromXml(XmlNode node, AimlLoader loader)
 {
     return(new Normalize(TemplateElementCollection.FromXml(node, loader)));
 }
Exemplo n.º 13
0
 public static TemplateNode.Formal FromXml(XmlNode node, AimlLoader loader)
 {
     return(new Formal(TemplateElementCollection.FromXml(node, loader)));
 }
Exemplo n.º 14
0
 public static JavaScript FromXml(XmlNode node, AimlLoader loader)
 {
     return(new JavaScript(TemplateElementCollection.FromXml(node, loader)));
 }
Exemplo n.º 15
0
            public static Condition FromXml(XmlNode node, AimlLoader loader)
            {
                // Search for XML attributes.
                XmlAttribute attribute;

                TemplateElementCollection?name  = null;
                TemplateElementCollection?value = null;
                bool localVar = false;
                List <TemplateNode> children = new List <TemplateNode>();
                List <li>           items    = new List <li>();

                attribute = node.Attributes["name"];
                if (attribute != null)
                {
                    name = new TemplateElementCollection(attribute.Value);
                }
                attribute = node.Attributes["var"];
                if (attribute != null)
                {
                    name     = new TemplateElementCollection(attribute.Value);
                    localVar = true;
                }
                attribute = node.Attributes["value"];
                if (attribute != null)
                {
                    value = new TemplateElementCollection(attribute.Value);
                }

                // Search for properties in elements.
                foreach (XmlNode node2 in node.ChildNodes)
                {
                    if (node2.NodeType == XmlNodeType.Whitespace)
                    {
                        children.Add(new TemplateText(" "));
                    }
                    else if (node2.NodeType == XmlNodeType.Text || node2.NodeType == XmlNodeType.SignificantWhitespace)
                    {
                        children.Add(new TemplateText(node2.InnerText));
                    }
                    else if (node2.NodeType == XmlNodeType.Element)
                    {
                        if (node2.Name.Equals("name", StringComparison.InvariantCultureIgnoreCase))
                        {
                            name     = TemplateElementCollection.FromXml(node2, loader);
                            localVar = false;
                        }
                        else if (node2.Name.Equals("var", StringComparison.InvariantCultureIgnoreCase))
                        {
                            name     = TemplateElementCollection.FromXml(node2, loader);
                            localVar = true;
                        }
                        else if (node2.Name.Equals("value", StringComparison.InvariantCultureIgnoreCase))
                        {
                            value = TemplateElementCollection.FromXml(node2, loader);
                        }
                        else if (node2.Name.Equals("li", StringComparison.InvariantCultureIgnoreCase))
                        {
                            items.Add(li.Parse(node2, loader));
                        }
                        else
                        {
                            children.Add(loader.ParseElement(node2));
                        }
                    }
                }

                if (items.Count == 0)
                {
                    if (name == null || value == null)
                    {
                        throw new AimlException("<condition> tag is missing attributes or <li> tags.");
                    }
                    return(new Condition(name, localVar, value, new TemplateElementCollection(children.ToArray())));
                }

                if (items.Any(i => i.Value == null))
                {
                    bool infiniteLoop = true;
                    foreach (var item in items)
                    {
                        if (item.Children == null || !item.Children.Loop)
                        {
                            infiniteLoop = false;
                            break;
                        }
                    }
                    if (infiniteLoop)
                    {
                        throw new AimlException("Infinite loop: every <li> has a loop (and there is a default <li>).");
                    }
                }

                return(new Condition(name, localVar, items.ToArray()));
            }
Exemplo n.º 16
0
 public static TemplateNode.Lowercase FromXml(XmlNode node, AimlLoader loader)
 {
     return(new Lowercase(TemplateElementCollection.FromXml(node, loader)));
 }
Exemplo n.º 17
0
                public static TemplateNode.Condition.li Parse(XmlNode node, AimlLoader loader)
                {
                    // Search for XML attributes.
                    XmlAttribute attribute;

                    TemplateElementCollection name  = null;
                    TemplateElementCollection value = null;
                    bool localVar = false;
                    List <TemplateNode> children = new List <TemplateNode>();

                    attribute = node.Attributes["name"];
                    if (attribute != null)
                    {
                        name = new TemplateElementCollection(attribute.Value);
                    }
                    attribute = node.Attributes["var"];
                    if (attribute != null)
                    {
                        name     = new TemplateElementCollection(attribute.Value);
                        localVar = true;
                    }
                    attribute = node.Attributes["value"];
                    if (attribute != null)
                    {
                        value = new TemplateElementCollection(attribute.Value);
                    }

                    // Search for properties in elements.
                    foreach (XmlNode node2 in node.ChildNodes)
                    {
                        if (node2.NodeType == XmlNodeType.Whitespace)
                        {
                            children.Add(new TemplateText(" "));
                        }
                        else if (node2.NodeType == XmlNodeType.Text || node2.NodeType == XmlNodeType.SignificantWhitespace)
                        {
                            children.Add(new TemplateText(node2.InnerText));
                        }
                        else if (node2.NodeType == XmlNodeType.Element)
                        {
                            if (node2.Name.Equals("name", StringComparison.InvariantCultureIgnoreCase))
                            {
                                name     = TemplateElementCollection.FromXml(node2, loader);
                                localVar = false;
                            }
                            else if (node2.Name.Equals("var", StringComparison.InvariantCultureIgnoreCase))
                            {
                                name     = TemplateElementCollection.FromXml(node2, loader);
                                localVar = true;
                            }
                            else if (node2.Name.Equals("value", StringComparison.InvariantCultureIgnoreCase))
                            {
                                value = TemplateElementCollection.FromXml(node2, loader);
                            }
                            else
                            {
                                children.Add(loader.ParseElement(node2));
                            }
                        }
                    }

                    return(new li(name, localVar, value, new TemplateElementCollection(children.ToArray())));
                }
Exemplo n.º 18
0
 public static First FromXml(XmlNode node, AimlLoader loader)
 {
     return(new First(TemplateElementCollection.FromXml(node, loader)));
 }
Exemplo n.º 19
0
 public static System FromXml(XmlNode node, AimlLoader loader)
 {
     return(new System(TemplateElementCollection.FromXml(node, loader)));
 }