Beispiel #1
0
        public override string GetAnswer(WBContext context, LUInfo luInfo)
        {
            string response = DatetimeUtils.GetOutofScopeAnswer();

            string    location = context.Location;
            TimeRange range    = context.timeRange;

            List <string> stations = DatetimeUtils.GetEntity(luInfo, "Station");

            string station = null;

            if (stations != null && stations.Count > 0)
            {
                station = stations[0];
            }

            if (range == null)
            {
                response = client.GetRealTimeAirQuality(location, station);
            }
            else if (!range.IsHourly)
            {
                response = client.GetPredictedSmogDaily(location, range.startDate, range.endDate);
            }
            else
            {
                response = client.GetPredictedSmogHourly(location, range.startDate, range.endDate);
            }

            return(response);
        }
Beispiel #2
0
        public override string GetAnswer(WBContext context, LUInfo luInfo)
        {
            string    location  = context.Location;
            TimeRange timeRange = context.timeRange;

            string response = client.GetSuggestion(location, LifeSuggestionType.CarWashing);

            if (timeRange != null && timeRange.startDate > DateTime.Now)
            {
                response += "\r\n我们仅提供今天的洗车指数\r\n";
            }

            return(response);
        }
Beispiel #3
0
        public override string GetAnswer(WBContext context, LUInfo luInfo)
        {
            string response = DatetimeUtils.GetOutofScopeAnswer();

            string    location = context.Location;
            TimeRange range    = context.timeRange;

            if (range == null)
            {
                response = client.GetRestrictedNumber(location, null, null);
            }
            else
            {
                response = client.GetRestrictedNumber(location, range.startDate, range.endDate);
            }

            return(response);
        }
Beispiel #4
0
        private void initContext(ref WBContext context, LUInfo luinfo, string utterance)
        {
            string intent = luinfo.Intent.intent;

            if ((IsLocationOnly(luinfo, utterance)) ||
                ContainsLocationDateOnly(luinfo, utterance))
            {
                intent = "DefaultIntent";
            }

            string    location = DatetimeUtils.GetLocation(luinfo, true);
            TimeRange range    = DatetimeUtils.GetTimeRange(luinfo);

            context.Intent    = intent;
            context.Location  = location;
            context.timeRange = range;

            context.validTime = DateTime.Now;
        }
Beispiel #5
0
        public WBContext GetContext(string userId)
        {
            // If userId is null, set a uniq id for each uatterance.
            if (string.IsNullOrWhiteSpace(userId))
            {
                userId = DateTime.Now.Ticks.ToString();
            }

            if (contextMap.ContainsKey(userId))
            {
                return(contextMap[userId]);
            }
            else
            {
                WBContext newContext = new WBContext(userId);
                contextMap.Add(userId, newContext);

                return(newContext);
            }
        }
Beispiel #6
0
        public override string GetAnswer(WBContext context, LUInfo luInfo)
        {
            string response = DatetimeUtils.GetOutofScopeAnswer();

            string    location = context.Location;
            TimeRange range    = context.timeRange;

            if (range == null)
            {
                response = client.GetRealTimeWeather(location);
            }
            else if (!range.IsHourly)
            {
                response = client.GetPredictedWeatherDaily(location, range.startDate, range.endDate);
            }
            else
            {
                response = client.GetPredictedWeatherHourly(location, range.startDate, range.endDate);
            }

            return(response + "\r\n");
        }
Beispiel #7
0
        private void updateContext(ref WBContext context, LUInfo luinfo)
        {
            string intent = luinfo.Intent.intent;

            if (!string.IsNullOrWhiteSpace(intent) && ValidIntent.Contains(intent))
            {
                context.Intent = intent;
            }

            string location = DatetimeUtils.GetLocation(luinfo, false);

            if (!string.IsNullOrWhiteSpace(location))
            {
                context.Location = location;
            }

            TimeRange range = DatetimeUtils.GetTimeRange(luinfo);

            if (range != null)
            {
                context.timeRange = range;
            }
        }
Beispiel #8
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);
        }
Beispiel #9
0
 public abstract string GetAnswer(WBContext context, LUInfo luInfo);