public double GetSentiment(string text, string sentimentType = "Compound")
        {
            /// Receives a text to be analyzed,
            /// sentimentType parameter will be what sentiment analysis to return:
            ///     Sentiment Types are "Positive", "Negative", "Neutral", or "Compound"
            ///     Type defaults to compound score

            // Creates an analyzer object
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();

            var results = analyzer.PolarityScores(text);

            switch (sentimentType)
            {
            case "Positive":
                return(Convert.ToDouble(results.Positive));

            case "Negative":
                return(Convert.ToDouble(results.Negative));

            case "Neutral":
                return(Convert.ToDouble(results.Neutral));

            default:
                return(Convert.ToDouble(results.Compound));
            }
        }
        public static async Task <List <AzureSentiment> > VaderSentimentAnalytics(Docs json, string score_type, bool stopword)
        {
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();



            List <AzureSentiment> azureSentiments = new List <AzureSentiment> {
            };


            foreach (var item in json.documents)
            {
                string text = item.text;

                if (stopword)
                {
                    //if stops words, clean the text.
                    text = Stopword.cleaner(item.text);
                }

                var score = analyzer.PolarityScores(text);
                var type  = new Hashtable {
                    { "compound", score.Compound },
                    { "neutral", score.Neutral },
                    { "positive", score.Positive },
                    { "negative", score.Negative }
                };

                azureSentiments.Add(new AzureSentiment {
                    id = item.id, score = (double)type[score_type]
                });
            }

            return(azureSentiments.ToList());
        }
Example #3
0
        public static async Task <double?> GetVaderAsync(string text)
        {
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();
            var results = analyzer.PolarityScores(text);

            return(results.Compound);;
        }
Example #4
0
        public void MatchPythonTest()
        {
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();

            var standardGoodTest = analyzer.PolarityScores("VADER is smart, handsome, and funny.");

            Assert.AreEqual(standardGoodTest.Negative, 0);
            Assert.AreEqual(standardGoodTest.Neutral, 0.254);
            Assert.AreEqual(standardGoodTest.Positive, 0.746);
            Assert.AreEqual(standardGoodTest.Compound, 0.8316);

            var kindOfTest = analyzer.PolarityScores("The book was kind of good.");

            Assert.AreEqual(kindOfTest.Negative, 0);
            Assert.AreEqual(kindOfTest.Neutral, 0.657);
            Assert.AreEqual(kindOfTest.Positive, 0.343);
            Assert.AreEqual(kindOfTest.Compound, 0.3832);

            var complexTest =
                analyzer.PolarityScores(
                    "The plot was good, but the characters are uncompelling and the dialog is not great.");

            Assert.AreEqual(complexTest.Negative, 0.327);
            Assert.AreEqual(complexTest.Neutral, 0.579);
            Assert.AreEqual(complexTest.Positive, 0.094);
            Assert.AreEqual(complexTest.Compound, -0.7042);
        }
Example #5
0
        //Get sentiment for given keywords over {duration} days
        public SentimentAnalysisResult GetSentiment(string[] keywords, int tweetCount = 100, bool translate = false)
        {
            List <ITweet> tweets = new List <ITweet>();

            //Get all the tweets for each keyword
            foreach (var keyword in keywords)
            {
                var searchParameter = new SearchTweetsParameters(keyword)
                {
                    Filters = TweetSearchFilters.Images,
                    //SinceId = (int)(DateTime.UtcNow.AddDays(duration * -1).Subtract(new DateTime(1970, 1, 1))).TotalSeconds
                };

                if (!translate)
                {
                    searchParameter.Lang = LanguageFilter.English;
                }

                var someTweets = Search.SearchTweets(searchParameter);
                if (someTweets != null)
                {
                    tweets.AddRange(someTweets);
                }
                else
                {
                    throw new Exception("Twitter rate limit reached.");
                }
            }

            //Translate them to sentiment results
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();

            string sanitizedTweet = Sanitize(tweets[0].FullText);
            var    results        = analyzer.PolarityScores(sanitizedTweet);
            //First result needs no math
            SentimentAnalysisResult overallSentiment = new SentimentAnalysisResult()
            {
                Negative     = results.Negative,
                Neutral      = results.Neutral,
                Positive     = results.Positive,
                Compound     = results.Compound,
                ItemsChecked = 1
            };

            //Keep an average of the sentiment in the found tweets
            for (int i = 1; i < tweets.Count(); i++)
            {
                sanitizedTweet = Sanitize(tweets[i].FullText);
                results        = analyzer.PolarityScores(sanitizedTweet);

                overallSentiment.Negative = overallSentiment.Negative + (results.Negative - overallSentiment.Negative) / overallSentiment.ItemsChecked;
                overallSentiment.Neutral  = overallSentiment.Neutral + (results.Neutral - overallSentiment.Neutral) / overallSentiment.ItemsChecked;
                overallSentiment.Positive = overallSentiment.Positive + (results.Positive - overallSentiment.Positive) / overallSentiment.ItemsChecked;
                overallSentiment.Compound = overallSentiment.Compound + (results.Compound - overallSentiment.Compound) / overallSentiment.ItemsChecked;
                overallSentiment.ItemsChecked++;
            }

            return(overallSentiment);
        }
Example #6
0
 private FilterJsonRead(FilterJsonRead src)
 {
     Ids          = src.Ids;
     ExpectedSize = src.ExpectedSize;
     Records      = new List <TweetScore>(ExpectedSize);
     _ser         = new DataContractJsonSerializer(typeof(UniTwitterRow));
     analyzer     = new SentimentIntensityAnalyzer();
 }
Example #7
0
        // analyzes the sentiment
        private void sentimentAnalyze(string input)
        {
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();

            var results = analyzer.PolarityScores(input);

            Program.Logger.Buffer.Sentiment = results.Compound;
        }
Example #8
0
        static double GetScore(String Input)
        {
            SentimentIntensityAnalyzer SIA = new SentimentIntensityAnalyzer();
            SentimentAnalysisResults   SAR = SIA.PolarityScores(Input);
            double CS = SAR.Compound;

            return(CS);
        }
Example #9
0
 protected override ApiResult ProcessClientQueueMessage(TextArtifact message)
 {
     foreach (string t in message.Text.Split(Environment.NewLine.ToCharArray()))
     {
         var k = SentimentIntensityAnalyzer.PolarityScores(t);
         message.Sentiment[t] = k.Compound;
     }
     return(ApiResult.Success);
 }
        //-------------------------------------------------------------------------- VaderSharp for Sentiment Score-------------------------------------
        //-- better for social media
        public static SentimentAnalysisResults runTweetAnalysis(string raw)
        {
            // var sanitized = sanitize(raw);

            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();
            var results = analyzer.PolarityScores(raw);

            return(results);
        }
Example #11
0
        public static void Serialize(IEnumerable <ITweet> tweets, string topic)
        {
            jsontweets = new List <DAL.Tweet>();
            //perform sentiment analysis on the tweet
            var analyzer = new SentimentIntensityAnalyzer();

            using (var db = new SentimentContext())
            {
                if (db.Tweets.Count() > 1)
                {
                    db.Tweets.RemoveRange(db.Tweets);
                }

                foreach (var tweet in tweets)
                {
                    var check = db.Tweets.Where(x => x.TwitterId == tweet.Id).FirstOrDefault();
                    if (check == null)
                    {
                        jsontweets.Add(new DAL.Tweet()
                        {
                            TweetId = DateTime.Now.ToString(CultureInfo.CurrentCulture),

                            //TweetContent = tweet.ToJson(),


                            TweetHandle  = tweet.CreatedBy.ScreenName,
                            TweetMsg     = tweet.FullText,
                            TwitterId    = tweet.Id,
                            TweetImgLink = tweet.CreatedBy.ProfileImageUrl400x400,
                            Topic        = topic,

                            TweetSentimentPositiveValue = $"{analyzer.PolarityScores(tweet.FullText).Positive.ToString(CultureInfo.CurrentCulture)}",
                            TweetSentimentNegativeValue = $"{analyzer.PolarityScores(tweet.FullText).Negative.ToString(CultureInfo.CurrentCulture)}",
                            TweetSentimentNeutralValue  = $"{analyzer.PolarityScores(tweet.FullText).Neutral.ToString(CultureInfo.CurrentCulture)}",
                            TweetSentimentCompoundValue = $"{analyzer.PolarityScores(tweet.FullText).Compound.ToString(CultureInfo.CurrentCulture)}",
                        });
                    }

                    db.Tweets.AddRange(jsontweets);
                }

                db.SaveChanges();
                //var serializer = new Newtonsoft.Json.JsonSerializer();
                //serializer.NullValueHandling = NullValueHandling.Ignore;
                //serializer.TypeNameHandling = TypeNameHandling.Auto;
                //serializer.Formatting = Formatting.Indented;


                //using (var sw = new StreamWriter(@".\tweets.json", true))
                //{
                //    using (JsonWriter jwriter = new JsonTextWriter(sw))
                //    {
                //        serializer.Serialize(jwriter, jsontweets, typeof(List<DAL.Tweet>));
                //    }
                //}
            }
        }
        public static double computeSentiment(string text)
        {
            SentimentIntensityAnalyzer s = new SentimentIntensityAnalyzer();
            SentimentAnalysisResults   k = new SentimentAnalysisResults();

            k = s.PolarityScores(text);
            double res = k.Compound;

            return(res = Math.Abs(res / 0.4) * 5);
        }
Example #13
0
        public override ApiResult Init()
        {
            if (Status != ApiStatus.Initializing)
            {
                SetErrorStatusAndReturnFailure();
            }

            SentimentIntensityAnalyzer = new SentimentIntensityAnalyzer();
            return(SetInitializedStatusAndReturnSucces());
        }
Example #14
0
        private void Analyze()
        {
            var analyzer = new SentimentIntensityAnalyzer();
            var results  = analyzer.PolarityScores(this.Content);

            this._positive = results.Positive;
            this._negative = results.Negative;
            this._neutral  = results.Neutral;
            this._compound = results.Compound;
        }
Example #15
0
        public void GivenAPositiveSentence_WhenPolarityScores_ThenTheScoreIsPositive()
        {
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();

            var standardGoodTest = analyzer.CalculatePolarityScores("VADER is smart, handsome, and funny.");

            Assert.Equal(standardGoodTest.Negative, 0);
            Assert.Equal(standardGoodTest.Neutral, 0.254);
            Assert.Equal(standardGoodTest.Positive, 0.746);
            Assert.Equal(standardGoodTest.Compound, 0.8316);
        }
Example #16
0
        public void GivenANeutralSentence_WhenPolarityScores_ThenTheScoreIsNeutral()
        {
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();

            var kindOfTest = analyzer.CalculatePolarityScores("The book was kind of good.");

            Assert.Equal(kindOfTest.Negative, 0);
            Assert.Equal(kindOfTest.Neutral, 0.657);
            Assert.Equal(kindOfTest.Positive, 0.343);
            Assert.Equal(kindOfTest.Compound, 0.3832);
        }
        public void Initialise(int engId, string tgtLocation, Encoding encoding)
        {
            TgtLocation = tgtLocation;

            _encoding = encoding;
            _inSer    = new DataContractJsonSerializer(typeof(TweetScore));
            _analyzer = new SentimentIntensityAnalyzer();

            _outSer = new DataContractJsonSerializer(typeof(TweetScore));
            _ofs    = File.Open(Path.Combine(TgtLocation, $"twitter-TweetScore-{engId}.json"), FileMode.Create);
        }
        private void Analyze(object obj)
        {
            SentimentIntensityAnalyzer  analyzer   = new SentimentIntensityAnalyzer();
            SentimentAnalyzerController regression = new SentimentAnalyzerController();

            foreach (Comment comment in Comments)
            {
                var analyzed = analyzer.PolarityScores(comment.Text);
                comment.NaiveBayes         = String.Format("Positive: {0} Neutral: {1} Negative: {2} Compound: {3}", analyzed.Positive, analyzed.Neutral, analyzed.Negative, analyzed.Compound);
                comment.LogisticRegression = regression.GetTextForMark(comment.Text).ToString();
            }
        }
Example #19
0
        public void GivenAComplexSentence_WhenPolarityScores_ThenTheScoreIsComplex()
        {
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();

            var complexTest =
                analyzer.CalculatePolarityScores(
                    "The plot was good, but the characters are uncompelling and the dialog is not great.");

            Assert.Equal(complexTest.Negative, 0.327);
            Assert.Equal(complexTest.Neutral, 0.579);
            Assert.Equal(complexTest.Positive, 0.094);
            Assert.Equal(complexTest.Compound, -0.7042);
        }
Example #20
0
        public void Classify(List <User> userList)
        {
            foreach (User user in userList)
            {
                double score = 0.0;

                if (user.GetReview() != "*")
                {
                    SentimentIntensityAnalyzer sentimentAnalyzer = new SentimentIntensityAnalyzer();
                    string deltaReview = Regex.Replace(user.GetReview(), "<.*?>", "");

                    var results = sentimentAnalyzer.PolarityScores(deltaReview);

                    if (results.Compound >= 0.5)
                    {
                        if (results.Compound >= 0.75)
                        {
                            score = 5;
                        }
                        else
                        {
                            score = 4;
                        }
                    }
                    else if (results.Compound <= -0.5)
                    {
                        if (results.Compound <= -0.75)
                        {
                            score = 1;
                        }
                        else
                        {
                            score = 2;
                        }
                    }
                    else
                    {
                        score = 3.0;
                    }
                }
                user.SetScore(score);
            }
        }
        private static void OnMatchedTweet_AnalyseUsing_VADER(object sender, MatchedTweetReceivedEventArgs args)
        {
            Console.WriteLine("**********************************New match tweet received*********************");
            var sanitized = sanitize(args.Tweet.FullText);
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();

            var results = analyzer.PolarityScores(sanitized);

            Console.WriteLine("---------------------------------------");

            Console.WriteLine($"tweet :- {args.Tweet}");
            Console.WriteLine("Positive score: " + results.Positive);
            Console.WriteLine("Negative score: " + results.Negative);
            Console.WriteLine("Neutral score: " + results.Neutral);
            Console.WriteLine("Compound score: " + results.Compound);



            Console.WriteLine("***********************************************************************");
        }
Example #22
0
        public static async Task <double?> GetVaderSentAvgAsync(List <string> tweets)
        {
            double temp;
            double?retval = 0;
            int    count  = tweets.Count;
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();

            foreach (string text in tweets)
            {
                var results = analyzer.PolarityScores(text);

                if (results.Compound == 0 && count > 0)
                {
                    count--;
                }
                else
                {
                    retval += results.Compound;
                }
            }

            // SAFE GUARD AGAINST ANY ILLEGAL RETURN VALUES
            if (tweets.Count > 0)
            {
                try
                {
                    retval = retval / count;
                }
                catch
                {
                    return(0);
                }

                if (retval == Double.NaN || !Double.TryParse(retval.ToString(), out temp))
                {
                    retval = 0;
                }
            }

            return(retval);
        }
Example #23
0
        /// <summary>
        /// Actually performs sentimnet analysis
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BgWkrProcess_DoWork(object sender, DoWorkEventArgs e)
        {
            bgWkrProcess.ReportProgress(0);
            Document doc;

            java.util.List jSents;
            chapterSents = new List <List <string> >();
            inputText    = "";
            for (int i = 0; i < inputChapters.Count; i++)
            {
                doc    = new Document(inputChapters[i]);
                jSents = doc.sentences();
                List <string> cSents = new List <string>();
                for (java.util.Iterator itr = jSents.iterator(); itr.hasNext();)
                {
                    cSents.Add(((Sentence)itr.next()).text());
                    inputText = inputText + cSents[cSents.Count - 1] + Environment.NewLine;
                }
                chapterSents.Add(cSents);
            }

            bgWkrProcess.ReportProgress(50);
            SentimentIntensityAnalyzer      analyzer = new SentimentIntensityAnalyzer();
            SentimentAnalysisResults        results;
            List <SentimentAnalysisResults> temp = new List <SentimentAnalysisResults>();

            chapterResultsList = new List <List <SentimentAnalysisResults> >();
            sents = new List <string>();
            foreach (List <string> outputChapter in chapterSents)
            {
                temp.Clear();
                foreach (string c in outputChapter)
                {
                    results = analyzer.PolarityScores(c);
                    sents.Add(c);
                    temp.Add(results);
                }
                chapterResultsList.Add(new List <SentimentAnalysisResults>(temp));
            }
            bgWkrProcess.ReportProgress(100);
        }
Example #24
0
        public static List <DAL.Tweet> reSerialize(List <DAL.Tweet> tweets)
        {
            var jsontweets = new List <DAL.Tweet>();
            //perform sentiment analysis on the tweet
            var analyzer = new SentimentIntensityAnalyzer();

            foreach (var tweet in tweets)
            {
                jsontweets.Add(new DAL.Tweet()
                {
                    TweetId = tweet.TweetId,
                    TweetSentimentPositiveValue = $"{analyzer.PolarityScores(tweet.TweetMsg).Positive.ToString(CultureInfo.CurrentCulture)}",
                    TweetSentimentNegativeValue = $"{analyzer.PolarityScores(tweet.TweetMsg).Negative.ToString(CultureInfo.CurrentCulture)}",
                    TweetSentimentNeutralValue  = $"{analyzer.PolarityScores(tweet.TweetMsg).Neutral.ToString(CultureInfo.CurrentCulture)}",
                    TweetSentimentCompoundValue = $"{analyzer.PolarityScores(tweet.TweetMsg).Compound.ToString(CultureInfo.CurrentCulture)}",

                    TweetHandle  = tweet.TweetHandle,
                    TweetMsg     = tweet.TweetMsg,
                    TwitterId    = tweet.TwitterId,
                    TweetImgLink = tweet.TweetImgLink,
                    Topic        = tweet.Topic,
                });
            }

            return(jsontweets);
            //var serializer = new Newtonsoft.Json.JsonSerializer();
            //serializer.NullValueHandling = NullValueHandling.Ignore;
            //serializer.TypeNameHandling = TypeNameHandling.Auto;
            //serializer.Formatting = Formatting.Indented;


            //using (var sw = new StreamWriter(@".\tweets.json", true))
            //{
            //    using (JsonWriter jwriter = new JsonTextWriter(sw))
            //    {
            //        serializer.Serialize(jwriter, jsontweets, typeof(List<DAL.Tweet>));
            //    }
            //}
        }
        private static void Main(string[] args)
        {
            var analyzer = new SentimentIntensityAnalyzer();

            Console.WriteLine($"Start {DateTime.Now}");

            const string src =
                @"E:\uni\Cluster and Cloud Computing\assign2\TwitterExplore\Extracts\FilteredExtract\bin\twitter-geotagged-posters.json";
            const string bigSrc =
                @"E:\uni\Cluster and Cloud Computing\assign2\TwitterExplore\Extracts\FilteredExtract\bin\data\twitter-all-geotagged-posters.json";

            var geoPosts = new JsonRead <TagPosterDetails>(new[] { bigSrc });

            geoPosts.DoLoad();

            var outcome = new List <KeyValuePair <double, string> >();

            foreach (var txt in geoPosts.Records.Select(x => x.Text))
            {
                var res = analyzer.PolarityScores(txt);
                outcome.Add(new KeyValuePair <double, string>(res.Compound, txt));
            }

            Console.WriteLine($"\nTotal Number: {outcome.Count:N0}\n");
            Console.WriteLine($"\nMin {outcome.Min(x => x.Key):P2}");
            Console.WriteLine($"Max {outcome.Max(x => x.Key):P2}");
            Console.WriteLine($"Number Zeros {outcome.Count(x => -0.02 < x.Key && x.Key < 0.02):N0}");
            Console.WriteLine($"Average rating {outcome.Average(x => x.Key):P2}\n");


            using (var of = new StreamWriter(@"..\..\BigScore.csv"))
            {
                foreach (var kvp in outcome.OrderByDescending(x => x.Key))
                {
                    of.WriteLine($"{kvp.Key:P}\t{kvp.Value.Pack()}");
                }
            }
        }
Example #26
0
        public void TestSentiment()
        {
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();
            string myStringIsABlowup            = "RECONSIDER THIS FORMULA!!<br /><br />Martek advertises this formula on their website!<br /><br /> Although Martek told the board that they would discontinue the use of the controversial neurotoxic solvent n-hexane for DHA/ARA processing, they did not disclose what other synthetic solvents would be substituted. Federal organic standards prohibit the use of all synthetic/petrochemical solvents.<br /><br />Martek Biosciences was able to dodge the ban on hexane-extraction by claiming USDA does not consider omega-3 and omega-6 fats to be agricultural ingredients. Therefore, they argue, the ban against hexane extraction does not apply. The USDA helped them out by classifying those oils as necessary vitamins and minerals, which are exempt from the hexane ban. But hexane-extraction is just the tip of the iceberg. Other questionable manufacturing practices and misleading statements by Martek included:<br /><br />Undisclosed synthetic ingredients, prohibited for use in organics (including the sugar alcohol mannitol, modified starch, glucose syrup solids, and other undisclosed ingredients)<br />Microencapsulation of the powder and nanotechnology, which are prohibited under organic laws<br />Use of volatile synthetic solvents, besides hexane (such as isopropyl alcohol)<br />Recombinant DNA techniques and other forms of genetic modification of organisms; mutagenesis; use of GMO corn as a fermentation medium<br />Heavily processed ingredients that are far from natural<br /><br />quote from: Why is this Organic Food Stuffed With Toxic Solvents? by Dr. Mercola - GOOGLE GMOs found in Martek.<br /><br />This is the latest I have found on DHA in organic and non organic baby food/ formula:<br />AT LEAST READ THIS ONE*** GOOGLE- False Claims That DHA in Organic and Non-Organic Infant Formula Is Safe. AND OrganicconsumersDOTorg<br /><br />Martek's patents for Life'sDHA states: includes mutant organisms and recombinant organisms, (a.k.a. GMOs!) The patents explain that the oil is extracted readily with an effective amount of solvent ... a preferred solvent is hexane.<br /><br />The patent for Life'sARA states: genetically-engineering microorganisms to produce increased amounts of arachidonic acid and extraction with solvents such as ... hexane. Martek has many other patents for DHA and ARA. All of them include GMOs. GMOs and volatile synthetic solvents like hexane aren't allowed in USDA Organic products and ingredients.<br /><br />Tragically, Martek's Life'sDHA is already in hundreds of products, many of them certified USDA Organic. Please demand that the National Organic Standards Board reject Martek's petition, and that the USDA National Organic Program inform the company that the illegal 2006 approval is rescinded and that their GMO, hexane-extracted Life'sDHA and Life'sARA are no longer allowed in organic products.<br /><br />BUT I went to the lifesdha website and THEY DO NOT DISCLOSE HOW THEY MAKE THEIR LifesDHA!!! I have contacted the company to see what they say.<br /><br />Also these are the corporate practices of Martek which are damaging to the environment as well written just last Dec 2011 at NaturalnewsDOTcom<br /><br />The best bet is to just avoid the lifeDHA at this time in my opinion b/c corporate america cares more about the almighty $ than your health.";
            string fixMyString = Regex.Replace(myStringIsABlowup, @"<[^>]*>", " ");

            List <string> sentences = new List <string> {
                "VADER is smart, handsome, and funny.",                                                // positive sentence example
                "VADER is smart, handsome, and funny!",                                                // punctuation emphasis handled correctly (sentiment intensity adjusted)
                "VADER is very smart, handsome, and funny.",                                           // booster words handled correctly (sentiment intensity adjusted)
                "VADER is VERY SMART, handsome, and FUNNY.",                                           // emphasis for ALLCAPS handled
                "VADER is VERY SMART, handsome, and FUNNY!!!",                                         // combination of signals - VADER appropriately adjusts intensity
                "VADER is VERY SMART, uber handsome, and FRIGGIN FUNNY!!!",                            // booster words & punctuation make this close to ceiling for score
                "VADER is not smart, handsome, nor funny.",                                            // negation sentence example
                "The book was good.",                                                                  // positive sentence
                "At least it isn't a horrible book.",                                                  // negated negative sentence with contraction
                "The book was only kind of good.",                                                     // qualified positive sentence is handled correctly (intensity adjusted)
                "The plot was good, but the characters are uncompelling and the dialog is not great.", // mixed negation sentence
                "Today SUX!",                                                                          // negative slang with capitalization emphasis
                "Today only kinda sux! But I'll get by, lol",                                          // mixed sentiment example with slang and constrastive conjunction "but"
                "Make sure you :) or :D today!",                                                       // emoticons handled
                "Catch utf-8 emoji such as such as 💘 and 💋 and 😁",                                     // emojis handled
                "Not bad at all"                                                                       // Capitalized negation
            };

            foreach (var sentence in sentences)
            {
                var sentence2 = analyzer.PolarityScores(sentence);
                Console.WriteLine("----------------");
                Console.WriteLine(sentence);
                Console.WriteLine("Positive score: " + sentence2.Positive);
                Console.WriteLine("Negative score: " + sentence2.Negative);
                Console.WriteLine("Neutral score: " + sentence2.Neutral);
                Console.WriteLine("Compound score: " + sentence2.Compound);
            }
        }
Example #27
0
        public string GetReactionOfComment(string comment)
        {
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();

            var    results  = analyzer.PolarityScores(comment);
            string reaction = "";

            if (results.Positive > results.Compound && results.Positive >= results.Neutral && results.Positive > results.Negative)
            {
                reaction = "Positive " + results.Positive * 100 + "%";
            }



            else if (results.Negative > results.Compound && results.Negative > results.Neutral && results.Negative > results.Positive)
            {
                reaction = "Negative ";
            }
            else
            {
                reaction = "Neutral Reaction";
            }
            return(reaction);
        }
 public SentimentAnalyzationService(SentimentIntensityAnalyzer sentimentIntensityAnalyzer)
 {
     _sentimentIntensityAnalyzer = sentimentIntensityAnalyzer;
 }
 private Classify(Classify src)
 {
     _analyzer = new SentimentIntensityAnalyzer(src._analyzer);
     Sad       = new SADictionary(src.Sad.SASets);
 }
 public Classify(List <TagPosterDetails> items, SADictionary sad)
 {
     Records   = items;
     Sad       = sad;
     _analyzer = new SentimentIntensityAnalyzer();
 }