virtual protected void SentimentAnalysis(TextAnalyticsResult result) { DocumentSentiment documentSentiment = Client.AnalyzeSentiment(result.Input); result.Sentiment = documentSentiment.Sentiment; result.Positive = documentSentiment.ConfidenceScores.Positive; result.Negative = documentSentiment.ConfidenceScores.Negative; result.Neutral = documentSentiment.ConfidenceScores.Neutral; }
virtual public TextAnalyticsResult Run(string input) { TextAnalyticsResult result = new TextAnalyticsResult { Input = input }; SentimentAnalysis(result); KeyPhraseExtraction(result); return(result); }
/// <summary> /// Extracts the data, runs it through text analytics, then writes it back into the output /// </summary> /// <param name="options"></param> /// <param name="output"></param> /// <param name="rows"></param> virtual protected void ReadAndWriteRows(Options options, CsvWriter output, IEnumerable <dynamic> rows, CsvWriter keyPhraseOutput) { // Data var rowsToProcess = rows.Skip(1); if (options.Take.HasValue) { rowsToProcess = rowsToProcess.Take(options.Take.Value); } int index = 1; IEnumerable <dynamic> dataRows = rowsToProcess; TextAnalytics analytics = new TextAnalytics(); foreach (dynamic row in dataRows) { System.Console.WriteLine($"Processing row {index++}"); List <string> outputRow = new List <string>(); foreach (dynamic col in row) { string header = col.Key; string value = col.Value; output.WriteField(value); if (IsAnalysisColumn(options, header)) { TextAnalyticsResult result = analytics.Run(value); output.WriteField(result.Sentiment.ToString()); // TODO: Sentiment Scores output.WriteField(result.KeyPhrasesSummary); foreach (string phrase in result.KeyPhrases) { keyPhraseOutput.WriteField(phrase); keyPhraseOutput.NextRecord(); } } } output.NextRecord(); } System.Console.WriteLine($"Analysis Done on {index - 1} rows"); }
virtual protected void KeyPhraseExtraction(TextAnalyticsResult result) { Response <KeyPhraseCollection> response = Client.ExtractKeyPhrases(result.Input); result.KeyPhrases = response.Value.ToArray(); }