static async Task <bool> GetGroupTopics(byte[] data, YammerGroup group) { group.Topics = new List <Topic>(); HttpClient cli = new HttpClient(); cli.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", TextAnalyticsKey); var response = await cli.PostAsync( "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/Topics/?minDocumentsPerWord=5", new ByteArrayContent(data)); var OperationLocation = response.Headers.GetValues("Operation-Location").First(); while (true)//should implement timeout { JObject documents = JObject.Parse(await GetTopicResult(cli, OperationLocation)); string status = documents["status"].ToString().ToLowerInvariant(); if (status == "succeeded") { JArray topics = JArray.Parse( documents["operationProcessingResult"]["topics"].ToString()); foreach (var topic in topics) { group.Topics.Add(new Topic { Label = topic["keyPhrase"].ToString(), Score = Convert.ToDouble(topic["score"]) }); } return(true); } else if (status == "failed") { return(false); } else { Thread.Sleep(60000); } } }
static async void MainAsync(string[] args) { YammerGroup group = new YammerGroup(); //retrieving the conversations of a given group List <YammerMessage> messages = GetYammerMessages(YammerGroupId); //preparing dataset for APIs byte[] data = GetAPIData(messages); //performing the keyPhrase analysis against the Yammer messages await KeyPhraseOrSentiment(data, messages); //performing the sentiment analysis against the Yammer messages await KeyPhraseOrSentiment(data, messages, true); group.Messages = messages; //retrieving the images of that group List <YammerImageFile> files = await GetImageFiles(YammerGroupId); await DonwloadAndAnalyzeYammerFile(files); group.Files = files; Console.WriteLine("---------------TOPIC DETECTION-----------------"); if (await GetGroupTopics(data, group)) { var MostDiscussedTopics = group.Topics.OrderByDescending(t => t.Score).Take(5); foreach (var MostDiscussedTopic in MostDiscussedTopics) { Console.WriteLine("{0} {1}", MostDiscussedTopic.Score, MostDiscussedTopic.Label); } } else { Console.WriteLine("Toppic Detection failed"); } Console.WriteLine("------------------SENSITIVE CONTENT---------------"); var TrickyImages = group.Files.Where(f => f.IsAdultContent == true || f.IsRacyContent == true); foreach (var TrickyImage in TrickyImages) { Console.WriteLine("{0} {1}", TrickyImage.Name, (TrickyImage.Tags != null) ? string.Join("/", TrickyImage.Tags) : String.Empty); } Console.WriteLine("----------------NEGATIVE MESSAGES--------------"); var NegativeMessages = group.Messages.Where(m => m.SentimentScore < 0.5).Take(5); var PositiveMessages = group.Messages.Where(m => m.SentimentScore >= 0.5).Take(5); foreach (var NegativeMessage in NegativeMessages) { Console.WriteLine("ID : {0} Score : {1} KP : {2}", NegativeMessage.Id, NegativeMessage.SentimentScore, (NegativeMessage.KeyPhrases != null) ? string.Join("/", NegativeMessage.KeyPhrases) : string.Empty); } Console.WriteLine("--------------POSITIVE MESSAGES--------------"); foreach (var PositiveMessage in PositiveMessages) { Console.WriteLine( "ID : {0} Score : {1} KP : {2}", PositiveMessage.Id, PositiveMessage.SentimentScore, (PositiveMessage.KeyPhrases != null) ? string.Join("/", PositiveMessage.KeyPhrases):String.Empty); } }