コード例 #1
0
        public async Task FullSentence()
        {
            var text = "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";

            ActualWordsHandler.InstanceSimple.Container.Context.DisableFeatureSentiment = true;
            ActualWordsHandler.InstanceSimple.Container.Context.DisableInvertors        = true;

            string[] positiveAdj = { "good", "lovely", "excellent", "delightful", "perfect" };
            string[] negativeAdj = { "bad", "horrible", "poor", "disgusting", "unhappy" };
            var      sentiment   = new Dictionary <string, double>();

            foreach (var item in positiveAdj)
            {
                sentiment[item] = 2;
            }

            foreach (var item in negativeAdj)
            {
                sentiment[item] = -2;
            }

            var adjustment = SentimentDataHolder.PopulateEmotionsData(sentiment);
            var request    = await textSplitter.Process(new ParseRequest(text)).ConfigureAwait(false);

            var document = request.Construct(ActualWordsHandler.InstanceSimple.WordFactory);

            ActualWordsHandler.InstanceSimple.Container.Context.Lexicon = adjustment;
            var review = ActualWordsHandler.InstanceSimple.Container.Resolve <Func <Document, IParsedReviewManager> >()(document).Create();

            Assert.IsNull(review.CalculateRawRating().StarsRating);
            SentimentValue[] sentiments = review.GetAllSentiments();
            Assert.AreEqual(0, sentiments.Length);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void Setup()
        {
            var path = ActualWordsHandler.InstanceSimple.Configuration.GetConfiguration("Resources");

            path = Path.Combine(path, @"Library\Standard");
            var stream = new DictionaryStream(Path.Combine(path, "EmotionLookupTable.txt"), new FileStreamSource());
            var data   = stream.ReadDataFromStream(double.Parse).ToDictionary(item => item.Word, item => item.Value, StringComparer.OrdinalIgnoreCase);

            sentimentData = SentimentDataHolder.PopulateEmotionsData(data);
        }
コード例 #4
0
        public void Setup()
        {
            var loader = new LexiconConfigLoader(ApplicationLogging.LoggerFactory.CreateLogger <LexiconConfigLoader>());
            var config = loader.Load(TestContext.CurrentContext.TestDirectory);
            var path   = config.GetFullPath(item => item.Model);
            var stream = new DictionaryStream(Path.Combine(path, "EmotionLookupTable.txt"), new FileStreamSource());
            var data   = stream.ReadDataFromStream(double.Parse).ToDictionary(item => item.Word, item => item.Value, StringComparer.OrdinalIgnoreCase);

            sentimentData = SentimentDataHolder.PopulateEmotionsData(data);
        }
コード例 #5
0
        public void Adjust(string word, double weight, double sentiment)
        {
            var table = new Dictionary <string, double>();

            table[word]   = weight;
            sentimentData = SentimentDataHolder.PopulateEmotionsData(table);
            Text.Words.IWordItem wordItem    = ActualWordsHandler.InstanceSimple.WordFactory.CreateWord(word, "NN");
            SentimentValue       measurement = sentimentData.MeasureSentiment(wordItem);

            Assert.AreEqual(sentiment, measurement.DataValue.Value);
        }
コード例 #6
0
        public async Task TestCustom(string text, bool useFallback, double?rating)
        {
            var sentiment = new Dictionary <string, double>();

            sentiment["hate"] = 2;
            var adjustment = SentimentDataHolder.PopulateEmotionsData(sentiment);

            ActualWordsHandler.InstanceSimple.Container.Context.UseBuiltInSentiment = useFallback;
            var request = await textSplitter.Process(new ParseRequest(text)).ConfigureAwait(false);

            var document = request.Construct(ActualWordsHandler.InstanceSimple.WordFactory);

            ActualWordsHandler.InstanceSimple.Container.Context.Lexicon = adjustment;
            var review = ActualWordsHandler.InstanceSimple.Container.Resolve <Func <Document, IParsedReviewManager> >()(document).Create();

            Assert.AreEqual(rating, review.CalculateRawRating().StarsRating);
        }