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);
        }
        public static ISentimentDataHolder Load(IEnumerable <WordSentimentValueData> reader)
        {
            var holder = new SentimentDataHolder();

            foreach (var valueData in reader)
            {
                holder.SetValue(valueData.Word, valueData.Data);
            }

            return(holder);
        }
Пример #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);
        }
Пример #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);
        }