private static void StringWalk(string[] sourceText, int level = 1) { StringMarkov model = new StringMarkov(level); model.Learn(sourceText); string format = model.Walk().First(); while (format.Trim() == String.Empty) { format = model.Walk().First(); } Console.WriteLine(format); }
static void Main(string[] args) { var model = new StringMarkov(2); var jArray = JArray.Parse(File.ReadAllText(@"pokemon.json")); var source = jArray.Select(x => x.Value <string>()).ToList(); var names = source; for (int i = 0; i < names.Count; i++) { var name = names[i]; int insertIndex = name.Length / 2; var charArray = name.ToCharArray().ToList(); //charArray.Insert(insertIndex, ' '); names[i] = string.Join(" ", charArray); } model.Learn(names); //GeneratorFacade gen = new GeneratorFacade(new MarkovGenerator(File.ReadAllText("book.txt"))); while (true) { Console.ReadLine(); var output = model.Walk().First(); output = output.Replace(" ", ""); //var output = gen.GenerateSentence(10); var result = output; if (source.Any(x => x == output)) { result = "did not change"; } Console.WriteLine(result); } }
public void WalkOnTrainedModelGeneratesCorrectNumberOfLines(int lineCount) { var model = new StringMarkov(); model.Learn(ExampleData); var result = model.Walk(lineCount); Assert.AreEqual(lineCount, result.Count()); }
public void WalkOnUntrainedModelIsEmpty() { var model = new StringMarkov(); var result = model.Walk(); CollectionAssert.AreEqual(new List <string> { string.Empty }, result); }
public void BasicWalkOnTrainedModelGeneratesCorrectNumberOfLines() { var model = new StringMarkov(); model.Learn(ExampleData); var result = model.Walk(1); Assert.AreEqual(1, result.Count()); Logger.Info(result.First()); }
public void MustCallWalkWithPositiveInteger(int lineCount) { var model = new StringMarkov(); var ex = Assert.Throws <ArgumentException>(() => { var x = model.Walk(lineCount).ToList(); }); Assert.AreEqual("Invalid argument - line count for walk must be a positive integer\r\nParameter name: lines", ex.Message); }
public void CanWalkWithUniqueOutput() { var model = new StringMarkov(); model.Learn(ExampleData); model.EnsureUniqueWalk = true; var results = model.Walk(500); Assert.AreEqual(results.Count(), results.Distinct().Count()); }
public string getRandomRya() { if (isReady) { return(stringMarkov.RebuildPhrase(stringMarkov.Walk())); } else { return(null); } }
private string GenerateSequence() { string seed = string.IsNullOrEmpty(start) ? null : start; //IEnumerable<string> result = model.Walk ( sequenceLength, seed ); IEnumerable <string> result = model.Walk(sequenceLength, seed, true); //IEnumerable<string> result = model.WalkRepeat ( sequenceLength, seed ); sequence = string.Join("\n", result); return(sequence); }
public void CanWalkUsingSeed() { var model = new StringMarkov(); model.Learn(ExampleData); var results = model.Walk(100, "This is a line"); Assert.AreEqual(100, results.Count()); foreach (var result in results) { Assert.That(result, Is.StringStarting("This is a line")); } }
public void GenerateQuotes(int n) { int numeroCadenas = 4; var model = new StringMarkov(n); Console.WriteLine("\nTraining ..."); model.Learn(lines); Console.WriteLine("============================================"); for (int i = 0; i < numeroCadenas; i++) { Console.WriteLine("[" + i + "]: " + model.Walk().First()); } }
private static async Task RespondAsync(BotArguments args, string text) { string response = null; var words = text.RemoveStopWords(args.Language).RemovePunctuation().Replace(args.TriggerWord, string.Empty).Split(' '); for (var index = words.Length - 1; index >= 0; index--) { response = _model.Walk(1, words[index]).First(); if (response == words[index]) { response = null; } } if (response == null) { response = _model.Walk(1).First(); } Console.WriteLine(response); await WriteChatAsync(args.ResponseTemplate + " " + response); }
public void CanWalkLoadedModel() { var model = new StringMarkov(1); model.Learn(ExampleData); model.Save(ModelFileName); var newModel = new StringMarkov().Load <StringMarkov>(ModelFileName); var lines = newModel.Walk(); Logger.Info(string.Join("\r\n", lines)); Assert.AreEqual(1, lines.Count()); Assert.That(lines.First(), Is.Not.Empty); }
public void WalkCreatesNewContent(int walkCount) { var model = new StringMarkov(); model.Learn(ExampleData); model.EnsureUniqueWalk = true; var results = model.Walk(walkCount); CollectionAssert.IsNotSubsetOf(results, ExampleData); foreach (var result in results) { Assert.That(result, Is.Not.Empty); CollectionAssert.DoesNotContain(ExampleData, result); } }
public void CanWalkWithUniqueOutputUsingSeed() { var model = new StringMarkov(); model.Learn(ExampleData); model.EnsureUniqueWalk = true; var results = model.Walk(1000, "This is a line"); foreach (var result in results) { Assert.That(result, Is.StringStarting("This is a line")); } Assert.AreEqual(results.Count(), results.Distinct().Count()); }
public async Task SendHelp(CommandContext ctx) { try { string[] lines = File.ReadAllLines(Path.Combine(Globals.AppPath, "Data", "help.txt")); StringMarkov model = new StringMarkov(1); model.Learn(lines); await ctx.RespondAsync(model.Walk().First()); } catch (Exception e) { Console.WriteLine(e); throw; } }
public void ProcessMarkov(List <string> inputHeadlines) { ProcessHeadlines(); // Create a new model var model = new StringMarkov(1); // Train the model model.Learn(Headlines.ToArray()); for (int i = 0; i < 3; i++) { generatedHeadline += model.Walk(3).First() + ".\n"; Console.WriteLine(generatedHeadline); } // Create some permutations Console.Read(); }
public async Task <string> MarkovReddit(string subreddit) { int walkSize = 1; if (subreddit.Split(' ').Length > 5) { walkSize = 2; } var model = new StringMarkov(walkSize) { EnsureUniqueWalk = true }; foreach (string sub in subreddit.Split(' ')) { model.Learn(await GetTitlesFromSubreddit(sub)); } return(model.Walk(15).Skip(5).OrderByDescending(x => x.Length).Take(5).GetRandom()); }
public void GenerateText() { // Some training data var lines = new string[] { "Frankly, my dear, I don't give a damn.", "Mama always said life was like a box of chocolates. You never know what you're gonna get.", "Many wealthy people are little more than janitors of their possessions." }; // Create a new model var model = new StringMarkov(1); // Train the model model.Learn(lines); // Create some permutations string txt = model.Walk().First(); text.text = txt; }