Beispiel #1
0
        public PairModel[] GetPairsForLearning(int count, int maxTranslationSize)
        {
            var fullPairs = _repository.GetWorst(count);

            foreach (var pairModel in fullPairs)
            {
                var translations = pairModel.GetTranslations().ToArray();
                if (translations.Length <= maxTranslationSize)
                {
                    continue;
                }
                var usedTranslations = translations.Randomize().Take(maxTranslationSize).ToArray();
                pairModel.SetTranslations(usedTranslations);
                for (int i = 0; i < pairModel.Phrases.Count; i++)
                {
                    var phrase = pairModel.Phrases[i];
                    if (!usedTranslations.Contains(phrase.Translation))
                    {
                        pairModel.Phrases.RemoveAt(i);
                    }
                }
            }
            return(fullPairs);
        }
Beispiel #2
0
        public void GetWorst10_ReturnsPhrase()
        {
            var repo = new WordsRepository("test");

            repo.ApplyMigrations();
            repo.CreateNew("word", "translation", "trans", new[]
            {
                new Phrase()
                {
                    Created         = DateTime.Now,
                    Origin          = "what is word",
                    OriginWord      = "word",
                    Translation     = "trans is trans",
                    TranslationWord = "trans"
                },
                new Phrase()
                {
                    Created         = DateTime.Now,
                    Origin          = "what is word 2",
                    OriginWord      = "word",
                    Translation     = "trans is trans 2",
                    TranslationWord = "trans"
                },
            });
            repo.CreateNew("word2", "translation2", "trans", new[]
            {
                new Phrase()
                {
                    Created         = DateTime.Now,
                    Origin          = "what is word",
                    OriginWord      = "word2",
                    Translation     = "trans is trans",
                    TranslationWord = "trans2"
                },
                new Phrase()
                {
                    Created         = DateTime.Now,
                    Origin          = "what is word 2",
                    OriginWord      = "word2",
                    Translation     = "trans is trans 2",
                    TranslationWord = "trans2"
                },
            });
            repo.CreateNew("word3", "translation3", "trans", new[]
            {
                new Phrase()
                {
                    Created         = DateTime.Now,
                    Origin          = "what is word",
                    OriginWord      = "word3",
                    Translation     = "trans is trans",
                    TranslationWord = "trans3"
                },
                new Phrase()
                {
                    Created         = DateTime.Now,
                    Origin          = "what is word 3",
                    OriginWord      = "word3",
                    Translation     = "trans is trans 3",
                    TranslationWord = "trans3"
                },
            });
            var words = repo.GetWorst(2);

            Assert.IsNotNull(words);
            Assert.AreEqual(2, words.Length);
        }