Esempio n. 1
0
        static void Main(string[] args)
        {
            var r = new Random();
            #if true
            var testText = "hel45o[ the^5re";
            testText = File.ReadAllText(@"D:\Users\Matthew\Desktop\egyptianNames.csv");
            //testText = "hello";
            var chain = new MarkovChain(r)
            {
                TerminatorCharacter = '\n',
                ChainName = "Egyptian"
            };

            for (int ltk = 2; ltk < 10; ltk++)
            {
                var sw = Stopwatch.StartNew();
                chain.LettersToKeep = ltk;
                chain.ConsumeText(testText);
                Console.WriteLine("Keeping {0}", ltk);
                for (var i = 0; i < 15; i++)
                {
                    var output = chain.BuildText();
                    Console.WriteLine(output);
                }

                Console.WriteLine("Time Taken: {0} millisec", sw.ElapsedMilliseconds);
                Console.WriteLine();
            }
            #endif

            #if false
            var serializedChain = File.ReadAllText("egyptian.nampak");
            var chain = MarkovChain.DeserializeFromText(serializedChain, r);

            for (var i = 0; i < 15; i++)
            {
                var output = chain.BuildText();
                Console.WriteLine(output);
            }
            #endif

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            #if true
            var serialOutput = chain.SerializeToText();

            File.WriteAllText("egyptian.nampak", serialOutput);
            #endif

            Console.WriteLine("Done!");
            Console.ReadKey();
        }
Esempio n. 2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            var r = new Random();

            _chain = new MarkovChain(r)
            {
                LettersToKeep = 3,
                TerminatorCharacter = '\n'
            };

            _chain.ConsumeText(TestText);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            var button = FindViewById<Button>(Resource.Id.GenerateButton);
            var nameLabel = FindViewById<TextView>(Resource.Id.NameTextView);

            button.Click += delegate { nameLabel.Text = _chain.BuildText(); };
        }