public static SraiX FromXml(XmlNode node, AimlLoader loader) { // Search for XML attributes. XmlAttribute attribute; string?serviceName = null; TemplateElementCollection?defaultReply = null; attribute = node.Attributes["service"]; if (attribute != null) { serviceName = attribute.Value; } attribute = node.Attributes["default"]; if (attribute != null) { defaultReply = new TemplateElementCollection(attribute.Value); } // Search for properties in elements. foreach (XmlNode node2 in node.ChildNodes) { if (node2.NodeType == XmlNodeType.Element) { if (node2.Name.Equals("default", StringComparison.InvariantCultureIgnoreCase)) { defaultReply = TemplateElementCollection.FromXml(node2, loader); } } } return(new SraiX(serviceName, node.Attributes, defaultReply, TemplateElementCollection.FromXml(node, loader))); }
public static Random FromXml(XmlNode node, AimlLoader loader) { List <li> items = new List <li>(); // Search for items. foreach (XmlNode node2 in node.ChildNodes) { if (node2.NodeType == XmlNodeType.Element) { if (node2.Name.Equals("li", StringComparison.InvariantCultureIgnoreCase)) { items.Add(li.Parse(node2, loader)); } } } if (items.Count == 0) { return(new Random(items.ToArray())); } foreach (var item in items) { if (!item.Children.Loop) { return(new Random(items.ToArray())); } } throw new AimlException("Infinite loop: every <li> has a loop."); }
public static TemplateNode.Input FromXml(XmlNode node, AimlLoader loader) { // Search for XML attributes. XmlAttribute attribute; TemplateElementCollection index = null; attribute = node.Attributes["index"]; if (attribute != null) { index = new TemplateElementCollection(attribute.Value); } // Search for properties in elements. foreach (XmlNode node2 in node.ChildNodes) { if (node2.NodeType == XmlNodeType.Element) { if (node2.Name.Equals("index", StringComparison.InvariantCultureIgnoreCase)) { index = TemplateElementCollection.FromXml(node2, loader); } } } return(new Input(index)); }
public static TemplateNode.Bot FromXml(XmlNode node, AimlLoader loader) { // Search for XML attributes. XmlAttribute attribute; TemplateElementCollection?key = null; attribute = node.Attributes["name"]; if (attribute != null) { key = new TemplateElementCollection(attribute.Value); } // Search for properties in elements. foreach (XmlNode node2 in node.ChildNodes) { if (node2.NodeType == XmlNodeType.Element) { if (node2.Name.Equals("name", StringComparison.InvariantCultureIgnoreCase)) { key = TemplateElementCollection.FromXml(node2, loader); } } } if (key == null) { throw new AimlException("bot tag is missing a name property."); } return(new Bot(key)); }
/// <summary>Returns a new TagCollection containing all nodes contained in a given XML node.</summary> /// <param name="node">The XML node whose children should be parsed.</param> /// <returns>A new TagCollection containing the results of calling Tag.Parse to construct child nodes from the XML node's children.</returns> public static TemplateElementCollection FromXml(XmlNode node, AimlLoader loader) { var tagList = new List <TemplateNode>(); foreach (XmlNode node2 in node.ChildNodes) { switch (node2.NodeType) { case XmlNodeType.Whitespace: tagList.Add(new TemplateText(" ")); break; case XmlNodeType.Text: tagList.Add(new TemplateText(node2.InnerText)); break; case XmlNodeType.SignificantWhitespace: tagList.Add(new TemplateText(node2.InnerText, false)); break; case XmlNodeType.Element: tagList.Add(loader.ParseElement(node2)); break; } } return(new TemplateElementCollection(tagList.ToArray())); }
public static LearnF FromXml(XmlNode node, AimlLoader loader) { XmlDocument document = new XmlDocument(); document.PreserveWhitespace = true; document.LoadXml(node.OuterXml); return(new LearnF(document.DocumentElement)); }
public static TemplateNode.Get FromXml(XmlNode node, AimlLoader loader) { // Search for XML attributes. XmlAttribute attribute; TemplateElementCollection key = null; bool localVar = false; TemplateElementCollection tupleKey = null; attribute = node.Attributes["name"]; if (attribute != null) { key = new TemplateElementCollection(attribute.Value); } else { attribute = node.Attributes["var"]; if (attribute != null) { key = new TemplateElementCollection(attribute.Value); localVar = true; } } attribute = node.Attributes["tuple"]; if (attribute != null) { tupleKey = new TemplateElementCollection(attribute.Value); } // Search for properties in elements. foreach (XmlNode node2 in node.ChildNodes) { if (node2.NodeType == XmlNodeType.Element) { if (node2.Name.Equals("name", StringComparison.InvariantCultureIgnoreCase)) { key = TemplateElementCollection.FromXml(node2, loader); localVar = false; } else if (node2.Name.Equals("var", StringComparison.InvariantCultureIgnoreCase)) { key = TemplateElementCollection.FromXml(node2, loader); localVar = true; } else if (node2.Name.Equals("tuple", StringComparison.InvariantCultureIgnoreCase)) { tupleKey = TemplateElementCollection.FromXml(node2, loader); } } } if (key == null) { throw new AimlException("get tag is missing a name or var property."); } return(new Get(key, tupleKey, localVar)); }
public static Interval FromXml(XmlNode node, AimlLoader loader) { // Search for XML attributes. XmlAttribute attribute; TemplateElementCollection style = null; TemplateElementCollection jformat = null; TemplateElementCollection start = null; TemplateElementCollection end = null; attribute = node.Attributes["style"]; if (attribute != null) { style = new TemplateElementCollection(attribute.Value); } attribute = node.Attributes["jformat"]; if (attribute != null) { jformat = new TemplateElementCollection(attribute.Value); } attribute = node.Attributes["from"]; if (attribute != null) { start = new TemplateElementCollection(attribute.Value); } attribute = node.Attributes["to"]; if (attribute != null) { end = new TemplateElementCollection(attribute.Value); } // Search for properties in elements. foreach (XmlNode node2 in node.ChildNodes) { if (node2.NodeType == XmlNodeType.Element) { if (node2.Name.Equals("style", StringComparison.InvariantCultureIgnoreCase)) { style = TemplateElementCollection.FromXml(node2, loader); } else if (node2.Name.Equals("jformat", StringComparison.InvariantCultureIgnoreCase)) { jformat = TemplateElementCollection.FromXml(node2, loader); } else if (node2.Name.Equals("from", StringComparison.InvariantCultureIgnoreCase)) { start = TemplateElementCollection.FromXml(node2, loader); } else if (node2.Name.Equals("to", StringComparison.InvariantCultureIgnoreCase)) { end = TemplateElementCollection.FromXml(node2, loader); } } } return(new Interval(jformat, start, end, style)); }
public static TemplateNode.Date FromXml(XmlNode node, AimlLoader loader) { // Search for XML attributes. XmlAttribute attribute; TemplateElementCollection format = null; TemplateElementCollection jformat = null; TemplateElementCollection locale = null; TemplateElementCollection timezone = null; attribute = node.Attributes["format"]; if (attribute != null) { format = new TemplateElementCollection(attribute.Value); } attribute = node.Attributes["jformat"]; if (attribute != null) { jformat = new TemplateElementCollection(attribute.Value); } attribute = node.Attributes["locale"]; if (attribute != null) { locale = new TemplateElementCollection(attribute.Value); } attribute = node.Attributes["timezone"]; if (attribute != null) { timezone = new TemplateElementCollection(attribute.Value); } // Search for properties in elements. foreach (XmlNode node2 in node.ChildNodes) { if (node2.NodeType == XmlNodeType.Element) { if (node2.Name.Equals("format", StringComparison.InvariantCultureIgnoreCase)) { format = TemplateElementCollection.FromXml(node2, loader); } else if (node2.Name.Equals("jformat", StringComparison.InvariantCultureIgnoreCase)) { jformat = TemplateElementCollection.FromXml(node2, loader); } else if (node2.Name.Equals("locale", StringComparison.InvariantCultureIgnoreCase)) { locale = TemplateElementCollection.FromXml(node2, loader); } else if (node2.Name.Equals("timezone", StringComparison.InvariantCultureIgnoreCase)) { timezone = TemplateElementCollection.FromXml(node2, loader); } } } return(new Date(format, jformat, locale, timezone)); }
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()))); }
public override string Evaluate(RequestProcess process) { // Evaluate <eval> tags. XmlNode node = this.Node.Clone(); this.ProcessXml(node, process); // Learn the result. process.Log(LogLevel.Diagnostic, $"In element <learn>: learning new category for {process.User.ID}: {node.OuterXml}"); AimlLoader loader = new AimlLoader(process.Bot); loader.ProcessCategory(process.User.Graphmaster, node, null); return(string.Empty); }
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)); }
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()))); }
public override string Evaluate(RequestProcess process) { // Evaluate <eval> tags. XmlNode node = this.Node.Clone(); this.ProcessXml(node, process); // Learn the result. process.Log(LogLevel.Diagnostic, "In element <learnf>: learning new category: " + node.OuterXml); AimlLoader loader = new AimlLoader(process.Bot); loader.ProcessCategory(process.Bot.Graphmaster, node, null); // Write it to a file. bool newFile = !File.Exists(process.Bot.Config.LearnfFile) || new FileInfo(process.Bot.Config.LearnfFile).Length < 7; StreamWriter writer = new StreamWriter(File.Open("learnf.aiml", FileMode.OpenOrCreate, FileAccess.Write)); if (newFile) { writer.WriteLine("<!-- This file contains AIML categories the bot has learned via <learnf> elements. -->"); writer.WriteLine(); writer.WriteLine("<aiml version=\"2.0\">"); writer.WriteLine(); } else { // Seek to just before the closing </aiml> tag. writer.BaseStream.Seek(-7, SeekOrigin.End); } writer.WriteLine("<!-- Learned from " + process.User.ID + " via category '" + process.Path + "' on " + DateTime.Now + ". -->"); writer.Write(node.InnerXml.Trim('\r', '\n')); writer.WriteLine(); writer.WriteLine(); writer.Write("</aiml>"); writer.Close(); return(string.Empty); }
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())); }
public static Loop FromXml(XmlNode node, AimlLoader loader) { return(new Loop()); }
public static Person2 FromXml(XmlNode node, AimlLoader loader) { return(new Person2(TemplateElementCollection.FromXml(node, loader))); }
public static TemplateNode.Lowercase FromXml(XmlNode node, AimlLoader loader) { return(new Lowercase(TemplateElementCollection.FromXml(node, loader))); }
public static Gossip FromXml(XmlNode node, AimlLoader loader) { return(new Gossip(TemplateElementCollection.FromXml(node, loader))); }
public static SR FromXml(XmlNode node, AimlLoader loader) { return(new SR()); // The sr tag supports no properties. }
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()))); }
public void LoadAIML() { AimlLoader aIMLLoader = new AimlLoader(this); aIMLLoader.LoadAimlFiles(); }
public static Explode FromXml(XmlNode node, AimlLoader loader) { return(new Explode(TemplateElementCollection.FromXml(node, loader))); }
public static TemplateNode.Random.li Parse(XmlNode node, AimlLoader loader) { return(new li(TemplateElementCollection.FromXml(node, loader))); }
public void LoadAIML(XmlDocument newAIML, string filename) { AimlLoader aIMLLoader = new AimlLoader(this); aIMLLoader.LoadAIML(newAIML, filename); }
public static Think FromXml(XmlNode node, AimlLoader loader) { return(new Think(TemplateElementCollection.FromXml(node, loader))); }
public static First FromXml(XmlNode node, AimlLoader loader) { return(new First(TemplateElementCollection.FromXml(node, loader))); }
public static Learn FromXml(XmlNode node, AimlLoader loader) { return(new Learn(node)); }
public static TemplateNode.ID FromXml(XmlNode node, AimlLoader loader) { return(new ID()); // The id tag supports no properties. }
public static TemplateNode.Version FromXml(XmlNode node, AimlLoader loader) { // The version tag supports no properties. return(new Version()); }