private LabeledUtterance LuisResultToLabeledUtterance(SpeechPredictionResponse speechPredictionResponse) { if (speechPredictionResponse == null) { return(new LabeledUtterance(null, null, null)); } var mappedTypes = this.LuisSettings.PrebuiltEntityTypes .ToDictionary(pair => $"builtin.{pair.Value}", pair => pair.Key); var query = speechPredictionResponse.PredictionResponse.Query; var entities = GetEntities( query, speechPredictionResponse.PredictionResponse.Prediction.Entities, mappedTypes)? .ToList(); var intent = speechPredictionResponse.PredictionResponse.Prediction.TopIntent; var intents = speechPredictionResponse.PredictionResponse.Prediction.Intents?.Select(i => new { Intent = i.Key, i.Value.Score }); var intentData = default(Intent); speechPredictionResponse.PredictionResponse.Prediction.Intents?.TryGetValue(intent, out intentData); return(new LabeledUtterance(query, intent, entities) .WithProperty("intents", intents) .WithScore(intentData?.Score) .WithTextScore(speechPredictionResponse.TextScore) .WithTimestamp(DateTimeOffset.Now)); }
private LabeledUtterance LuisResultToLabeledUtterance(SpeechPredictionResponse speechPredictionResponse) { if (speechPredictionResponse == null) { return(new LabeledUtterance(null, null, null)); } var mappedTypes = this.LuisSettings.PrebuiltEntityTypes .ToDictionary(pair => $"builtin.{pair.Value}", pair => pair.Key); var intent = speechPredictionResponse.PredictionResponse.Prediction.TopIntent; var entities = GetEntities( speechPredictionResponse.PredictionResponse.Query, speechPredictionResponse.PredictionResponse.Prediction.Entities, mappedTypes)? .ToList(); var intentData = default(Intent); speechPredictionResponse.PredictionResponse.Prediction.Intents?.TryGetValue(intent, out intentData); return((intentData != null && intentData.Score.HasValue) || Math.Abs(speechPredictionResponse.TextScore) > Epsilon ? new ScoredLabeledUtterance(speechPredictionResponse.PredictionResponse.Query, intent, intentData?.Score ?? 0, speechPredictionResponse.TextScore, entities) : new LabeledUtterance(speechPredictionResponse.PredictionResponse.Query, intent, entities)); }
private ILabeledUtterance LuisResultToLabeledUtterance(SpeechPredictionResponse speechPredictionResponse) { if (speechPredictionResponse == null) { return(new LabeledUtterance(null, null, null)); } var query = speechPredictionResponse.PredictionResponse.Query; var entities = GetEntities( query, speechPredictionResponse.PredictionResponse.Prediction.Entities)? .ToList(); var intent = speechPredictionResponse.PredictionResponse.Prediction.TopIntent; var intents = speechPredictionResponse.PredictionResponse.Prediction.Intents?.Select(i => new { Intent = i.Key, i.Value.Score }); var intentData = default(Intent); speechPredictionResponse.PredictionResponse.Prediction.Intents?.TryGetValue(intent, out intentData); return(new LabeledUtterance(query, intent, entities) .WithProperty("intents", intents) .WithScore(intentData?.Score) .WithTextScore(speechPredictionResponse.TextScore) .WithTimestamp(DateTimeOffset.Now)); }