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 void Load() { if (loaded) { throw new InvalidOperationException(); } loaded = true; booster = ReadTextData("BoosterWordList.txt"); negating = ReadTextData("NegatingWordList.txt"); question = ReadTextData("QuestionWords.txt"); stopWords = ReadTextData("StopWords.txt"); stopPos = ReadTextData("StopPos.txt"); var emotions = ReadTextData("EmotionLookupTable.txt"); foreach (var sentiment in extended.GetSentiments()) { if (!emotions.ContainsKey(sentiment.Word)) { emotions[sentiment.Word] = sentiment.Sentiment; } } sentimentData = SentimentDataHolder.PopulateEmotionsData(emotions); ReadRepairRules(); }
public static ISentimentDataHolder Load(IEnumerable <WordSentimentValueData> reader) { var holder = new SentimentDataHolder(); foreach (var valueData in reader) { holder.SetValue(valueData.Word, valueData.Data); } return(holder); }
public void Load(string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentException("Value cannot be null or empty.", nameof(path)); } logger.LogInformation("Loading lexicons: {0}", path); table = new Dictionary <string, ISentimentDataHolder>(StringComparer.OrdinalIgnoreCase); foreach (var file in Directory.GetFiles(path)) { var name = Path.GetFileNameWithoutExtension(file); var holder = SentimentDataHolder.Load(file); table[name] = holder; } logger.LogInformation("Loaded {0} lexicons", table.Count); }
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); }
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); }
public void Load() { if (string.IsNullOrEmpty(config?.Lexicons?.Local)) { logger.LogWarning("Lexicons not found"); return; } var path = config.GetFullPath(item => item.Lexicons); logger.LogInformation("Loading lexicons: {0}", path); table = new Dictionary <string, ISentimentDataHolder>(StringComparer.OrdinalIgnoreCase); foreach (var file in Directory.GetFiles(path)) { var name = Path.GetFileNameWithoutExtension(file); var holder = SentimentDataHolder.Load(file); table[name] = holder; } logger.LogInformation("Loaded {0} lexicons", table.Count); }