Example #1
0
        public static void Main()
        {
            var generator = new TextGenerator(WordTypes.Name);

            var names = generator.GenerateText(1000);
            var trie = new Trie();
            var words = new HashSet<string>();
            names.Split(' ').ToList().ForEach(
                x =>
                    {
                        words.Add(x);
                        trie.AddWord(x);
                    });

            var result = new StringBuilder();

            foreach (var word in words.OrderBy(x => x))
            {
                int occurenceCount;
                trie.TryFindWord(word, out occurenceCount);
                result.AppendFormat("{0} -> {1} times", word, occurenceCount).AppendLine();
            }

            Console.WriteLine(result);
        }
        public void CreateNonEnglishTextTest()
        {
            string s = File.ReadAllText(@"Corpuses\rus.txt", Encoding.UTF8);

            Corpus c = Corpus.CreateFromText(s);

            TextGenerator wc = new TextGenerator(c);
            string text = wc.GenerateText(200);
            text.Split(' ').Length.Should().Be(200);
            text.Should().EndWith(".");
        }
        public void MakeRussianAndSpanishText()
        {
            string s = File.ReadAllText(@"Corpuses\rus.txt", Encoding.UTF8);
            Corpus c = Corpus.CreateFromText(s);

            // Corpus can be serialized for later usage; the resulting file can be embedded as a resource; see
            //c.SerializeToFile(string) and Corpus.DeserializeFromEmbeddedResource() methods.

            TextGenerator wc = new TextGenerator(c);
            string russian = wc.GenerateText(20);

            s = File.ReadAllText(@"Corpuses\spanish.txt", Encoding.UTF8);
            c = Corpus.CreateFromText(s);
            wc = new TextGenerator(c);
            string spanish = wc.GenerateText(20);
        }
 public void CreateText_ShouldWorkOffSmallCorpus()
 {
     string s = File.ReadAllText(@"Corpuses\short.txt", Encoding.UTF8);
     Corpus c = Corpus.CreateFromText(s);
     TextGenerator wc = new TextGenerator(c);
     string text = wc.GenerateText(2000);
     text.Split(' ').Length.Should().Be(2000);
     text.Should().EndWith(".");
 }
 public void CreateTextTest()
 {
     TextGenerator wc = new TextGenerator();
     string text = wc.GenerateText(200);
     text.Split(' ').Length.Should().Be(200);
     text.Should().EndWith(".");
 }
        public void WordCreator_ShouldNotGenerateWords_ThatHave3SameAdjacentLetters()
        {
            TextGenerator wc = new TextGenerator();
            string text = wc.GenerateText(10000);

            string[] split = text.Split(' ', '.');
            split.Any(x => Regex.Match(x, "(.)\\1{2,}").Groups.Count > 1).Should().BeFalse();
        }
        public void Text_ShouldNotHaveSentences_LongerThan_MaxSentenceLength()
        {
            TextGenerator wc = new TextGenerator();
            string text = wc.GenerateText(10000);

            string[] split = text.Split('.');
            split.Count(x => x.Split(' ').Length > wc.MaxSentenceLength).Should().Be(0);
        }
        public void Text_ShouldNotEndWithDoubleDots()
        {
            TextGenerator wc = new TextGenerator();
            string text = wc.GenerateText(50000);

            text.Should().NotContain("..");
        }
        public void TextGenerator_ShouldTakeLessThan_500ms_ToGenerate_10000Words()
        {
            TextGenerator wc = new TextGenerator();
            Stopwatch sw = Stopwatch.StartNew();
            for (int i = 0; i < 4; i++)
            {
                string text = wc.GenerateText(10000);
            }

            Debug.WriteLine("Total elapsed: " + sw.ElapsedMilliseconds / 4 + " ms");

            (sw.ElapsedMilliseconds / 4).Should().BeLessOrEqualTo(500);
        }
 public void IWant_TextGenerator_ToTakeLessThan_500ms_ToGenerate_1000Words()
 {
     TextGenerator wc = new TextGenerator();
     Stopwatch sw = Stopwatch.StartNew();
     string text = wc.GenerateText(1000);
     Debug.WriteLine("Total elapsed: " + sw.ElapsedMilliseconds + " ms");
     sw.ElapsedMilliseconds.Should().BeLessOrEqualTo(500);
 }
Example #11
0
 public void MakeText()
 {
     TextGenerator wc = new TextGenerator();
     string text = wc.GenerateText(20);
 }