public async Task <ActionResult <IList> > PostSentimentAsync([FromBody] DocsWithTime json) { Docs jsonDoc = JsonSerializer.Deserialize <Docs>(JsonSerializer.Serialize(json)); string result = await TextAnalticsAPI.CallTextAnalyticsAPI(json : jsonDoc, RequestType : "sentiment", azure_key : _configuration["azure_key"]); //string result = await CallTextAnalyticsAPI(jsonDoc); Sentiment sentimentresponse = JsonSerializer.Deserialize <Sentiment>(result); var sentimentscores = sentimentresponse.documents; var originaldocument = json.documents; var query = sentimentscores.Join(originaldocument, s => s.id, o => o.id, (s, o) => new { id = s.id, text = o.text, score = s.score, likeCount = o.likeCount, date = o.publishedAt, dayName = o.publishedAt.DayOfWeek.ToString(), month = o.publishedAt.Month.ToString() }); var DayAggregate = query.GroupBy(d => d.dayName).Select(g => new { Day = g.Key, Scores = g.Select(s => s.score), Avg = (g.Sum(g => g.score) / g.Select(s => s.score).Count()) }).OrderBy(o => o.Day); var MonthAggregate = query.GroupBy(d => d.month).Select(g => new { Month = Int32.Parse(g.Key), Scores = g.Select(s => s.score), Avg = (g.Sum(g => g.score) / g.Select(s => s.score).Count()) }).OrderByDescending(o => o.Month); var LikeAggregate = query.GroupBy(l => l.likeCount).Select(s => new { LikeCount = s.Key, Scores = s.Select(s => s.score) }).OrderBy(o => o.LikeCount);//does this make sense? return(Ok(new { textanalyticsbase = query.ToList(), MonthAggregate = MonthAggregate.ToList(), DayAggregate = DayAggregate.ToList(), LikeAggregate = LikeAggregate.ToList() })); }
public async Task <ActionResult <IList> > PostKeyPhraseAsync([FromBody] DocsWithTime json) { Docs jsonDoc = JsonSerializer.Deserialize <Docs>(JsonSerializer.Serialize(json)); //string result = await CallTextAnalyticsAPI(jsonDoc); string result = await TextAnalticsAPI.CallTextAnalyticsAPI(json : jsonDoc, RequestType : "keyphrases", azure_key : _configuration["azure_key"]); TextAnalytics textanalyticsresponse = JsonSerializer.Deserialize <TextAnalytics>(result); var p = textanalyticsresponse.documents; //.GroupBy(i => i.keyPhrases); var allphrases = p.SelectMany(s => s.keyPhrases).ToList(); var allPhrasesCount = allphrases.GroupBy(x => x) .Where(g => g.Count() > 1) .Select(y => new { word = y.Key, count = y.Count() }) .ToList(); return(allPhrasesCount.ToList()); }
public async Task <ActionResult <IList> > GetEntities([FromBody] DocsWithTime json) { Docs jsonDoc = JsonSerializer.Deserialize <Docs>(JsonSerializer.Serialize(json)); string result = await TextAnalticsAPI.CallTextAnalyticsAPI(json : jsonDoc, RequestType : "entities", azure_key : _configuration["azure_key"]); Entities entityresponse = JsonSerializer.Deserialize <Entities>(result); var entitiesmatches = entityresponse.documents; var originaldocument = json.documents; var query = entitiesmatches.Join(originaldocument, e => e.id, o => o.id, (e, o) => new { id = e.id, text = o.text, likeCount = o.likeCount, date = o.publishedAt, entities = e.entities }); return(Ok(query.ToList())); }