예제 #1
0
        private RobotBehavior CreateRobotBehavior(LuisResult _luisResult, bool _isAlwaysUseCache)
        {
            var factory = new SynAppsIntentFactory(this.DeviceId);

            return(new RobotBehavior(
                       _luisResult,
                       factory.CreateSynAppsIntentList(_isAlwaysUseCache),
                       PredictionIntentModel.FindAllBySynAppsDeviceIdAndIntentGroupByLuisExampleId(this.DeviceId, _luisResult.TopScoringIntent.Name),
                       PredictionEntityModel.FindAllBySynAppsDeviceIdGroupByEntityName(this.DeviceId)
                       ));
        }
예제 #2
0
        public LuisService(string _deviceId, string _luisAppId, string _luisSubscriptionKey, string _luisProgrammaticAPIKey, string _luisVersionId, string _connectionString)
        {
            this.DeviceId            = _deviceId;
            this.luisAppId           = _luisAppId;
            this.luisSubscriptionKey = _luisSubscriptionKey;
            this.luisVersionId       = _luisVersionId;

            this.httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _luisProgrammaticAPIKey);

            SynAppsIntentModel.Connection(_connectionString);
            ConversationHistoryModel.Connection(_connectionString);
            PredictionIntentModel.Connection(_connectionString);
            PredictionEntityModel.Connection(_connectionString);
            SynAppsSyncStatusModel.Connection(_connectionString);
        }
예제 #3
0
        private static List <PredictionEntityModel> Build(IQueryable <PredictionEntity> records)
        {
            var list = new List <PredictionEntityModel>();

            foreach (var r in records)
            {
                var model = PredictionEntityModel.New();
                model.Id = r.Id;
                model.SynAppsDeviceId = r.SynAppsDeviceId;
                model.LuisExampleId   = r.LuisExampleId;
                model.EntityName      = r.EntityName;
                model.EntityValue     = r.EntityValue;
                model.CreatedAt       = r.CreatedAt;
                model.UpdatedAt       = r.UpdatedAt;

                list.Add(model);
            }

            return(list);
        }
예제 #4
0
        public ApiResult RefreshPredictions()
        {
            var apiResult = new ApiResult {
                StatusCode = StatusCode.Success
            };

            var intentList = new List <PredictionIntentModel>();
            var entityList = new List <PredictionEntityModel>();
            var list       = new List <PreviewLabeledExampleDto>();

            var r = GetPreviewLabeledExamples();

            list.AddRange(r);
            while (r.Count >= 500)
            {
                r = GetPreviewLabeledExamples(list.Count);
                list.AddRange(r);
            }

            foreach (var l in list)
            {
                var intentModel = PredictionIntentModel.New();
                intentModel.SynAppsDeviceId = this.DeviceId;
                intentModel.LuisExampleId   = l.Id;
                intentModel.Intent          = l.IntentLabel;
                intentList.Add(intentModel);

                foreach (var e in l.EntityLabels)
                {
                    var entityModel = PredictionEntityModel.New();
                    entityModel.SynAppsDeviceId = this.DeviceId;
                    entityModel.LuisExampleId   = l.Id;
                    entityModel.EntityName      = e.EntityName;
                    entityModel.EntityValue     = e.EntityValue;
                    entityList.Add(entityModel);
                }
            }

            var intentResult = PredictionIntentModel.Refresh(this.DeviceId, intentList);

            if (intentResult.StatusCode == StatusCode.Success)
            {
                var entityResult = PredictionEntityModel.Refresh(this.DeviceId, entityList);
                if (entityResult.StatusCode == StatusCode.Success)
                {
                    var status = SynAppsSyncStatusModel.FindBySynAppsDeviceId(this.DeviceId);
                    status.LastTrainingDateTime = DateTime.UtcNow;
                    status.Save();
                }
                else
                {
                    apiResult.StatusCode = StatusCode.Error;
                    apiResult.Message    = entityResult.Message;
                }
            }
            else
            {
                apiResult.StatusCode = StatusCode.Error;
                apiResult.Message    = intentResult.Message;
            }

            return(apiResult);
        }