Esempio n. 1
0
        private void ProcessTopic(PatternNode target, XmlNode node, string filename)
        {
            string topicName = "*";

            if (node.Attributes.Count == 1 & node.Attributes[0].Name == "name")
            {
                topicName = node.Attributes["name"].Value;
            }
            foreach (XmlNode xmlNode in node.ChildNodes)
            {
                if (xmlNode.Name == "category")
                {
                    this.ProcessCategory(target, xmlNode, topicName, filename);
                }
            }
        }
Esempio n. 2
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;
        }
Esempio n. 3
0
        public Bot(string configDirectory)
        {
            this.Config          = new Config();
            this.ConfigDirectory = configDirectory;
            this.Graphmaster     = new PatternNode(null, StringComparer.CurrentCultureIgnoreCase);
            this.Sets            = new Dictionary <string, Set>(StringComparer.CurrentCultureIgnoreCase);
            this.Maps            = new Dictionary <string, Map>(StringComparer.CurrentCultureIgnoreCase);
            this.Triples         = new TripleCollection();
            //this.CustomTags = new Dictionary<string, TagHandler>(StringComparer.InvariantCultureIgnoreCase);

            // Add predefined sets and maps.
            var inflector = new Inflector(StringComparer.CurrentCultureIgnoreCase);

            this.Sets.Add("number", new Sets.NumberSet());
            this.Maps.Add("successor", new Maps.ArithmeticMap(1));
            this.Maps.Add("predecessor", new Maps.ArithmeticMap(-1));
            this.Maps.Add("singular", new Maps.SingularMap(inflector));
            this.Maps.Add("plural", new Maps.PluralMap(inflector));
        }
Esempio n. 4
0
        public void LoadAIML(PatternNode target, XmlNode doc, string filename)
        {
            var     versionAttribute = doc.Attributes["version"];
            Version version;

            this.ForwardCompatible = (versionAttribute == null || !Version.TryParse(versionAttribute.Value, out version) || version > AimlVersion);

            XmlNodeList childNodes = doc.ChildNodes;

            foreach (XmlNode xmlNode in childNodes)
            {
                if (xmlNode.Name == "topic")
                {
                    this.ProcessTopic(target, xmlNode, filename);
                }
                else if (xmlNode.Name == "category")
                {
                    this.ProcessCategory(target, xmlNode, filename);
                }
            }
            //GC.Collect();
        }
Esempio n. 5
0
 public PatternNode GetOrAddChild(PathToken token)
 {
     if (token.IsSet)
     {
         var child = this.SetChildren.FirstOrDefault(c => c.SetName == token.Text);
         if (child == null)
         {
             var node = new PatternNode(this.children.Comparer);
             this.setChildren.Add(new SetChild(token.Text, node));
             return(node);
         }
         return(child.Node);
     }
     else
     {
         if (this.Children.TryGetValue(token.Text, out var node))
         {
             return(node);
         }
         node = new PatternNode(this.children.Comparer);
         this.children.Add(token.Text, node);
         return(node);
     }
 }
Esempio n. 6
0
 public SetChild(string setName, PatternNode node)
 {
     this.SetName = setName;
     this.Node    = node;
 }
Esempio n. 7
0
 public void ProcessCategory(PatternNode target, XmlNode node, string filename)
 {
     this.ProcessCategory(target, node, "*", filename);
 }