public ActionResult GenerateText(InputText inputTextType, string userInputText = "", int numberOfSentences = -1) { if (numberOfSentences == -1) { numberOfSentences = random.Next(1, 11); } Dictionary<string, List<string>> dict = null; switch (inputTextType) { case InputText.InDesertAndWilderness: dict = PredefinedDictionaries.InDesertAndWilderness; break; case InputText.LordOfTheRings: dict = PredefinedDictionaries.Lotr; break; case InputText.Other: var dictGenerator = new DictionaryGenerator(); var d = dictGenerator.GenerateFrequencyTable(userInputText); var g = new MarkovChainTextGenerator(d); //return g.GetRandomChain(numberOfSentences); return PartialView(new Chain(inputTextType, g.GetRandomChain(numberOfSentences))); } var generator = new MarkovChainTextGenerator(dict); //return generator.GetRandomChain(numberOfSentences); return PartialView(new Chain(inputTextType, generator.GetRandomChain(numberOfSentences))); }
static void Main(string[] args) { var dictGenerator = new DictionaryGenerator(); var dictManager = new DictionaryFileManager(); //var dict = new DictionaryFileManager().Load("lotr.dict"); //Console.WriteLine(new MarkovChainTextGenerator(dict).GetRandomChain()); //var dict = dictGenerator.GenerateFrequencyTableFromFile("puszcza.txt"); //dictManager.Save("puszcza.dict", dict); var dict = dictManager.Load("puszcza.dict"); //dictManager.Save("lotr_full.dict", dict); //var dict = dictManager.Load("lotr_full.dict"); //var markovGenerator = new MarkovChainTextGenerator(dict); //string txt = markovGenerator.GetRandomChain(); //Console.WriteLine(txt); //using (var stream = File.Create("out.txt")) //{ // using (var streamWriter = new StreamWriter(stream)) // { // streamWriter.Write(txt); // } //} var markovGenerator = new MarkovChainTextGenerator(dict); while (true) { Console.Clear(); Console.WriteLine(markovGenerator.GetRandomChain()); Console.ReadKey(); } Console.ReadKey(); }