public void ReparseDocument() { review.Setup(item => item.Text).Returns("DataRow"); var words = new List <TestWordItem>(); var sentences = new List <Mock <ISentence> >(); sentences.Add(new Mock <ISentence>()); sentences.Add(new Mock <ISentence>()); foreach (var sentence in sentences) { sentence.Setup(item => item.Text).Returns("Sentence"); var currentWords = new List <TestWordItem>(); for (var i = 0; i < 2; i++) { var wordItem = new TestWordItem(); wordItem.Text = "Word"; wordItem.Relationship = new TestWordItemRelationship(); wordItem.Relationship.Sentiment = new SentimentValue(wordItem, i + 1); currentWords.Add(wordItem); words.Add(wordItem); } sentence.Setup(item => item.Occurrences).Returns(currentWords.ToArray()); } var adjustment = new Mock <IRatingAdjustment>(); var rating = new RatingData(); rating.AddPositive(2); adjustment.Setup(item => item.Rating) .Returns(rating); for (var i = 0; i < words.Count; i++) { var word = words[i]; adjustment.Setup(item => item.GetSentiment(word)).Returns(new SentimentValue(word, 10)); } review.Setup(item => item.Sentences).Returns(sentences.Select(item => item.Object).ToList()); adjustment.Setup(item => item.Review).Returns(review.Object); review.Setup(item => item.Document).Returns(new Document("Test")); var document = new DocumentFromReviewFactory().ReparseDocument(adjustment.Object); Assert.AreEqual(2, document.Sentences.Count); foreach (var sentenceItem in document.Sentences) { Assert.AreEqual(2, sentenceItem.Words.Count); Assert.AreEqual("Sentence", sentenceItem.Text); for (var i = 0; i < sentenceItem.Words.Count; i++) { Assert.AreEqual(i + 1, sentenceItem.Words[i].Value); Assert.AreEqual(10, sentenceItem.Words[i].CalculatedValue); } } Assert.AreEqual("Test", document.Text); Assert.IsTrue(document.GetPositivity() == PositivityType.Positive); }
public static void AddSentiment(this RatingData instance, SentimentValueData data) { if (data.IsPositive) { instance.AddPositive(Math.Abs(data.Value)); } else { instance.AddNegative(Math.Abs(data.Value)); } }