コード例 #1
0
        public SentimentMessage Process(IProcessor processor)
        {
            if (null != _score)
            {
                throw new Exception("Message cannot be processed multiple times");
            }

            _score = processor.Process(GetMessage());

            _textSentiment = GetRankedLabel(GetScore());

            return(this);
        }
コード例 #2
0
        public static Sentiment.TextSentiment GetRankedLabel(SentimentScore messageScore)
        {
            var sentimentRank = new Dictionary <Sentiment.TextSentiment, double>
            {
                { Sentiment.TextSentiment.Positive, messageScore.Positive },
                { Sentiment.TextSentiment.Neutral, messageScore.Neutral },
                { Sentiment.TextSentiment.Negative, messageScore.Negative }
            };

            if (messageScore.Neutral.CompareTo(messageScore.Positive) == 0 &&
                messageScore.Neutral.CompareTo(messageScore.Negative) == 0)
            {
                return(Sentiment.TextSentiment.Neutral);
            }

            return(sentimentRank.OrderBy(item => item.Value).Last().Key);
        }