public static SentimentDataHolder PopulateEmotionsData(Dictionary <string, double> data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            var instance = new SentimentDataHolder();

            foreach (var item in data)
            {
                var value = new SentimentValueData(item.Value);
                if (item.Key[item.Key.Length - 1] == '*')
                {
                    var word = item.Key.Substring(0, item.Key.Length - 1);
                    instance.SetValue(word, value);
                    if (word.Length > 4)
                    {
                        instance.EmotionsLookup.Add(string.Intern(word), value);
                    }
                }
                else
                {
                    instance.SetValue(item.Key, value);
                }
            }

            return(instance);
        }
        private void AddSentimentValue(string word, SentimentValueData value)
        {
            if (EmotionsTable.ContainsKey(word))
            {
                return;
            }

            EmotionsTable[string.Intern(word)] = value;
        }
Beispiel #3
0
        public static SentimentDataHolder PopulateEmotionsData(Dictionary <string, double> data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            var instance = new SentimentDataHolder();

            foreach (var item in data)
            {
                var value = new SentimentValueData(item.Value);
                if (!SetMasked(item.Key, instance, value))
                {
                    instance.SetValue(new WordSentimentValueData(item.Key, value));
                }
            }

            return(instance);
        }
Beispiel #4
0
        private static bool SetMasked(string wordMask, SentimentDataHolder instance, SentimentValueData value)
        {
            if (wordMask[wordMask.Length - 1] != '*')
            {
                return(false);
            }

            var word = string.Intern(wordMask.Substring(0, wordMask.Length - 1));

            instance.SetValue(new WordSentimentValueData(word, value));
            if (word.Length > 4)
            {
                instance.EmotionsLookup.Add(word, value);
            }
            else
            {
                logger.LogWarning("Ignoring masked {0} as it is too short", word);
            }

            return(true);
        }
 private void SetValue(string word, SentimentValueData value)
 {
     EmotionsTable.Remove(word);
     AddSentimentValue(word, value);
 }
Beispiel #6
0
 public WordSentimentValueData(string word, SentimentValueData data)
 {
     Word = word ?? throw new System.ArgumentNullException(nameof(word));
     Data = data ?? throw new System.ArgumentNullException(nameof(data));
 }