示例#1
0
        /// <summary>
        /// Calculates Inclusion Value
        /// </summary>
        /// <returns>
        /// Returns value from -1 to 1
        /// </returns>
        public static double CalculateInclusion(EmotionState info, double incl, double excl, double syntax_value)
        {
            double result = 0;

            if (incl + excl == 0)
            {
                //if there is no familiar inclusivity words in sentence
                //we should export some value from emotions and sentiment value to not export zero result

                if (info.Sentiment > 0)
                {
                    result = 0.1 * info.Sentiment + syntax_value;
                }
                else
                {
                    result = 0.1 * info.Sentiment - syntax_value;
                }
                return(result);
            }
            if (incl >= excl)
            {
                result = CustomPowerfunction(0.9, (incl - excl + 1)) + syntax_value;
                return(result);
            }
            else
            {
                result = CustomPowerfunction(0.9, (excl - incl + 1)) + syntax_value;
                return(-result);
            }
        }
示例#2
0
        /// <summary>
        /// Analyses <see cref="text"/> data
        /// </summary>
        /// <param name="text">
        /// actual text which should be analyzed
        /// </param>
        /// <returns>
        /// The <see cref="EmotionState"/> type variable is the result of this analyze
        /// which stores all the values being analyzed
        /// </returns>
        public EmotionState DoAnalysis(string text)
        {
            //count speech parts
            string[] tokens = Library.tokenizer.Tokenize(text); //divide sentence into words
            for (int j = 1; j < tokens.Count(); j++)
            {
                if (tokens[j - 1] == ":" && tokens[j].Length <= 3)
                {
                    tokens[j] = ":" + tokens[j];
                }
            }
            string[] tags = Library.posTagger.Tag(tokens);       //and also get for each word what speech part it is

            EmotionState result = AnalyseSentence(tokens, tags); //merge each result for each sentence to get final result

            return(result);
        }
示例#3
0
        /// <summary>
        /// Calculates Emotion Values
        /// </summary>
        /// <returns>
        /// Fills values of emotion types in info variable.
        /// Values are from 0 to 1.
        /// </returns>
        public static EmotionState CalculateEmotions(EmotionState info, double syntax_value)
        {
            //about joy
            // 30% sentiment value, 60% already collected info.joy , 10% syntax value
            info.Joy = Math.Max(syntax_value, 0.3 * info.Sentiment + CustomPowerfunction(0.6, info.Joy) + syntax_value);

            //about sadnass
            // 40% sentiment value, 50% already collected info.joy , 10% syntax value
            info.Sadness = Math.Max(syntax_value, -0.4 * info.Sentiment + CustomPowerfunction(0.5, info.Joy) + syntax_value);

            //about disgust
            // 25% sentiment value, 65% already collected info.joy , 10% syntax value
            info.Disgust = Math.Max(syntax_value, -0.25 * info.Sentiment + CustomPowerfunction(0.65, info.Joy) + syntax_value);

            //about fear
            // 20% sentiment value, 70% already collected info.joy , 10% syntax value
            info.Fear = Math.Max(syntax_value, -0.20 * info.Sentiment + CustomPowerfunction(0.50, info.Joy) + syntax_value);

            //about anger
            // 30% sentiment value, 60% already collected info.joy , 10% syntax value
            info.Anger = Math.Max(syntax_value, -0.30 * info.Sentiment + CustomPowerfunction(0.60, info.Joy) + syntax_value);
            return(info);
        }
示例#4
0
        /// <summary>
        /// Calculates Sentiment Values
        /// </summary>
        /// <returns>
        /// Value from -1 to 1
        /// </returns>
        public static double CalculateSentiment(EmotionState info, double pos, double neg, double incl, double excl, double syntax_value)
        {
            if (pos == 0 && neg == 0 && incl == 0 && excl == 0 && info.Joy + info.Fear + info.Disgust + info.Sadness + info.Anger == 0)
            {
                //this means absolutily nothing is familiar in text,then
                //we are calculating sentiment syntax
                info.Sentiment = syntax_value;
                return(info.Sentiment);
            }
            double result = 0;

            if (pos >= neg)  //if positive is greater then negative,it includes emotions and inclusivity
            {
                //this means sentiment is positive,
                result = CustomPowerfunction(0.9, (pos - neg + 1)) + syntax_value;
                return(result);
            }
            else
            {
                result = CustomPowerfunction(0.9, (neg - pos + 1)) + syntax_value;
                return(-result);
                //so if it comes here it means sentiment is negative
            }
        }
示例#5
0
        /// <summary>
        /// Analyze each tokens with speech parts
        /// </summary>
        private EmotionState AnalyseSentence(string[] words, string[] parts)
        {
            EmotionState Result = new EmotionState(); //calc is the total emotion and sentiment values of each words

            //here we are collecting info from emotion data
            foreach (string word in words)
            {
                double coeff = word == HelperMethods.ToLowRegistry(word) ? 1 : high_capital_factor;

                int[] values = null;
                if (Library.IsEmotionsAvaliable(word))
                {
                    values = Library.GetEmotions(word);
                }
                if (values != null)
                {
                    //increase values of each thing
                    Result.Anger   += values[0] * coeff;
                    Result.Disgust += values[1] * coeff;
                    Result.Fear    += values[2] * coeff;
                    Result.Joy     += values[3] * coeff;
                    Result.Sadness += values[4] * coeff;
                }
            }

            double incl_val = 0, excl_val = 0;

            foreach (string word in words)
            {
                double coeff = word == HelperMethods.ToLowRegistry(word) ? 1 : high_capital_factor;

                if (Library.GetInclusionValue(word) > 0)
                {
                    incl_val += 1 * coeff;
                }

                if (Library.GetExclusionValue(word) > 0)
                {
                    excl_val += 1 * coeff;
                }
            }

            double pos_val = Result.Joy + incl_val;
            double neg_val = excl_val + Result.Disgust + Result.Sadness + Result.Fear + Result.Anger;

            //lets translate emotions into positive and negative values, only joy is positive others are negative

            //here we are collecting results from positive and negative data
            foreach (string word in words)
            {
                double coeff = word == HelperMethods.ToLowRegistry(word) ? 1 : high_capital_factor;

                if (Library.IsPositive(word))
                {
                    pos_val += 1 * coeff;
                }
                if (Library.IsNegative(word))
                {
                    neg_val += 1 * coeff;
                }
            }

            //now we have collected anger,fear,sadness,joy,disgust pos_val,neg_val  incl_val,excl_val

            //before summarise we have to calculate syntax value
            double syntax_value = MathAnalyzer.SyntaxValue(parts); //syntax value is a little point here

            //but improtant its range is from 0 to 0.1

            Result.Sentiment = MathAnalyzer.CalculateSentiment(Result, pos_val, neg_val, incl_val, excl_val, syntax_value); //calculating sentiment

            Result = MathAnalyzer.CalculateEmotions(Result, syntax_value);                                                  //calculating emotions
            //it is improtant that before running you already have calculatid sentiment

            Result.Inclusion = MathAnalyzer.CalculateInclusion(Result, incl_val, excl_val, syntax_value);

            //rounding values
            Result.Sentiment = Math.Round(Result.Sentiment, 2);
            Result.Fear      = Math.Round(Result.Fear, 2);
            Result.Disgust   = Math.Round(Result.Disgust, 2);
            Result.Anger     = Math.Round(Result.Anger, 2);
            Result.Sadness   = Math.Round(Result.Sadness, 2);
            Result.Joy       = Math.Round(Result.Joy, 2);
            Result.Inclusion = Math.Round(Result.Inclusion, 2);

            //return result
            return(Result);
        }