Esempio n. 1
0
File: Bot.cs Progetto: zsxqblz/BCZM
        public static string go(string QuestionStr)
        {
            if (CourseName.Count == 0)
            {
                InitializeCourseName();
            }
            string   answer = null, VProfile = "-1";
            Question question = null;
            bool     hololens = false;

            if (QuestionStr.Contains("user:"******"";
                    answer = GetAnsFromLUIS(question);
                }
            }
            catch (Exception ex) { answer = "出现错误/r/n" + ex.Message; }

finish:
            insertQuestionLog(QuestionStr, answer);//加入问题信息到数据库记录中

            return(answer);
        }
Esempio n. 2
0
File: Bot.cs Progetto: zsxqblz/BCZM
        public static string GetHololensJson(Question Question)
        {
            Hololens Hololens = new Hololens();

            if (Question.intent == "成绩查询")
            {
                Hololens.type = 1;
                if (ID[0] == null || ID[1] == null)
                {
                    ID = getSQLID("不存在的声纹"); //声纹不存在的
                }
                //string PWRJsonStr = GetPWRJson(); //从服务器get太慢了,下面直接给了用来调试
                string PWRJsonStr = "{\"term\":\"16-17 - VMA\",\"semester\":\"S2\",\"GPA\":\"1\",\"courses\":[{\"name\":\"AP Calculus BC\",\"grade\":\"A+\",\"gradeValue\":1.0,\"value\":-1,\"hours\":5.0},{\"name\":\"AP Chemistry\",\"grade\":\"A+\",\"gradeValue\":1.0,\"value\":-1,\"hours\":5.0},{\"name\":\"AP Computer Science\",\"grade\":\"A+\",\"gradeValue\":1.0,\"value\":-1,\"hours\":5.0},{\"name\":\"AP English\",\"grade\":\"A-\",\"gradeValue\":1.0,\"value\":-1,\"hours\":5.0},{\"name\":\"Basketball 3\",\"grade\":\"B\",\"gradeValue\":1.0,\"value\":-1,\"hours\":1.0},{\"name\":\"Biology 3\",\"grade\":\"A\",\"gradeValue\":1.0,\"value\":-1,\"hours\":1.0},{\"name\":\"Chinese 11\",\"grade\":\"A-\",\"gradeValue\":1.0,\"value\":-1,\"hours\":1.0},{\"name\":\"Civil Science Seminar \",\"grade\":\"A+\",\"gradeValue\":1.0,\"value\":-1,\"hours\":2.0},{\"name\":\"Debate\",\"grade\":\"A\",\"gradeValue\":1.0,\"value\":-1,\"hours\":2.0},{\"name\":\"Earth & Environmental Science\",\"grade\":\"A-\",\"gradeValue\":1.0,\"value\":-1,\"hours\":2.0},{\"name\":\"Han House Time\",\"grade\":\"\",\"gradeValue\":1.0,\"value\":-1,\"hours\":0.0},{\"name\":\"Martial Arts 3\",\"grade\":\"A+\",\"gradeValue\":1.0,\"value\":-1,\"hours\":1.0},{\"name\":\"Painting\",\"grade\":\"A\",\"gradeValue\":1.0,\"value\":-1,\"hours\":1.0},{\"name\":\"Test Prep 3\",\"grade\":\"A\",\"gradeValue\":1.0,\"value\":-1,\"hours\":0.0},{\"name\":\"UCO Course\",\"grade\":\"\",\"gradeValue\":1.0,\"value\":-1,\"hours\":0.0}]}";
                Grades PWRJsonObj = JsonConvert.DeserializeObject <Grades>(PWRJsonStr);
                Hololens.grades = PWRJsonObj;


                List <string> Courses = new List <string>();
                foreach (Entity e in Question.entities)
                {
                    if (e.type == "已知学科")
                    {
                        Courses.Add(e.entity);
                    }
                }
                //查总体成绩
                if (Courses.Count == 0)
                {
                    Hololens.response = "这是你的成绩";
                }
                else
                {
                    foreach (string course in Courses)
                    {
                        Course[] CoursesJsonList = PWRJsonObj.courses;
                        string   CourseEng       = (string)CourseName[course];
                        foreach (Course JT in CoursesJsonList)
                        {
                            if (JT.name == CourseEng)
                            {
                                Hololens.response += "你的" + course + "的成绩是" + JT.grade + "; \n";
                                //Hololens.data += JT.ToString().Replace("\n", "").Replace("  "," ").Replace("{ ", "{") + " "; //这里是截取的
                                break;
                            }
                        }
                    }
                    Hololens.response = Hololens.response.Substring(0, Hololens.response.Count() - 3); //删掉后面多补的
                    Hololens.data     = Hololens.data.Substring(0, Hololens.data.Count() - 1);         //删掉后面多补的
                }
                return(JsonConvert.SerializeObject(Hololens));
            }

            else if (Question.intent == "地点查询")
            {
                string RoomNo = null;
                foreach (Entity e in Question.entities)
                {
                    if (e.type == "门牌号")
                    {
                        RoomNo = e.entity;
                        break;
                    }
                }
                if (RoomNo == null)
                {
                    return(null);
                }
                Hololens.type     = 0;
                Hololens.response = RoomNo + "在这里:";
                Hololens.data     = RoomNo;
                return(JsonConvert.SerializeObject(Hololens));
            }

            else
            {
                string response = "";
                try
                {
                    response = QnA.GetAnsFromQnA(Question.question);
                    if (response != null && response != "")
                    {
                        Hololens.response = response;
                    }
                    else
                    {
                        response          = GetAnsFromLUIS(Question);
                        Hololens.response = response;
                    }
                }
                catch { Hololens.response = response; }
            }
            return(JsonConvert.SerializeObject(Hololens));
        }