Ejemplo n.º 1
0
        public void Test_First_Get_Learn_State()
        {
            var initSentences = new[]
            { new Sentence("hate", WordCategory.Negative), new Sentence("love", WordCategory.Positive) };
            var learningService = LearningService.WithCacheService(new CacheServiceForTests()).WithLearner(new TweetLearner()).WithSentences(initSentences).Build();
            var learnerState    = learningService.Get();

            learnerState.Should().NotBeNull();
            learnerState.WordPerQuantity.Keys.Count().Should().Be(2);
            learnerState.CategoryPerQuantity.Keys.Count().Should().Be(2);
        }
        public void Test_Classifier_With_Many_Tweets_When_All_Tweets_Are_Positive()
        {
            var initSentences = new[]
            { new Sentence("hate", WordCategory.Negative), new Sentence("love", WordCategory.Positive) };
            var learningService = LearningService.WithCacheService(new CacheServiceForTests()).WithLearner(new TweetLearner()).WithSentences(initSentences).Build();

            var service = new BayesAnalysisService(learningService, new TweetClassifier());

            var testResult = service.Analyze(Enumerable.Range(0, 10000).Select(x => new Tweet
            {
                Text = "love and sun"
            }).ToList());

            testResult.IsSuccess.Should().BeTrue();
            testResult.Value.First().Sentiment.Should().Be(WordCategory.Positive);
        }
        public async Task Test_Async_Classifier_With_Many_Tweets_When_All_Tweets_Are_Positive()
        {
            var testClassifier = A(TestLearnState().WithSentence(ImmutableDictionary <string, int> .Empty.Add("f**k", -1).Add("love", 4).Add("suck", -5).Add("sun", 5)));
            var initSentences  = new[]
            { new Sentence("hate", WordCategory.Negative), new Sentence("love", WordCategory.Positive) };
            var learningService = LearningService.WithCacheService(new CacheServiceForTests()).WithLearner(new TweetLearner()).WithSentences(initSentences).Build();

            var service = new BayesAnalysisService(learningService, new TweetClassifier());

            var testResult = await service.AnalyzeAsync(Enumerable.Range(0, 10000).Select(x => new Tweet
            {
                Text = "love and sun"
            }).ToList());

            testResult.IsSuccess.Should().BeTrue();
            testResult.Value.First().Sentiment.Should().Be(WordCategory.Positive);
        }
        public async Task Test_Async_Classifier_When_All_Tweets_Are_Negative()
        {
            var initSentences = new[]
            { new Sentence("hate", WordCategory.Negative), new Sentence("love", WordCategory.Positive) };
            var learningService = LearningService.WithCacheService(new CacheServiceForTests()).WithLearner(new TweetLearner()).WithSentences(initSentences).Build();

            var service    = new BayesAnalysisService(learningService, new TweetClassifier());
            var testResult = await service.AnalyzeAsync(new List <Tweet>
            {
                new Tweet
                {
                    Text = "f**k and suck"
                }
            });

            testResult.IsSuccess.Should().BeTrue();
            testResult.Value.First().Sentiment.Should().Be(WordCategory.Negative);
        }