Beispiel #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 MakeWords()
        {
            TextGenerator wc = new TextGenerator();
            List<string> wordsList = new List<string>(20);
            for (int i = 0; i < 20; i++)
            {
                wordsList.Add(wc.GenerateWord(6));
            }

            string words = string.Join(", ", wordsList);
        }
        public void MakeNames()
        {
            TextGenerator wc = new TextGenerator(WordTypes.Name);
            List<string> namesList = new List<string>(20);
            for (int i = 0; i < 20; i++)
            {
                namesList.Add(wc.GenerateWord(6));
            }

            string names = string.Join(", ", namesList);
        }
        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 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 WordCreator_ShouldMakeWords()
 {
     TextGenerator wc = new TextGenerator();
     wc.GenerateWord(6).Should().NotBeNullOrEmpty().And.HaveLength(6);
 }
 public void WordCreator_ShouldMakeNames()
 {
     TextGenerator wc = new TextGenerator(WordTypes.Name);
     for (int i = 0; i < 100; i++)
     {
         string name = wc.GenerateWord(6);
         name.Should().NotBeNullOrEmpty().And.HaveLength(6);
         name[0].Should().Be(char.ToUpper(name[0]));
     }
 }
 public void WordCreator_ShouldMakeLongWords()
 {
     TextGenerator wc = new TextGenerator();
     wc.GenerateWord(100).Should().NotBeNullOrEmpty();
     string s = wc.GenerateWord(100);
 }
 public void WordCreatorConstructors_ShouldNotTrowExceptions()
 {
     TextGenerator wc = new TextGenerator();
     wc = new TextGenerator(WordTypes.Name);
     Corpus c = Corpus.DeserializeFromEmbeddedResource("names.bin");
     wc = new TextGenerator(c);
 }
        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);
 }
 public void MakeText()
 {
     TextGenerator wc = new TextGenerator();
     string text = wc.GenerateText(20);
 }
 public void CreateTextTest()
 {
     TextGenerator wc = new TextGenerator();
     string text = wc.GenerateText(200);
     text.Split(' ').Length.Should().Be(200);
     text.Should().EndWith(".");
 }
 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 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);
        }