コード例 #1
0
        public int Classify(string text)
        {
            Lemmatizer.Stopwords = _stopwords;
            var vector = Lemmatizer.LemmatizeCurrentText(text);
            int sign = 1, tone = 0, toneCount = 0;

            for (int i = 0; i < vector.Count; i++)
            {
                if (_sentilex.ContainsKey(vector[i]) || _specificLexicon.ContainsKey(vector[i]))
                {
                    int basictone = (_specificLexicon.ContainsKey(vector[i])) ? _specificLexicon[vector[i]] : _sentilex[vector[i]];
                    if (i - 1 > 0)
                    {
                        if (_negations.Contains(vector[i - 1]))
                        {
                            sign = -1;
                        }
                        if (_gains.Contains(vector[i - 1]))
                        {
                            if (i - 2 > 0 && _negations.Contains(vector[i - 2]))
                            {
                                sign = -1;
                            }
                        }
                    }
                    tone += basictone * sign;
                    toneCount++;
                }
            }
            if (toneCount > 0)
            {
                var doubletone = tone / (toneCount + 0.0);
                if (doubletone > 0.3)
                {
                    return(1);
                }
                else if (doubletone < -0.3)
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                return(0);
            }
        }
コード例 #2
0
        public void parse(string inputString, int emotion)
        {
            var lemmatizer = new Lemmatizer();

            this.emotion = emotion;
            StringReader input    = new StringReader(inputString);
            var          vector   = Lemmatizer.LemmatizeCurrentText(inputString);
            string       prevWord = null;

            foreach (var str in vector)
            {
                addGramm(str);
                if (prevWord != null)
                {
                    addGramm(prevWord + " " + str);
                }
                prevWord = str;
            }
        }