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 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); }