static void Main(string[] args) { // verbot variables Verbot5Engine verbot = new Verbot5Engine(); KnowledgeBase kb = new KnowledgeBase(); KnowledgeBaseItem kbi = new KnowledgeBaseItem(); State state = new State(); // build the knowledgebase Rule vRule = new Rule(); vRule.Id = kb.GetNewRuleId(); vRule.AddInput("Hello", ""); vRule.AddInput("Hi", ""); vRule.AddOutput("Hello, World", "", ""); kb.Rules.Add(vRule); string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // save the knowledgebase XMLToolbox xToolbox = new XMLToolbox(typeof(KnowledgeBase)); xToolbox.SaveXML(kb, path + @"\kbi.vkb"); // load the knowledgebase item kbi.Filename = "kbi.vkb"; kbi.Fullpath = path + @"\"; // set the knowledge base for verbot verbot.AddKnowledgeBase(kb, kbi); state.CurrentKBs.Add(path + @"\kbi.vkb"); // get input Console.WriteLine("Please enter your message"); while (true) { string msg = Console.ReadLine(); // process the reply Reply reply = verbot.GetReply(msg, state); if (reply != null) { Console.WriteLine(reply.AgentText); } else { Console.WriteLine("No reply found."); } } }
// Use this for initialization void Start() { // build the knowledgebase Rule vRule = new Rule(); vRule.Id = kb.GetNewRuleId(); vRule.AddInput("Hello", ""); vRule.AddInput("Hi", ""); vRule.AddOutput("Hello, World", "", ""); kb.Rules.Add(vRule); //Path to save the file string fileNameVKB = "kbi.vkb"; string sPath = System.IO.Path.Combine(Application.streamingAssetsPath, "Verbots"); string fullPath = System.IO.Path.Combine(sPath, fileNameVKB); try { // save the knowledgebase XMLToolbox xToolbox = new XMLToolbox(typeof(KnowledgeBase)); xToolbox.SaveXML(kb, fullPath); Debug.Log(string.Format("{0} file saved in: {1}", fileNameVKB, fullPath)); } catch (Exception e) { Debug.LogWarning(e.ToString()); } // load the knowledgebase item kbi.Filename = fileNameVKB; kbi.Fullpath = sPath + @"\"; // set the knowledge base for verbot verbot.AddKnowledgeBase(kb, kbi); state.CurrentKBs.Add(fullPath); //Console: bot Response Debug.Log("Verbot initialized"); string userInput = "Hello"; Debug.Log(string.Format("User: {0}", userInput)); Debug.Log(string.Format("Bot: {0}", getReply(userInput))); }
/// <summary> /// Load the Verbot knowledge base *.VKB /// </summary> /// <param name="paths">StreamingAssets/.../...</param> public void LoadKnowledgeBase(string [] paths) { // Clears the values of the variables. this.state.CurrentKBs.Clear(); // Get all paths in the array. foreach (string path in paths) { if (FileExist(path) == true) { //Load a knowledge base. kb = verbot.LoadKnowledgeBase(path); //Load the knowledgebase item. kbi.Filename = Path.GetFileName(path); kbi.Fullpath = Path.GetDirectoryName(path) + @"\"; //Set the knowledge base for verbot. verbot.AddKnowledgeBase(kb, kbi); this.state.CurrentKBs.Add(path); } } }