static void Main(string[] args) { Chain chain = new Chain(); string[] input = File.ReadAllLines("TrumpTweets.txt"); string[] FormattedInput = Format.Tweets(input); foreach (string tweet in FormattedInput) { chain.AddString(tweet); } //update all the probabilities with the new data chain.UpdateProbabilities(); while (true) { string word = chain.GetRandomStartingWord(); String nextWord = chain.GetNextWord(word); Console.Write(word); while (nextWord != "") { Console.Write(" " + nextWord); nextWord = chain.GetNextWord(nextWord); } Console.ReadLine(); Console.WriteLine(); } }
static void Main(string[] args) { Chain chain = new Chain(); Console.WriteLine("Welcome to Marky Markov's Random Text Generator!"); Console.WriteLine("Enter some text I can learn from (enter single ! to finish): "); //LoadText("Sample.txt", chain); while (true) { Console.Write("> "); String line = Console.ReadLine(); if (line == "!") { break; } chain.AddString(line); // Let the chain process this string } // Now let's update all the probabilities with the new data chain.UpdateProbabilities(); // Okay now for the fun part Console.WriteLine("Done learning! Now give me a word and I'll tell you what comes next."); Console.Write("> "); String word = Console.ReadLine(); String nextWord = chain.GetNextWord(word); Console.WriteLine("I predict the next word will be " + nextWord); /*for (int i = 0; i < 10; i++) * { * Console.WriteLine(chain.GenerateSentence(chain.GetRandomStartingWord())); * } */ Console.WriteLine("Now I will generate some fun sentences!"); Random random = new Random(); int count = random.Next(1, 50); int num = 0; while (num < count) { Console.WriteLine(chain.GenerateSentence(chain.GetRandomStartingWord())); num++; } }
static void Main(string[] args) { Chain chain = new Chain(); Console.WriteLine("Welcome to Marky Markov's Random Text Generator!"); Console.WriteLine("Enter some text I can learn from (enter single ! to finish): "); const Int32 BufferSize = 128; using (var fileStream = File.OpenRead(@"C:\Users\eahscs\Desktop\Text.txt")) using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize)) { String line; while ((line = streamReader.ReadLine()) != null) { // Process line chain.AddString(line); } } // Now let's update all the probabilities with the new data chain.UpdateProbabilities(); // Okay now for the fun part Console.WriteLine("Done learning! Now give me a word and I'll tell you what comes next."); Console.Write("> "); String word = chain.GetRandomStartingWord(); String nextWord = chain.GetNextWord(word); Console.WriteLine("Starting Word: " + word); Console.WriteLine("I predict the next word will be " + nextWord); while (nextWord != "") { // String newWord = nextWord; nextWord = chain.GetNextWord(nextWord); //nextWord = newWord; Console.WriteLine(nextWord); //dd } }
static void Main(string[] args) { Chain chain = new Chain(); Console.WriteLine("Welcome to Marky Markov's Random Text Generator!"); Console.WriteLine("Enter some text I can learn from (enter single ! to finish): "); LoadText("Sample.txt", chain); while (true) { Console.Write("> "); String line = Console.ReadLine(); if (line == "!") { break; } chain.AddString(line); // Let the chain process this string } // Now let's update all the probabilities with the new data chain.UpdateProbabilities(); // Okay now for the fun part Console.WriteLine("Done learning! Now give me a word and I'll tell you what comes next."); Console.Write("> "); String nextWord; String word = chain.GetRandomStartingWord(); while (true) { Console.WriteLine(chain.GenerateSentence(word)); word = Console.ReadLine(); } }
static void Main(string[] args) { Random rand = new Random(System.Environment.TickCount); Chain chain = new Chain(); Console.WriteLine("Welcome to Marky Markov's Random Text Generator!"); /* * Console.WriteLine("Enter some text I can learn from (enter single ! to finish): "); * * while (true) * { * * Console.Write("> "); * * String line = Console.ReadLine(); * if (line == "!") * break; * * chain.AddString(line); // Let the chain process this string * }*/ string[] lines = File.ReadAllLines(@"Text\Minecraft.txt"); foreach (String line in lines) { String line2 = new string(line.Where(c => !char.IsPunctuation(c)).ToArray()); chain.AddString(line2.ToLower()); } // Now let's update all the probabilities with the new data chain.UpdateProbabilities(); // Okay now for the fun part //Console.WriteLine("Done learning! Now type in 10 words seperated by spaces, and I'll generate a minecraft parody."); //Console.Write("> "); //string[] startWords = Console.ReadLine().Split(' '); //Console.WriteLine(); /*for (int i = 0; i < startWords.Length; i++) * { * string nextWord = startWords[i]; * string New = nextWord; * New = New.Substring(0, 1).ToUpper() + New.Substring(1); * Console.Write(New + " "); * while (true) * { * nextWord = chain.GetNextWord(nextWord); * * if (nextWord == "") * break; * * Console.Write(nextWord + " "); * * } * Console.WriteLine(); * } */ Dictionary <String, List <String> > lyrics = new Dictionary <string, List <string> >(); for (int i = 0; i < 1000; i++) { string line = ""; string nextWord = chain.GetRandomStartingWord(); string New = nextWord; string lastWord = ""; New = New.Substring(0, 1).ToUpper() + New.Substring(1); line = New + " "; while (true) { lastWord = nextWord; nextWord = chain.GetNextWord(nextWord); if (nextWord == "") { break; } line += nextWord + " "; } List <String> list; if (lyrics.ContainsKey(lastWord)) { list = lyrics[lastWord]; list.Add(line); } else { list = new List <string>(); list.Add(line); lyrics.Add(lastWord, list); } } List <String> song = new List <String>(); int step = 0; for (int i = 0; i < 20; i++) { String key = lyrics.Keys.ElementAt(rand.Next() % lyrics.Keys.Count); if (lyrics[key].Count == 1) { i--; continue; } int first = rand.Next(lyrics[key].Count); int second = first; while (first == second) { second = rand.Next(lyrics[key].Count); } if (step == 1) { song.Insert(song.Count - 1, lyrics[key][first]); } else { song.Add(lyrics[key][first]); } song.Add(lyrics[key][second]); step++; if (step == 2) { step = 0; } } foreach (String s in song) { Console.WriteLine(s); } }
static void Main(string[] args) { Chain chain = new Chain(); Console.WriteLine("Welcome to Marky Markov's Random Text Generator!"); Console.WriteLine("Enter some text I can learn from (enter single ! to finish): "); bool going = true; while (going == true) { int counter = 0; string line; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader("TextFile1.txt"); while ((line = file.ReadLine()) != null) { //System.Console.WriteLine(line); if (line == "!") { going = false; } chain.AddString(line); // Let the chain process this string counter++; } file.Close(); } // Now let's update all the probabilities with the new data chain.UpdateProbabilities(); // Okay now for the fun part String word = chain.GetRandomStartingWord(); while (true) { //Console.WriteLine("Done learning! Now give me a word and I'll tell you what comes next."); //Console.Write("> "); String nextWord = chain.GetNextWord(word); Console.Write(" " + nextWord); if (nextWord.Contains(".") || nextWord.Contains("!") || nextWord.Contains("?")) { Console.WriteLine("\n"); word = chain.GetRandomStartingWord(); } else { word = nextWord; } if (word == "peckish") { break; } } }