public async Task <object> GetIntentStats(string intentId) { var stats = await _luisService.GetIntentStatsAsync(intentId); if (stats != null) { var incorrectly = new List <IncorrectlyResult>(); var unclear = new List <IncorrectlyResult>(); var temp1 = stats.Utterances?.Where(u => u.MisclassifiedIntentPredictions?.Count > 0) .Select(u => new { u.MisclassifiedIntentPredictions, u.AmbiguousIntentPredictions }); if (temp1 != null) { foreach (var item in temp1) { item.MisclassifiedIntentPredictions.ForEach(e => { var existed = incorrectly.FirstOrDefault(i => i.Id == e.Id); if (existed != null) { incorrectly.Remove(existed); existed.Count++; incorrectly.Add(existed); } else { incorrectly.Add(new IncorrectlyResult { Name = item.AmbiguousIntentPredictions.FirstOrDefault(a => a.Id == e.Id)?.Name, Count = 1, Id = e.Id }); } }); } } var temp2 = stats.Utterances?.Where(u => u.MisclassifiedIntentPredictions?.Count <= 0 && u.AmbiguousIntentPredictions?.Count > 0).Select(u => u.AmbiguousIntentPredictions); if (temp2 != null) { foreach (var item in temp2) { item.ForEach(e => { var existed = unclear.FirstOrDefault(i => i.Id == e.Id); if (existed != null) { unclear.Remove(existed); existed.Count++; unclear.Add(existed); } else { unclear.Add(new IncorrectlyResult { Name = e.Name, Count = 1, Id = e.Id }); } }); } } return(new { incorrectly, unclear }); } return(null); }