public async Task NgramSentiment() { ActualWordsHandler.InstanceOpen.Container.Context.DisableFeatureSentiment = true; var words = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Adjustment/words.csv"); ISentimentDataHolder lexicon = SentimentDataHolder.Load(words); var loader = SentimentDataHolder.Load(new[] { "veto it really" }.Select(item => new WordSentimentValueData( item, new SentimentValueData(2)))); lexicon.Merge(loader); var text = "I Veto it really"; var result = await ActualWordsHandler.InstanceOpen.TextSplitter.Process(new ParseRequest(text)).ConfigureAwait(false); var document = result.Construct(ActualWordsHandler.InstanceOpen.WordFactory); ActualWordsHandler.InstanceOpen.Container.Context.Lexicon = lexicon; Text.Data.IParsedReview review = ActualWordsHandler.InstanceOpen.Container.Resolve <Func <Document, IParsedReviewManager> >()(document).Create(); Assert.AreEqual(1, review.CalculateRawRating().StarsRating); ActualWordsHandler.InstanceOpen.Container.Context.NGram = 3; review = ActualWordsHandler.InstanceOpen.Container.Resolve <Func <Document, IParsedReviewManager> >()(document).Create(); Assert.AreEqual(5, review.CalculateRawRating().StarsRating); IRatingAdjustment adjustment = RatingAdjustment.Create(review, null); var resultDocument = new DocumentFromReviewFactory(ActualWordsHandler.InstanceOpen.Container.Resolve <INRCDictionary>()).ReparseDocument(adjustment); Assert.AreEqual(5, resultDocument.Stars); Assert.AreEqual("I Veto it really", resultDocument.Text); }
public async Task TestReview(bool disableInvert) { var txt = "#paulryan #killed #rnc2016 #america #died #wisconsin no more EMOTICON_kissing_heart since you gave up on #trump, you don't represent #us"; var stream = new DictionaryStream(Path.Combine(path, "Library", "Standard", "EmotionLookupTable.txt"), new FileStreamSource()); var data = stream.ReadDataFromStream(double.Parse).ToDictionary(item => item.Word, item => item.Value, StringComparer.OrdinalIgnoreCase); foreach (var item in data.Keys.ToArray().Where(k => !k.StartsWith("EMOTICON"))) { data.Remove(item); } var lexicon = SentimentDataHolder.PopulateEmotionsData(data); ActualWordsHandler.InstanceOpen.Container.Context.DisableInvertors = disableInvert; var result = await ActualWordsHandler.InstanceOpen.TextSplitter.Process(new ParseRequest(txt)).ConfigureAwait(false); var document = result.Construct(ActualWordsHandler.InstanceOpen.WordFactory); ActualWordsHandler.InstanceOpen.Container.Context.Lexicon = lexicon; Text.Data.IParsedReview review = ActualWordsHandler.InstanceOpen.Container.Resolve <Func <Document, IParsedReviewManager> >()(document).Create(); MachineLearning.Mathematics.RatingData ratings = review.CalculateRawRating(); Assert.AreEqual(1, review.Sentences.Count); Assert.AreEqual(disableInvert, ratings.IsPositive); }
public async Task Adjusted() { ActualWordsHandler.InstanceOpen.Container.Context.DisableFeatureSentiment = true; var words = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Adjustment/words.csv"); ISentimentDataHolder lexicon = SentimentDataHolder.Load(words); var text = "I Veto it"; var result = await ActualWordsHandler.InstanceOpen.TextSplitter.Process(new ParseRequest(text)).ConfigureAwait(false); var document = result.Construct(ActualWordsHandler.InstanceOpen.WordFactory); ActualWordsHandler.InstanceOpen.Container.Context.Lexicon = lexicon; Text.Data.IParsedReview review = ActualWordsHandler.InstanceOpen.Container.Resolve <Func <Document, IParsedReviewManager> >()(document).Create(); Assert.AreEqual(1, review.CalculateRawRating().StarsRating); }
public async Task FullSentence() { var text = "Today, this tale based on two Edgar Allen Poe pieces (\"The Fall of the House of Usher\", \"Dance of Death\" (poem) ) is actually quite creepy from beginning to end. It is similar to some of the old black-and-white movies about people that meet in an old decrepit house (for example, \"The Cat and the Canary\", \"The Old Dark House\", \"Night of Terror\" and so on). Boris Karloff plays a demented inventor of life-size dolls that terrorize the guests. He dies early in the film (or does he ? ) and the residents of the house are subjected to a number of terrifying experiences. I won't go into too much detail here, but it is definitely a must-see for fans of old dark house mysteries.<br /><br />Watch it with plenty of popcorn and soda in a darkened room.<br /><br />Dan Basinger 8/10"; var request = await textSplitter.Process(new ParseRequest(text)).ConfigureAwait(false); var document = request.Construct(ActualWordsHandler.InstanceSimple.WordFactory); Text.Data.IParsedReview review = ActualWordsHandler.InstanceOpen.Container.Resolve <Func <Document, IParsedReviewManager> >()(document) .Create(); Assert.AreEqual(1, (int)review.CalculateRawRating().StarsRating); Assert.AreEqual(10, document.Words.Count(item => item.EntityType != NamedEntities.None)); }
public async Task TestBasic(string text, int rating, int totalSentiments, bool disableInvertor) { ActualWordsHandler.InstanceSimple.Container.Context.DisableFeatureSentiment = disableInvertor; var request = await textSplitter.Process(new ParseRequest(text)).ConfigureAwait(false); var document = request.Construct(ActualWordsHandler.InstanceSimple.WordFactory); Text.Data.IParsedReview review = ActualWordsHandler.InstanceSimple.Container.Resolve <Func <Document, IParsedReviewManager> >()(document).Create(); Assert.AreEqual(rating, (int)review.CalculateRawRating().StarsRating); SentimentValue[] sentiments = review.GetAllSentiments(); Assert.AreEqual(totalSentiments, sentiments.Length); IRatingAdjustment adjustment = RatingAdjustment.Create(review, new NullMachineSentiment()); Assert.AreEqual(rating, (int)adjustment.Rating.StarsRating); }