예제 #1
0
 public LearningServiceTestBase()
 {
     UnitOfWork = new ListUnitOfWork(new ListRepository <Category>(), new ListRepository <Flashcard>(),
                                     new ListRepository <User>(), new ListRepository <UserProgress>());
     Options = new LearningServiceOptions();
     Service = new LearningService(UnitOfWork, new OptionsWrapper <LearningServiceOptions>(Options));
 }
예제 #2
0
 private void StartLearning()
 {
     learningService = mContr.GetLearningService();
     this.Controls.Add(GetShowWordPanel());
     ShowNextWordButton_Click(null, null);
     GetNextButton().Click += ShowNextWordButton_Click;
 }
예제 #3
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);
        }
예제 #4
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Put serial ports to combobox
            SerialPortsBox.ItemsSource   = SerialPort.GetPortNames();
            SerialPortsBox.SelectedIndex = 0;

            // Creating Learning Service
            _learningService = new LearningService(this.DataContext as MainViewModel);

            // Error Graph Initialization
            ErrorGraph.PlotY(new double[] { 0 });
        }
        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);
        }
예제 #8
0
        public void LearningStatus_Should_Show_Results()
        {
            var numberOfQuestions = 10;
            var questions         = MockFactory.CreateEmptyTestQuestions(numberOfQuestions);
            var learningService   = new LearningService();

            var result          = learningService.SetupAndGetFirstQuestion(questions);
            var currentQuestion = result.NextQuestion;

            result.Status.New.Should().Be(10);
            result.Status.Learning.Should().Be(0);
            result.Status.Memorized.Should().Be(0);
            result.Status.IsAnythingToLearn.Should().BeTrue();

            // answering 'Again' and 'Memorized' alternately
            for (var i = 1; i <= 10; i++)
            {
                var validationResult = i.IsOdd() ? QuestionResult.Again : QuestionResult.Memorized;
                result = learningService.ProcessResultAndGetNextQuestion(currentQuestion, validationResult);
            }

            result.Status.New.Should().Be(0);
            result.Status.Learning.Should().Be(5);
            result.Status.Memorized.Should().Be(5);
            result.Status.IsAnythingToLearn.Should().BeTrue();

            // answering 'Memorized'
            for (var i = 1; i <= 5; i++)
            {
                result = learningService.ProcessResultAndGetNextQuestion(currentQuestion, QuestionResult.Memorized);
            }

            result.Status.New.Should().Be(0);
            result.Status.Learning.Should().Be(0);
            result.Status.Memorized.Should().Be(10);
            result.Status.IsAnythingToLearn.Should().BeFalse();
        }
예제 #9
0
 public LearnCommand(TelegramService telegramService, LearningService learningService)
 {
     _telegramService = telegramService;
     _learningService = learningService;
 }
예제 #10
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _telegramService = new TelegramService(context);

            var message = _telegramService.Message;

            _learningService = new LearningService(message);

            if (!_telegramService.IsSudoer())
            {
                Log.Information("This user is not sudoer");
                return;
            }

            if (message.ReplyToMessage != null)
            {
                var repMessage = message.ReplyToMessage;
                var repText    = repMessage.Text ?? repMessage.Caption;
                var param      = message.Text.SplitText(" ").ToArray();
                var mark       = param.ValueOfIndex(1);
                var opts       = new List <string>()
                {
                    "spam", "ham"
                };

                if (!opts.Contains(mark))
                {
                    await _telegramService.SendTextAsync("Spesifikasikan spam atau ham (bukan spam)")
                    .ConfigureAwait(false);

                    return;
                }

                await _telegramService.SendTextAsync("Sedang memperlajari pesan")
                .ConfigureAwait(false);

                var learnData = new LearnData()
                {
                    Message = repText.Replace("\n", " "),
                    Label   = mark
                };

                if (LearningService.IsExist(learnData))
                {
                    Log.Information("This message has learned");
                    await _telegramService.EditAsync("Pesan ini mungkin sudah di tambahkan.")
                    .ConfigureAwait(false);

                    return;
                }

                await _learningService.Save(learnData).ConfigureAwait(false);

                await _telegramService.EditAsync("Memperbarui local dataset")
                .ConfigureAwait(false);

                // MachineLearning.WriteToCsv();

                await _telegramService.EditAsync("Sedang mempelajari dataset")
                .ConfigureAwait(false);

                await MachineLearning.SetupEngineAsync().ConfigureAwait(false);

                // BackgroundJob.Enqueue(() => LearningHelper.SetupEngine());

                await _telegramService.EditAsync("Pesan berhasil di tambahkan ke Dataset")
                .ConfigureAwait(false);

                return;
            }
            else
            {
                await _telegramService.SendTextAsync("Sedang mempelajari dataset")
                .ConfigureAwait(false);

                await MachineLearning.SetupEngineAsync()
                .ConfigureAwait(false);

                await _telegramService.EditAsync("Training selesai")
                .ConfigureAwait(false);

                return;
            }

            await _telegramService.SendTextAsync("Balas pesan yang ingin di pelajari")
            .ConfigureAwait(false);
        }