Beispiel #1
0
        //Conjunction based opinion word extraction process 100%

        protected string GetConjunctionBaseOpinionWord(string word, int index, string sentence)
        {
            FillConjunctions();
            FillNegativeWords();
            FillPositiveWords();
            var tempWord = "";

            if (index + 2 <= WordsInSentence.Length || index + 1 <= WordsInSentence.Length)
            {
                var unknown = WordsInSentence[index];
                foreach (var conjunction in Conjunctions)
                {
                    if (Equals(conjunction, unknown))
                    {
                        if (PositiveWords.Contains(WordsInSentence[index + 1]) ||
                            NegativeWords.Contains(WordsInSentence[index + 1]))
                        {
                            tempWord = WordsInSentence[index + 1];
                            return(tempWord);
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        //Extract new opinion words 70%
        protected List <OpinionWord> ExtractOpinionWords()
        {
            FillPositiveWords();
            FillNegativeWords();
            Lexicon();
            PositionOfReview      = 0;
            DoublePropagationList = new List <OpinionWord>();
            foreach (var opinion in Opinions)
            {
                SentenceIndex     = 0;
                SentencesInReview = SentencesSeparator(SentencesInReview, PositionOfReview);
                foreach (var sentence in SentencesInReview)
                {
                    WordsInSentence = EachWordInSentence(WordsInSentence, SentencesInReview, SentenceIndex);
                    var i = -1;
                    foreach (var word in WordsInSentence)
                    {
                        i++;
                        var tempWord    = word.ToLower();
                        var opinionWord = new OpinionWord(tempWord, WordOrientation)
                        {
                            OpWord      = tempWord,
                            Orientation = WordOrientation
                        };
                        var position = i;
                        Target = GetOpinionWordTarget(tempWord, position, sentence);
                        if (OpinionTargetList.Contains(Target))
                        {
                            tempWord = GetDoublePropagationOpinionWord(tempWord, position, sentence);
                            if ((PositiveWords.Contains(tempWord) || NegativeWords.Contains(tempWord)) &&
                                tempWord != null)
                            {
                                WordOrientation = GetOpinionWordOrientation(tempWord, position, sentence);

                                if (!OpinionLexicon.Contains(tempWord))
                                {
                                    DoublePropagationList.Add(new OpinionWord(opinionWord.OpWord,
                                                                              opinionWord.Orientation));
                                }
                            }
                            else
                            {
                                if (tempWord != null)
                                {
                                    DoublePropagationList.Add(new OpinionWord(tempWord, opinionWord.Orientation));
                                }
                            }
                        }
                    }
                    SentenceIndex++;
                }
                PositionOfReview++;
            }

            return(DoublePropagationList);
        }
Beispiel #3
0
        //Filter seed extraction process 100%
        protected List <OpinionWord> ExtractFilteredSeedOpinionWords()
        {
            FillPositiveWords();
            FillNegativeWords();
            Lexicon();
            PositionOfReview = 0;
            FilteredSeed     = new List <OpinionWord>();
            foreach (var opinion in Opinions)
            {
                SentenceIndex     = 0;
                SentencesInReview = SentencesSeparator(SentencesInReview, PositionOfReview);
                foreach (var sentence in SentencesInReview)
                {
                    WordsInSentence = EachWordInSentence(WordsInSentence, SentencesInReview, SentenceIndex);
                    var i = -1;
                    foreach (var word in WordsInSentence)
                    {
                        i++;
                        var tempWord    = word.ToLower();
                        var opinionWord = new OpinionWord(tempWord, WordOrientation)
                        {
                            OpWord      = tempWord,
                            Orientation = WordOrientation
                        };
                        if (PositiveWords.Contains(tempWord) || NegativeWords.Contains(tempWord))
                        {
                            var position = i;
                            WordOrientation = GetOpinionWordOrientation(tempWord, position, sentence);

                            if (!OpinionLexicon.Contains(tempWord))
                            {
                                FilteredSeed.Add(new OpinionWord(tempWord, WordOrientation)
                                {
                                    OpWord = tempWord, Orientation = WordOrientation
                                });
                            }
                            else
                            {
                                FilteredSeed.Add(opinionWord);
                            }//in documentation says that we have to add only oriantation..how to implement that?
                        }
                    }

                    SentenceIndex++;
                    Array.Clear(WordsInSentence, 0, WordsInSentence.Length);
                }

                PositionOfReview++;
            }

            return(FilteredSeed);
        }
Beispiel #4
0
        public void ProcessItem(Post item)
        {
            string content = item.Content.ToLower();

            foreach (var ignoreChar in IgnoreChars)
            {
                content = content.Replace(ignoreChar, " ");
            }
            var cantNeg = NegativeWords.Count(word => content.Contains(" " + word + " "));
            var cantPos = PositiveWords.Count(word => content.Contains(word));

            item.Sentiment = SentimentNeutral;
            if (cantNeg > 0)
            {
                item.Sentiment = SentimentNegative;
            }
            if (cantPos > 0)
            {
                item.Sentiment = SentimentPositive;
            }
            if (cantNeg > 0 && cantPos > 0)
            {
                item.Sentiment = SentimentNeutral;
            }

            if (item.Sentiment == SentimentNegative)
            {
                _negativeCount++;
            }
            if (item.Sentiment == SentimentPositive)
            {
                _positiveCount++;
            }
            if (item.Sentiment == SentimentNeutral)
            {
                _neutralCount++;
            }
        }
Beispiel #5
0
        //Conjunction based extraction process 90%

        protected List <OpinionWord> ExtractConjunctionBasedOpinionWords()
        {
            FillPositiveWords();
            FillNegativeWords();
            PositionOfReview = 0;
            SentenceIndex    = 0;
            ConjunctionList  = new List <OpinionWord>();
            foreach (var Opinion in Opinions)
            {
                SentenceIndex     = 0;
                SentencesInReview = SentencesSeparator(SentencesInReview, PositionOfReview);
                foreach (var sentence in SentencesInReview)
                {
                    WordsInSentence = EachWordInSentence(WordsInSentence, SentencesInReview, SentenceIndex);
                    var i = -1;
                    foreach (var word in WordsInSentence)
                    {
                        i++;
                        var tempWord    = word.ToLower();
                        var position    = i;
                        var opinionWord = new OpinionWord(tempWord, WordOrientation)
                        {
                            OpWord      = tempWord,
                            Orientation = WordOrientation
                        };
                        //check if the opinion word is included in filteredSeed list
                        var matches = FilteredSeed.Find(Didaxto => opinionWord.OpWord == tempWord);
                        // var matches = FilteredSeed.Where(OpinionWord => OpinionWord.OpWord == tempWord);
                        if (FilteredSeed.Contains(matches)) //matches.OfType<OpinionWord>().Equals(opinionWord)
                        {
                            if (position + 1 < WordsInSentence.Length)
                            {
                                if (Conjunctions.Contains(WordsInSentence[position + 1]))
                                {
                                    tempWord = GetConjunctionBaseOpinionWord(tempWord, position, sentence);
                                    {
                                        if (PositiveWords.Contains(tempWord) || NegativeWords.Contains(tempWord))
                                        {
                                            WordOrientation = GetOpinionWordOrientation(tempWord, position, sentence);
                                            if (!OpinionLexicon.Contains(tempWord))
                                            {
                                                ConjunctionList.Add(new OpinionWord(tempWord, WordOrientation)
                                                {
                                                    OpWord = tempWord, Orientation = WordOrientation
                                                });
                                            }
                                            else
                                            {
                                                ConjunctionList.Add(new OpinionWord(tempWord, opinionWord.Orientation));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                SentenceIndex++;
                Array.Clear(WordsInSentence, 0, WordsInSentence.Length);
            }

            PositionOfReview++;

            return(ConjunctionList);
        }
Beispiel #6
0
        //Orientation=> if pos = true else false 80%
        protected bool GetOpinionWordOrientation(string word, int position, string sentence)
        {
            FillPositiveWords();
            FillNegativeWords();
            FillAdverbs();
            FillComparatives();
            FillConjunctions();
            FillDecreasers();
            FillFutureWords();
            FillIncreasers();
            FillVerbs();
            FillNegations();
            //{pos}
            if (PositiveWords.Contains(word))
            {
                WordOrientation = true;
            }

            if (NegativeWords.Contains(word))
            {
                WordOrientation = false;
            }

            if (position != 0)
            {
                //{pos} {pos}
                if (PositiveWords.Contains(WordsInSentence[position - 1]))
                {
                    WordOrientation = true;
                }

                //{neg} {pos}
                if (NegativeWords.Contains(WordsInSentence[position - 1]))
                {
                    WordOrientation = false;
                }

                if (position >= 2)
                {
                    //{fut} {verb} {pos}
                    if (FutureWords.Contains(WordsInSentence[position - 2]) &&
                        Verbs.Contains(WordsInSentence[position - 1]) &&
                        PositiveWords.Contains(WordsInSentence[position]))
                    {
                        WordOrientation = true;
                    }

                    //{pos} {neg}
                    if (PositiveWords.Contains(WordsInSentence[position - 1]) &&
                        NegativeWords.Contains(WordsInSentence[position]))
                    {
                        WordOrientation = false;
                    }

                    //{decr} {comp} {pos}
                    if (Decreasers.Contains(WordsInSentence[position - 2]) && Comparatives.Contains(
                            WordsInSentence[position - 1]) &&
                        PositiveWords.Contains(
                            WordsInSentence[position]))
                    {
                        WordOrientation = true;
                    }

                    if (position >= 3)
                    {
                        //{pos} {conj} {nego} {cpos}
                        if (PositiveWords.Contains(WordsInSentence[position - 3]) && Conjunctions.Contains(
                                WordsInSentence[position - 2]) &&
                            Negations.Contains(
                                WordsInSentence[position - 1]) &&
                            PositiveWords.Contains(
                                WordsInSentence[position]))
                        {
                            WordOrientation = true;
                        }

                        //{neg} {conj} {incr} {cneg}
                        if (NegativeWords.Contains(WordsInSentence[position - 3]) && Conjunctions.Contains(
                                WordsInSentence[position - 2]) &&
                            Increasers.Contains(
                                WordsInSentence[position - 1]) &&
                            NegativeWords.Contains(
                                WordsInSentence[position]))
                        {
                            WordOrientation = false;
                        }
                    }
                }
            }

            return(WordOrientation);
        }