public void Process(Document document) { if (document is null) { throw new ArgumentNullException(nameof(document)); } var table = new AutoEvictingDictionary <WordEx, WordsContext>(length: WindowSize); var sentences = new AutoEvictingDictionary <SentenceItem, SentenceItem>(length: WindowSize); foreach (SentenceItem sentenceItem in document.Sentences) { table.Increment(); sentences.Increment(); sentences.Add(sentenceItem, sentenceItem); foreach (WordEx word in sentenceItem.Words) { WordsContext current = GetVector(word).CreateNewVector(); current.SentimentValue = sentences.Values.Select(item => item.CalculateSentiment().RawRating).Where(item => item.HasValue).Select(item => item.Value).Sum(); foreach (WordsContext addedRecords in table.Values) { addedRecords.AddContext(word); current.AddContext(addedRecords.Word); } table[word] = current; } } }
public void Test() { var dictionary = new AutoEvictingDictionary <string, string>(StringComparer.OrdinalIgnoreCase, 2); dictionary.Add("Test", "DataValue"); Assert.AreEqual("DataValue", dictionary.Get("Test")); Assert.AreEqual("DataValue", dictionary.Get("test")); dictionary.Increment(); Assert.AreEqual("DataValue", dictionary.Get("Test")); dictionary.Increment(); Assert.AreEqual(null, dictionary.Get("Test")); }
public void TestDefault() { var dictionary = new AutoEvictingDictionary <string, string>(); dictionary.Add("Test", "DataValue"); Assert.AreEqual("DataValue", dictionary.Get("Test")); Assert.AreEqual(null, dictionary.Get("test")); dictionary.Increment(); dictionary.Increment(); dictionary.Increment(); Assert.AreEqual("DataValue", dictionary.Get("Test")); dictionary.Increment(); Assert.AreEqual(null, dictionary.Get("Test")); }
public void AddSame() { var dictionary = new AutoEvictingDictionary <int, string>(); dictionary[1] = "Test"; Assert.AreEqual("Test", dictionary[1]); dictionary.Increment(); dictionary.Increment(); Assert.AreEqual("Test", dictionary[1]); dictionary[1] = "Test"; dictionary.Increment(); dictionary.Increment(); Assert.AreEqual("Test", dictionary[1]); dictionary.Increment(); Assert.AreEqual("Test", dictionary[1]); dictionary.Increment(); Assert.AreEqual(null, dictionary[1]); }
public SentencePart(ISentence sentence, ISentencePart previous) { windowItems = new AutoEvictingDictionary <IWordItem, IWordItem>(length: sentence.Review.Context.NGram); Sentence = sentence; Previous = previous; }