Example #1
0
        public mst_bot_response AskEducationEngine()
        {
            var jsonString = Request.Content.ReadAsStringAsync().Result;

            var botRequest = JsonConvert.DeserializeObject <mst_bot_request>(jsonString);

            dynamic q        = botRequest.data["query"];
            dynamic u        = botRequest.data["userid"];
            string  question = q.text;
            string  userId   = u.text;

            log.Info("userid: " + userId + "; query: " + question);

            ConversationInfo resp = dm.Answer(userId, question);

            oaskills_textanswer answer = new oaskills_textanswer();

            answer.answer = resp.answer;
            //answer.userid = userId;
            //answer.query = question;
            answer.contextinfo = "";

            if (resp.context != null)
            {
                answer.contextinfo = JsonConvert.SerializeObject(resp.context);//resp.context.ToString();
            }

            var map = new mst_map();

            map.Add("answer", answer);
            return(new mst_bot_response()
            {
                result = map
            });
        }
Example #2
0
        /*
         * public static void TestExam()
         * {
         *  string mapFile = "Education.Engine.Res.examoptionmap.json";
         *  string selectionFile = "Education.Engine.Res.examselection.json";
         *  ExamController controller = new ExamController(mapFile, selectionFile);
         *  string userId = "123";
         *
         *  Console.Clear();
         *
         *  DateTime dat = DateTime.Now;
         *
         *  Console.WriteLine("\nToday is {0:d} at {0:T}.", dat);
         *
         *  Console.WriteLine(controller.Start(userId));
         *
         *  string input = Console.ReadLine();
         *  while( input != "quit")
         *  {
         *      if (input.ToLower().StartsWith("dotest"))
         *      {
         *          Console.WriteLine(controller.Start(userId));
         *      }
         *      else
         *      {
         *      string resp = controller.HandleMessage(userId, input);
         *      Console.WriteLine(resp);
         *      }
         *      input = Console.ReadLine();
         *  }
         *
         *  Console.WriteLine("Quit!");
         * }
         *
         * public static void TestIR()
         * {
         *  string mapFile = "Education.Engine.Res.iroptionmap.json";
         *  string selectionFile = "Education.Engine.Res.irselection.json";
         *  IRController controller = new IRController(mapFile, selectionFile);
         *  string userId = "123";
         *
         *  Console.Clear();
         *
         *  DateTime dat = DateTime.Now;
         *
         *  Console.WriteLine("\nToday is {0:d} at {0:T}.", dat);
         *
         *  Console.WriteLine(controller.Start(userId));
         *
         *  string input = Console.ReadLine();
         *  while (input != "quit")
         *  {
         *      if (input.ToLower().StartsWith("dotest"))
         *      {
         *          Console.WriteLine(controller.Start(userId));
         *      }
         *      else
         *      {
         *          string resp = controller.HandleMessage(userId, input);
         *          Console.WriteLine(resp);
         *      }
         *      input = Console.ReadLine();
         *  }
         *
         *  Console.WriteLine("Quit!");
         * }
         */

        public static void TestBot()
        {
            DialogManager dm = new DialogManager("be658451-50ed-4dcc-8787-5c35d4d676e3", "3d4bd4fa6ad349b2ad07b86163d463be");

            Console.Write("[User]: ");
            string input = Console.ReadLine();

            string userId = "123";

            while (input != "quit")
            {
                if (string.IsNullOrWhiteSpace(input))
                {
                    Console.Write("\r\n[User]: ");
                    input = Console.ReadLine();
                }
                else
                {
                    string resp = dm.Answer(userId, input).answer;
                    Console.WriteLine("\r\n[Bot]: " + resp);
                    Console.Write("\r\n[User]: ");
                    input = Console.ReadLine();
                }
            }

            Console.WriteLine("Quit!");
        }