public void AddItem(IWordItem item) { if (item == null) { return; } if (!item.IsSimple) { throw new ProcessingException("Can add only simple word item type"); } if (item.IsSimpleConjunction()) { return; } if (items.Count > 0) { var previous = items[items.Count - 1]; item.Relationship.Previous = previous; previous.Relationship.Next = item; } items.Add(item); if (item.Parent != null) { item.Parent.Relationship.Part = this; } item.Relationship.Part = this; AddRelationship(item); windowItems.Add(item, item); windowItems.Increment(); }
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")); }