예제 #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);
        }
        private static List <PredictionIntentModel> Build(IQueryable <PredictionIntent> records)
        {
            var list = new List <PredictionIntentModel>();

            foreach (var r in records)
            {
                var model = PredictionIntentModel.New();
                model.Id = r.Id;
                model.SynAppsDeviceId = r.SynAppsDeviceId;
                model.LuisExampleId   = r.LuisExampleId;
                model.Intent          = r.Intent;
                model.CreatedAt       = r.CreatedAt;
                model.UpdatedAt       = r.UpdatedAt;

                list.Add(model);
            }

            return(list);
        }
        public static List <PredictionIntentModel> FindAllBySynAppsDeviceIdAndIntentOrderByLuisExampleId(string _synappsDeviceId, string _intent)
        {
            List <PredictionIntentModel> list = new List <PredictionIntentModel>();

            var dc      = new PredictionExamplesDataContext(SqlConnectionString);
            var records =
                from n in dc.PredictionIntents
                join b in dc.PredictionEntities on n.LuisExampleId equals b.LuisExampleId
                where n.SynAppsDeviceId == _synappsDeviceId
                where n.Intent == _intent
                where b.SynAppsDeviceId == _synappsDeviceId
                orderby n.LuisExampleId
                select new
            {
                Id = n.Id,
                SynAppsDeviceId = n.SynAppsDeviceId,
                LuisExampleId   = n.LuisExampleId,
                Intent          = n.Intent,
                EntityName      = b.EntityName,
                EntityValue     = b.EntityValue,
                CreatedAt       = n.CreatedAt,
                UpdatedAt       = n.UpdatedAt
            };

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

                list.Add(model);
            }

            return(list);
        }
예제 #5
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);
        }