Beispiel #1
0
        public EEContext Understand(string userId, string userInput)
        {
            EEContext context = cStore.GetContext(userId);

            if ((context == null) || (!IsValid(context)))
            {
                log.Info("No valid EEContxt exists. Create new EEContext.");
                LUInfo luinfo = this.Parse(userInput);

                context = CreateContext(userId, luinfo);
                cStore.SetContext(userId, context);
            }
            else
            {
                log.Info("EEContxt exists. \r\n" + JsonConvert.SerializeObject(context));
                MergeContext(userId, userInput, ref context);
                cStore.SetContext(userId, context);
            }

            return(context);
        }
Beispiel #2
0
        public string Answer(string userId, string utterance)
        {
            LUInfo luinfo = this.luController.Understand(utterance);

            WBContext context = contextStore.GetContext(userId);


            if (!context.IsValid())
            {
                initContext(ref context, luinfo, utterance);
            }
            else
            {
                updateContext(ref context, luinfo);
            }

            switch (context.Intent)
            {
            case "DefaultIntent":
                this.srvs.Add(new WeatherSrv());
                this.srvs.Add(new SmogSrv());
                break;

            case "CarWashing":
                this.srvs.Add(new CarWashingSrv());
                break;

            case "Weather":
                this.srvs.Add(new WeatherSrv());
                break;

            case "Smog":
                this.srvs.Add(new SmogSrv());
                break;

            case "RestrictedDriving":
                this.srvs.Add(new RestrictedDrivingSrv());
                break;

            case "Cloth":
                this.srvs.Add(new ClothSrv());
                break;

            default:
                break;
            }

            string answer = "";

            DateTime startTime = DateTime.Now;

            foreach (IntentSrv srv in this.srvs)
            {
                string singleAnswer = srv.GetAnswer(context, luinfo);
                answer += singleAnswer;
            }

            this.srvs.Clear();

            if (string.IsNullOrWhiteSpace(answer))
            {
                answer = DatetimeUtils.GetOutofScopeAnswer();
            }

            DateTime endTime = DateTime.Now;

            LogUtils.Log(startTime, endTime, "[Seniverse Service]");

            return(answer);
        }