Exemplo n.º 1
0
        public string AnalyzeSentiment()
        {
            var statementSentimentCount = new Dictionary <string, int>();

            ReportHelper.InitializeSentimentCounters(statementSentimentCount);

            var statements = File.ReadAllLines(_file);

            foreach (var statement in statements)
            {
                var isNegative = _negativeSentimentAnalyser.IsWordSentiment(statement);
                var isPositive = _positiveSentimentAnalyser.IsWordSentiment(statement);


                if (isNegative == isPositive && isNegative)
                {
                    statementSentimentCount[Constants.NegativeSentimentLabel]++;
                    statementSentimentCount[Constants.PositiveSentimentLabel]++;
                }
                else if (isNegative)
                {
                    statementSentimentCount[Constants.NegativeSentimentLabel]++;
                }
                else if (isPositive)
                {
                    statementSentimentCount[Constants.PositiveSentimentLabel]++;
                }
            }

            var finalSentiment = determineSentiment(statementSentimentCount);

            return(finalSentiment);
        }
Exemplo n.º 2
0
        public void TestQuestionMarks()
        {
            var words = new Dictionary <string, int>();

            words.Add("\\?", 2);

            _negativeSentimentAnalyser = new NegativeSentimentAnalyser(words);

            var text = "A similar aspect can be applied to the matter at hand? Under which circumstances?";

            Assert.IsTrue(_negativeSentimentAnalyser.IsWordSentiment(text));
        }
Exemplo n.º 3
0
        public void TestSad()
        {
            var words = new Dictionary <string, int>();

            words.Add("Sadly", 1);

            _negativeSentimentAnalyser = new NegativeSentimentAnalyser(words);

            var text = "In essence, the ad was sadly misleading.";

            Assert.IsTrue(_negativeSentimentAnalyser.IsWordSentiment(text));
        }
Exemplo n.º 4
0
        public void TestComplain()
        {
            var words = new Dictionary <string, int>();

            words.Add("COMPLAIN", 1);

            _negativeSentimentAnalyser = new NegativeSentimentAnalyser(words);

            var text = "In essence, the complainant unhappily submitted that the advertisement is misleading.";

            Assert.IsTrue(_negativeSentimentAnalyser.IsWordSentiment(text));
        }
Exemplo n.º 5
0
        public void TestNegativeHappy()
        {
            var words = new Dictionary <string, int>();

            words.Add("complain", 1);

            _positiveSentimentAnalyser = new PositiveSentimentAnalyser(words);

            var text = "In essence, the ad was sadly misleading.";

            Assert.IsFalse(_positiveSentimentAnalyser.IsWordSentiment(text));
        }
Exemplo n.º 6
0
        public void TestHappy()
        {
            var words = new Dictionary <string, int>();

            words.Add("happy", 1);

            _positiveSentimentAnalyser = new PositiveSentimentAnalyser(words);

            var text =
                "The ASA Directorate was happy to considered the relevant documentation submitted by the respective parties.";

            Assert.IsTrue(_positiveSentimentAnalyser.IsWordSentiment(text));
        }
Exemplo n.º 7
0
        public void TestComplaintViaEmail()
        {
            var words = new Dictionary <string, int>();

            words.Add("complain", 1);

            _negativeSentimentAnalyser = new NegativeSentimentAnalyser(words);

            var text =
                "The respondent provided his email address [email protected] that Ms Watkins could use to send any complaints to.";

            Assert.IsTrue(_negativeSentimentAnalyser.IsWordSentiment(text));
        }
Exemplo n.º 8
0
        public void TestExclamationPoint()
        {
            var words = new Dictionary <string, int>();

            words.Add("\\!", 1);

            _positiveSentimentAnalyser = new PositiveSentimentAnalyser(words);

            var text =
                "Unilever lodged a competitor complaint against the respondent’s packaging of its Royco soup!";

            Assert.IsTrue(_positiveSentimentAnalyser.IsWordSentiment(text));
        }