Beispiel #1
0
        /// <summary>
        /// Initiates the asynchronous execution of the DetectSentiment operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the DetectSentiment operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/comprehend-2017-11-27/DetectSentiment">REST API Reference for DetectSentiment Operation</seealso>
        public virtual Task <DetectSentimentResponse> DetectSentimentAsync(DetectSentimentRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = DetectSentimentRequestMarshaller.Instance;
            var unmarshaller = DetectSentimentResponseUnmarshaller.Instance;

            return(InvokeAsync <DetectSentimentRequest, DetectSentimentResponse>(request, marshaller,
                                                                                 unmarshaller, cancellationToken));
        }
        public async Task <int> GetSentimentAsIntAsync(string messageText)
        {
            var request = new DetectSentimentRequest()
            {
                Text = messageText, LanguageCode = LanguageCode.En
            };
            var sentiment = await _awsComprehendClient.DetectSentimentAsync(request);

            return(ParseSentimentToInt(sentiment));
        }
Beispiel #3
0
        public async Task <DetectSentimentResponse> GetSentiment(string text, DominantLanguage language)
        {
            var request = new DetectSentimentRequest()
            {
                Text         = text,
                LanguageCode = language.LanguageCode
            };
            var response = await _Client.DetectSentimentAsync(request);

            return(response);
        }
Beispiel #4
0
        public async Task <float> AnalyzePositivityAsync(string message)
        {
            var analyzeRequest = new DetectSentimentRequest()
            {
                LanguageCode = LanguageCode.En,
                Text         = message
            };
            var response = await this.comprehend.DetectSentimentAsync(analyzeRequest);

            return(response.SentimentScore.Positive);
        }
        public async Task <DetectSentimentResponse> DetermineSentiment(string text)
        {
            // Call DetectKeyPhrases API
            DetectSentimentRequest detectSentimentRequest = new DetectSentimentRequest()
            {
                Text         = text,
                LanguageCode = "en"
            };
            DetectSentimentResponse detectSentimentResponse = await config.AzComprehendClient.DetectSentimentAsync(detectSentimentRequest);

            return(detectSentimentResponse);
        }
        public static void Sample()
        {
            String text = "It is raining today in Seattle";

            var comprehendClient = new AmazonComprehendClient(Amazon.RegionEndpoint.USWest2);

            // Call DetectKeyPhrases API
            Console.WriteLine("Calling DetectSentiment");
            var detectSentimentRequest = new DetectSentimentRequest()
            {
                Text         = text,
                LanguageCode = "en"
            };
            var detectSentimentResponse = comprehendClient.DetectSentiment(detectSentimentRequest);

            Console.WriteLine(detectSentimentResponse.Sentiment);
            Console.WriteLine("Done");
        }
Beispiel #7
0
        /// <summary>
        /// This method calls the DetetectSentimentAsync method to analyze the
        /// supplied text and determine the overal sentiment.
        /// </summary>
        public static async Task Main()
        {
            string text = "It is raining today in Seattle";

            var comprehendClient = new AmazonComprehendClient(Amazon.RegionEndpoint.USWest2);

            // Call DetectKeyPhrases API
            Console.WriteLine("Calling DetectSentiment");
            var detectSentimentRequest = new DetectSentimentRequest()
            {
                Text         = text,
                LanguageCode = "en",
            };
            var detectSentimentResponse = await comprehendClient.DetectSentimentAsync(detectSentimentRequest);

            Console.WriteLine($"Sentiment: {detectSentimentResponse.Sentiment}");
            Console.WriteLine("Done");
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            String text = ExtFunc.Read("Input a text to Sentiment-Analysation i.E \"That was a nice trip. The Hotel was amazing!\"");

            AmazonComprehendClient comprehendClient = new AmazonComprehendClient(
                Amazon.RegionEndpoint.USEast1);

            // Call DetectKeyPhrases API
            Console.WriteLine("Calling DetectSentiment");
            DetectSentimentRequest detectSentimentRequest = new DetectSentimentRequest()
            {
                Text         = text,
                LanguageCode = "en"
            };
            DetectSentimentResponse detectSentimentResponse = comprehendClient.DetectSentiment(detectSentimentRequest);

            Console.WriteLine(detectSentimentResponse.Sentiment);
            Console.WriteLine("Done");
        }
Beispiel #9
0
        private async Task <string> GetComprehendData(string transcriptText, string key)
        {
            JObject transcriptJSON        = JObject.Parse(transcriptText);
            string  test                  = (string)transcriptJSON["Text"];
            AmazonComprehendClient client = new AmazonComprehendClient();


            DetectEntitiesRequest entitiesRequest = new DetectEntitiesRequest();

            entitiesRequest.LanguageCode = LanguageCode.En;
            entitiesRequest.Text         = test;



            DetectSentimentRequest sentimentRequest = new DetectSentimentRequest();

            sentimentRequest.LanguageCode = LanguageCode.En;
            sentimentRequest.Text         = test;

            DetectKeyPhrasesRequest keyPhrasesRequest = new DetectKeyPhrasesRequest();

            keyPhrasesRequest.LanguageCode = LanguageCode.En;
            keyPhrasesRequest.Text         = test;

            DetectEntitiesResponse entitiesResponse = await client.DetectEntitiesAsync(entitiesRequest);

            DetectSentimentResponse setimentResponse = await client.DetectSentimentAsync(sentimentRequest);

            DetectKeyPhrasesResponse keyPhrasesResponse = await client.DetectKeyPhrasesAsync(keyPhrasesRequest);


            CreateKeyPhraseCSV(key, keyPhrasesResponse);
            CreateSetimentJSON(key, setimentResponse);



            //now send the file to s3

            //we need to write two different files, one for setiment and one for Key Phrases.

            return(string.Empty);
        }
Beispiel #10
0
        private static string DetectSentiment(string text, AmazonComprehendClient comprehendClient)
        {
            var stringBuilder = new StringBuilder();

            var detectSentimentRequest = new DetectSentimentRequest()
            {
                Text         = text,
                LanguageCode = "en"
            };

            var detectSentimentResponse = comprehendClient.DetectSentiment(detectSentimentRequest);

            stringBuilder.AppendLine("Detect Sentiment:");
            stringBuilder.AppendLine("==========================");

            stringBuilder.AppendLine(detectSentimentResponse.Sentiment);

            Console.WriteLine("DetectSentiment => Done\n");

            return(stringBuilder.ToString());
        }
Beispiel #11
0
    protected override async Task <bool> HandleMessage(DiscordMessage discordMessage)
    {
        logger.LogInformation($"Getting 10 messages before {discordMessage.Id}");
        IReadOnlyList <DiscordMessage> messages = await discordMessage.Channel.GetMessagesAsync(10, before : discordMessage.Id);

        logger.LogInformation($"Got {messages.Count} messages before {discordMessage.Id}");

        string text = messages
                      .Select(m => m.Content)
                      .Aggregate("", (acc, value) => acc + "\n" + value);

        DetectSentimentRequest detectSentimentRequest = new DetectSentimentRequest();

        detectSentimentRequest.LanguageCode = "en";
        detectSentimentRequest.Text         = text;

        logger.LogInformation($"Calling AWS::Comprehend with {messages.Count} messages and total text length {text.Length}");
        DetectSentimentResponse detectSentimentResponse = await AmazonComprehendClient.DetectSentimentAsync(detectSentimentRequest);

        logger.LogInformation($"Called AWS::Comprehend with {messages.Count} messages");

        if (detectSentimentResponse.HttpStatusCode != System.Net.HttpStatusCode.OK)
        {
            return(false);
        }

        await metrics.AddCounter("Discord.SentimentScore.Positive", detectSentimentResponse.SentimentScore.Positive);

        await metrics.AddCounter("Discord.SentimentScore.Negative", detectSentimentResponse.SentimentScore.Negative);

        await metrics.AddCounter("Discord.SentimentScore.Mixed", detectSentimentResponse.SentimentScore.Mixed);

        await metrics.AddCounter("Discord.SentimentScore.Neutral", detectSentimentResponse.SentimentScore.Neutral);

        await metrics.AddCounter($"Discord.Sentiment.{detectSentimentResponse.Sentiment.Value}", 1);

        return(true);
    }