Ejemplo n.º 1
0
        public TTweet AnalyzeSingle(ITweet tweet)
        {
            TTweet temp = new TTweet();

            temp.t = tweet;
            string[] words = tweet.Text.Split(' ');
            temp.numWords = words.Length;

            //Pulls out 6 emotionalChar of a tweet
            pullSixOut(words, temp);
            pullSubjectiviityOut(words, temp);
            return(temp);
        }
Ejemplo n.º 2
0
        public void pullSubjectiviityOut(string[] words, TTweet temp)
        {
            temp.subjectivities = new List <TTweet.subjectivity>();

            foreach (var tweet_word in words)
            {
                foreach (var word_dic in wordSbs)
                {
                    if (tweet_word.Contains(word_dic.word))
                    {
                        temp.pos = (word_dic.posneg.Contains("positive")) ? TTweet.positive.POSITIVE : TTweet.positive.NEGATIVE;
                        temp.str = (word_dic.posneg.Contains("strongsubj")) ? TTweet.strong.STRONG : TTweet.strong.WEAK;

                        TTweet.subjectivity tempSub = new TTweet.subjectivity(true, true);
                        if (temp.pos == TTweet.positive.POSITIVE)
                        {
                            if (temp.str == TTweet.strong.STRONG)
                            {
                                tempSub.positive = true;
                                tempSub.strong   = true;
                            }
                            else if (temp.str == TTweet.strong.WEAK)
                            {
                                tempSub.positive = true;
                                tempSub.strong   = false;
                            }
                        }
                        else if (temp.pos == TTweet.positive.NEGATIVE)
                        {
                            if (temp.str == TTweet.strong.STRONG)
                            {
                                tempSub.positive = false;
                                tempSub.strong   = true;
                            }
                            else if (temp.str == TTweet.strong.WEAK)
                            {
                                tempSub.positive = false;
                                tempSub.strong   = false;
                            }
                        }

                        temp.subjectivities.Add(tempSub);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        //Updates the tweets score of the 6 traits based on emotions
        public void pullSixOut(string[] words, TTweet temp)
        {
            foreach (var word in words)
            {
                countWord(word);
                foreach (var emotion in wordEs)
                {
                    if (word.Contains(emotion.e))
                    {
                        switch (emotion.word)
                        {
                        case "joy":
                            temp.joy++;
                            break;

                        case "anger":
                            temp.anger++;
                            break;

                        case "surprise":
                            temp.surprise++;
                            break;

                        case "disgust":
                            temp.disgust++;
                            break;

                        case "fear":
                            temp.fear++;
                            break;

                        case "sadness":
                            temp.sadness++;
                            break;

                        default:
                            break;
                        }
                        break;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private TTweetList AnalyzeList(IEnumerable <ITweet> tweets)
        {
            var tempList = new TTweetList();
            var temp     = new List <TTweet>();

            int tweetCounter = 0;
            int wordCounter  = 0;

            double tempPos = 0;
            double tempNeg = 0;

            foreach (var item in tweets)
            {
                //Need to account for word and text lenght missing from TTWEET
                TTweet f = AnalyzeSingle(item);
                temp.Add(f);

                tempPos += f.getSubHits(TTweet.positive.POSITIVE, TTweet.strong.ALL);
                tempNeg += f.getSubHits(TTweet.positive.NEGATIVE, TTweet.strong.ALL);

                wordCounter       += f.numWords;
                tempList.anger    += f.anger;
                tempList.disgust  += f.disgust;
                tempList.fear     += f.fear;
                tempList.joy      += f.joy;
                tempList.surprise += f.surprise;
                tempList.sadness  += f.sadness;
                tweetCounter++;
            }

            if (tweetCounter != 0)
            {
                tempList.tweetLength = wordCounter / tweetCounter;
                tempPos = tempPos / tweetCounter;
                tempNeg = tempNeg / tweetCounter;
            }


            double c = 35 + ((tempPos - tempNeg * .5) / (tempPos + tempNeg * .5) * 500);

            if (tempPos == 0 && tempNeg == 0)
            {
                c = 0;
            }
            Console.WriteLine(tempPos + "||" + tempNeg);
            c = (c >= 100) ? 100 : c;
            c = (c <= -100) ? -100 : c;
            tempList.positivity = c;

            tempList.size =
                tempList.anger +
                tempList.disgust +
                tempList.fear +
                tempList.joy +
                tempList.surprise +
                tempList.sadness;

            wordCountList = wordCountList.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);

            topN = new List <string>();
            int    countt = 0;
            string line;


            foreach (var item in wordCountList)
            {
                StreamReader file = new System.IO.StreamReader("DataClassify/NounList.csv");
                while ((line = file.ReadLine()) != null)
                {
                    if (item.Key.Equals(line) && countt < 10)
                    {
                        topN.Add(item.Key);
                        countt++;
                        if (countt > 10)
                        {
                            return(tempList);
                        }
                    }
                }
            }

            return(tempList);
        }