public void ContinuePhrase_DoNothing_OnEmptyDictionary(string phraseStart, int phraseWordsCount)
        {
            var actual = TextGeneratorTask.ContinuePhrase(
                new Dictionary <string, string>(),
                phraseStart,
                phraseWordsCount);

            Assert.AreEqual(phraseStart, actual);
        }
        public void ContinuePhrase_DoNothing_WhenWordsCountIsZero()
        {
            var mostFrequentNextWords = new Dictionary <string, string>
            {
                { "x", "y" }
            };

            var actual =
                TextGeneratorTask.ContinuePhrase(mostFrequentNextWords, "x", 0);

            Assert.AreEqual("x", actual);
        }
        public void ContinuePhrase(string phraseBeginning, int wordsCount, string expectedResult)
        {
            var mostFrequentNextWords = new Dictionary <string, string>
            {
                { "x", "y" },
                { "x y", "z" },
                { "y", "q" }
            };

            var actual =
                TextGeneratorTask.ContinuePhrase(mostFrequentNextWords, phraseBeginning, wordsCount);

            Assert.AreEqual(expectedResult, actual);
        }
        public void ContinuePhrase_StopWhenNoBigrammsAndTrigramms()
        {
            var mostFrequentNextWords = new Dictionary <string, string>
            {
                { "x", "y" },
                { "x y", "z" },
                { "y", "q" }
            };

            var actual =
                TextGeneratorTask.ContinuePhrase(mostFrequentNextWords, "x", 4);

            Assert.AreEqual("x y z", actual);
        }
        public void ContinuePhrase_WhenNoTrigrams(string phraseBeginning, string expectedNextWord)
        {
            var mostFrequentNextWords = new Dictionary <string, string>
            {
                { "x", "y" },
                { "y", "z" },
                { "z", "x" },
                { "a", "b" }
            };

            var actual =
                TextGeneratorTask.ContinuePhrase(mostFrequentNextWords, phraseBeginning, 2);

            Assert.AreEqual(phraseBeginning + " " + expectedNextWord, actual);
        }
        public void ContinuePhrase_WithMultiletterWords(string phraseBeginning, string expectedNextWord)
        {
            var mostFrequentNextWords = new Dictionary <string, string>
            {
                { "hello", "everybody" },
                { "everybody be", "cool" },
                { "everybody", "be" }
            };

            var actual =
                TextGeneratorTask.ContinuePhrase(mostFrequentNextWords, phraseBeginning, 1);
            var expected = string.IsNullOrEmpty(expectedNextWord) ? phraseBeginning : phraseBeginning + " " + expectedNextWord;

            Assert.AreEqual(expected, actual);
        }
Example #7
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            Console.InputEncoding  = Encoding.UTF8;
            // Запуск автоматических тестов. Ниже список тестовых наборов, который нужно запустить.
            // Закомментируйте тесты на те задачи, к которым ещё не приступали, чтобы они не мешались в консоли.
            // Все непрошедшие тесты
            var testsToRun = new string[]
            {
                "TextGenerator.SentencesParser_Tests",
                "TextGenerator.FrequencyAnalysis_Tests",
                "TextGenerator.TextGenerator_Tests",
            };

            /*new AutoRun().Execute(new[]
             * {
             *  "--stoponerror", // Останавливать после первого же непрошедшего теста. Закомментируйте, чтобы увидеть все падающие тесты
             *  "--noresult",
             *  "--test=" + string.Join(",", testsToRun)
             * });*/

            var text = File.ReadAllText("HarryPotterText.txt");
            //var text = File.ReadAllText("moskva-petushki.txt");
            var sentences = SentencesParserTask.ParseSentences(text);
            var frequency = FrequencyAnalysisTask.GetMostFrequentNextWords(sentences);

            while (true)
            {
                Console.Write("Введите первое слово (например, harry): ");
                var beginning = Console.ReadLine();
                if (string.IsNullOrEmpty(beginning))
                {
                    return;
                }
                var phrase = TextGeneratorTask.ContinuePhrase(frequency, beginning.ToLower(), 10);
                Console.WriteLine(phrase);
            }
        }