Exemplo n.º 1
0
        public void PhraseGeneratorTest()
        {
            var one = new Word {
                Value = "one", IsStart = true
            };
            var two = new Word {
                Value = "two", IsStart = false
            };
            var three = new Word {
                Value = "three", IsStart = true
            };
            var four = new Word {
                Value = "four", IsStart = false
            };

            var model = new MarkovModel
            {
                Words = new Word[]
                {
                    one,
                    two,
                    three,
                    four
                },
                StartWords = new Word[]
                {
                    one,
                    three
                },
                WordLinks = new WordLink[]
                {
                    new WordLink {
                        FromWord = one, ToWord = two, Weight = 100
                    },
                    new WordLink {
                        FromWord = three, ToWord = four, Weight = 100
                    },
                    new WordLink {
                        FromWord = two, ToWord = three, Weight = 10
                    },
                }
            };

            var generator = new MarkovPhraseGenerator(model, true);

            for (var index = 0; index < 100; index++)
            {
                var phrase = generator.GetPhrase();
                Assert.IsTrue(phrase.StartsWith("One two three") ||
                              phrase.StartsWith("Three four"));
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var inputText =
                File.ReadAllText(@"E:\Users\aleksandr\Documents\inputText1.txt") + " " +
                File.ReadAllText(@"E:\Users\aleksandr\Documents\inputText2.txt") + " " +
                File.ReadAllText(@"E:\Users\aleksandr\Documents\inputText3.txt") + " " +
                File.ReadAllText(@"E:\Users\aleksandr\Documents\inputText4.txt");

            var useAltrnativeModelGenerator = true;
            var phrasesCount = 100;

            var modelGenerator = useAltrnativeModelGenerator ?
                                 new MarkovModelGenerator(new AlternativeTextPreparator(), new AlternativeTextSplitter()) :
                                 new MarkovModelGenerator();
            var model = modelGenerator.MakeFromText(inputText);

            var generator = new MarkovPhraseGenerator(model, true);

            for (var index = 0; index < phrasesCount; index++)
            {
                Console.WriteLine(generator.GetPhrase());
            }
        }