public bool HasValue(SentimentCategory category)
        {
            switch (category)
            {
            case SentimentCategory.Anger:
                return(IsAnger);

            case SentimentCategory.Anticipation:
                return(IsAnticipation);

            case SentimentCategory.Disgust:
                return(IsDisgust);

            case SentimentCategory.Fear:
                return(IsFear);

            case SentimentCategory.Joy:
                return(IsJoy);

            case SentimentCategory.Sadness:
                return(IsSadness);

            case SentimentCategory.Surprise:
                return(IsSurprise);

            case SentimentCategory.Trust:
                return(IsTrust);

            case SentimentCategory.None:
                return(!HasAnyValue);

            default:
                throw new ArgumentOutOfRangeException(nameof(category));
            }
        }
예제 #2
0
        public static async Task <IActionResult> GetSentimentCategory(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            SentimentCategory sentimentCategory = SentimentCategory.NORMAL;

            log.LogInformation("Sentiment Webhook http function triggered");

            var sentimentObjects = JObject.Parse(await new StreamReader(req.Body).ReadToEndAsync());

            log.LogInformation($"Sentiment object array {sentimentObjects}");

            foreach (var sentiment in sentimentObjects["documents"])
            {
                log.LogInformation($"Sentiment object : sentiment id  {sentiment["id"] } , sentiment score : {sentiment["score"]}");

                var sentimentScore = double.Parse(Convert.ToString(sentiment["score"]));

                // If content of mail is negative ,
                // return ASAP as response for immediate attention

                if (sentimentScore < 0.4)
                {
                    sentimentCategory = SentimentCategory.ASAP;
                }

                // If content of mail is neutral ,
                // return NEUTRAL as response

                else if (sentimentScore < 0.7)
                {
                    sentimentCategory = SentimentCategory.NEUTRAL;
                }

                log.LogInformation($"Sentiment category based on score { sentimentCategory }");
            }

            return(new OkObjectResult(sentimentCategory.ToString()));
        }