public MessageForm(string jid, string domain) { InitializeComponent(); CheckForIllegalCrossThreadCalls = false; jidFrom = jid; serverName = domain; this.Text = "Chat with: " + jid; synBot = new SynBot(); botUser = new BotUser(synBot, jid); synBot.Learning += SynBot_Learning; synBot.Memorizing += synBot_Memorizing; synBot.Configuration.StoreVocabulary = true; synBot.Configuration.StoreExamples = true; synBot.Learning += SynBot_Learning; synBot.Memorizing += synBot_Memorizing; synBot.Configuration.StoreVocabulary = true; synBot.Configuration.StoreExamples = true; //Load brain files(siml) here... Program.xclient.SendMessage(jidFrom + "@" + serverName, "Loading Brain please wait..."); var simlPackage = File.ReadAllText("package\\projectamy.simlpk"); synBot.PackageManager.LoadFromString(simlPackage); try { var fileLearn = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "package\\Learned.siml")); synBot.AddSiml(fileLearn); Console.WriteLine("Loaded learning file..."); } catch (Exception ex) { Console.WriteLine("Project Amy has not learned anything new yet..."); } try { //var fileMem = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory() + "\\package", botUser.ID, "Memorized.siml")); //synBot.AddSiml(fileMem); var memPackage = File.ReadAllText("package\\" + jid + "\\memory.simlpk"); synBot.PackageManager.LoadFromString(simlPackage); Console.WriteLine("Loaded personal user Memory file..."); } catch (Exception ex) { Console.WriteLine("No memory file for user " + botUser.ID); } Program.xclient.SendMessage(jidFrom + "@" + serverName, "Loaded! You may now send me messages!"); }
public MainWindow() { InitializeComponent(); Bot = new SynBot(); DatabaseUtility = new DatabaseUtility(); DatabaseUtility.Initialize(); UpdateDataGrid("SELECT * From Employees"); Bot.Sets.Add(new NameSet(DatabaseUtility)); Bot.Sets.Add(new JobSet(DatabaseUtility)); Bot.Sets.Add(new SalarySet(DatabaseUtility)); Bot.Sets.Add(new AgeSet(DatabaseUtility)); Bot.Sets.Add(new IdSet(DatabaseUtility)); Bot.Adapters.Add(new SqlAdapter(this)); var simlFiles = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "SIML"), "*.siml", SearchOption.AllDirectories); foreach (var simlDocument in simlFiles.Select(XDocument.Load)) { Bot.AddSiml(simlDocument); } ExamplesBox.Text = Properties.Resources.Examples; }
static void ConsoleInputThreadProc(object state) { xclient.Message += OnNewMessage; Console.WriteLine("ProjectAmy - Ver. 1.0"); var synBot = new SynBot(); Console.Write("Enter a username: "******"Enter A Password: "******"ProjectAmy - Ver. 1.0"); Console.WriteLine(); Console.WriteLine("Please wait, contacting XMPP Server..."); try { xclient.Connect(); } catch (Exception ex) { Console.WriteLine("Could not connect to server, you can still chat in console though." + Environment.NewLine + ex.ToString()); } if (xclient.Connected == true) { try { xclient.Authenticate(user, pass); } catch (System.Security.Authentication.AuthenticationException ex) { Console.WriteLine("Authentication failure!." + Environment.NewLine + ex.ToString()); } if (xclient.Authenticated == true) { Console.WriteLine("Logged into urgero.net:5222 xmpp protocol."); //No error handlers yet, lets focus on OnNewMessage first... //xclient.Error += OnError; } } Console.WriteLine(); Console.WriteLine("Loading brain files, please wait..."); Console.WriteLine(); Console.WriteLine("-----------------------------------"); synBot.Learning += SynBot_Learning; synBot.Memorizing += synBot_Memorizing; synBot.Configuration.StoreVocabulary = true; synBot.Configuration.StoreExamples = true; //Load brain files(siml) here... var simlPackage = File.ReadAllText("package\\projectamy.simlpk"); synBot.PackageManager.LoadFromString(simlPackage); try { var fileLearn = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "package\\Learned.siml")); synBot.AddSiml(fileLearn); Console.WriteLine("Loaded learning file..."); } catch (Exception ex) { Console.WriteLine("Project Amy has not learned anything new yet..."); } try { //var fileMem = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory() + "\\package", botUser.ID, "Memorized.siml")); //synBot.AddSiml(fileMem); var memPackage = File.ReadAllText("package\\" + user + "\\memory.simlpk"); synBot.PackageManager.LoadFromString(simlPackage); Console.WriteLine("Loaded personal user Memory file..."); } catch (Exception ex) { Console.WriteLine("No memory file for user " + botUser.ID); } bool isChat = true; var interactions = synBot.Stats.Interactions; var idleTime = synBot.Stats.IdleTime; var loadTime = synBot.Stats.LoadTime; var mappingTime = synBot.Stats.MappingTime; var modelCount = synBot.Stats.ModelCount; var vocabCount = synBot.Stats.Vocabulary.Count(); Console.WriteLine("Interactions: " + interactions); Console.WriteLine("LoadTime: " + loadTime); Console.WriteLine("Mapping Time: " + mappingTime); Console.WriteLine("Vocabulary Count: " + vocabCount); Console.WriteLine("Model count: " + modelCount); Console.WriteLine("-----------------------------------"); Console.WriteLine(); Console.WriteLine("Brain Loaded."); //Actual Chatting Session: if (xclient.Connected == false) { while (isChat == true) { Console.Write("Enter Message: "); String message = Console.ReadLine(); if (message == "exit") { if (xclient.Connected == true) { xclient.Dispose(); } //var settings = synBot.Settings.GetDocument(); //settings.Save("package\\BotSettings.siml"); Console.WriteLine("--------------------"); Console.WriteLine("Writing memory to package for later..."); //For some reason the following does not work. try { var elementList = new List <XDocument>(); foreach (var simlFile in Directory.GetFiles(@"package\\" + user, "*.siml")) { var simlElement = XElement.Load(simlFile); elementList.Add(simlElement.Document); } var xdoc = new XDocument(elementList); var packageString = synBot.PackageManager.ConvertToPackage(elementList); File.WriteAllText(@"package\\" + user + "\\memory.simlpk", packageString); } catch (Exception ex) { Console.WriteLine("ERROR: " + ex.ToString()); Console.ReadLine(); } Console.WriteLine("--------------------"); Environment.Exit(0); } var chatReq = new ChatRequest(message, botUser); var chatResult = synBot.Chat(chatReq); if (chatResult.Success) { Console.WriteLine("Amy: " + chatResult.BotMessage); } } } }