//private int tweetCount; //var generator = new MarkovGenerator(markovOrder, false); public TweetGenerator(SingleUserAuthorizer auth, string screenname, int count, int order) { this.auth = auth; this.generator = new MarkovGenerator(order, false); this.screenname = screenname; this.tweetCount = count; }
public void MarkovGenerator_Dummy() { string[] data = new[] { "martin", "bernard", "thomas", "petit", "robert", "richard", "durand", "dubois", "moreau", "laurent" }; var learner = new SimpleLearner <char>(); learner.Learn(data); var generator = new MarkovGenerator <char>(learner.GetStates()); var strings = new List <string>(); for (int i = 0; i < 100; i++) { strings.Add(string.Concat(generator.Generate(10))); } }
public static Species GetSpecies(string name = "") { GradientColorKey[] colorKeys = new GradientColorKey[3]; float position = 0.0f; for (int i = 0; i < 3; i++) { colorKeys[i] = new GradientColorKey(Constants.GetRandomPastelColor(), position); position += 0.50f; } GradientAlphaKey[] alphaKeys = new GradientAlphaKey[2] { new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 1) }; Gradient g = new Gradient(); g.alphaKeys = alphaKeys; g.colorKeys = colorKeys; Sprite[] sprites = SpriteLoader.GetRandomSetOfAlienSprites().ToArray(); if (name == "") { name = MarkovGenerator.GenerateMarkovWord(StringLoader.GetAllStrings("SpeciesButterfly"), 1)[0]; } return(new Species(name, sprites, g)); }
private GeneratorFacade InitBaseFacade() { Test_MarkovGenerator markovTest = new Test_MarkovGenerator(); MarkovGenerator gen = markovTest.InitBaseMarkovGenerator(); return(new GeneratorFacade(gen, new Random(3000))); }
public static string Markov(string input) { //Load Markov.bin or create new Markov mkv = new Markov(); if (File.Exists("Markov.bin")) { try { mkv.LoadChainState("Markov"); } catch { } } //Feed input mkv.Feed(input); //Generate new sentence Random rnd = new Random(); string markov = MarkovGenerator.Create(rnd.Next(50, 150), mkv); markov = MarkovGenerator.Create(mkv); //Save mkv.SaveChainState("Markov"); //Return new sentence return(markov); }
public void keySize_one_through_five_are_good() { foreach (var i in Enumerable.Range(1, 5)) { var _ = new MarkovGenerator(i); } }
public MapGeneratorConfiguration(ParseBlock Block) { var attributes = Block.BreakToAttributes <object>(typeof(Attribute), true); UniqueKey = Block.Name; NameGenerator = (MarkovGenerator <char>)attributes[(int)Attribute.NAME_GENERATOR]; TerrainGenerator = (TerrainGeneratorConfiguration)attributes[(int)Attribute.TERRAIN_GENERATOR]; }
public MarkovEditor(MarkovGenerator mg) { this.StartPosition = FormStartPosition.CenterParent; InitializeComponent(); _m = mg; PopulateForm(); }
public IActionResult Index(string screenname, string order) { // TODO handle hashtags separately int markovOrder; // default order is 2, if the parse failed if (!int.TryParse(order, out markovOrder)) markovOrder = 2; // hack to avoid null pointer exception if (markovOrder > 5) markovOrder = 5; int tweetCount = 200; var generator = new MarkovGenerator(markovOrder, false); // how to handle hashtags? just keep a list of them along with a probability for each, // i.e. a single-prefix markov chain? // would also need a no-hashtag probability // no, that won't work, since there wouldn't be an end point, really. at least not one that makes sense. // what might work is keeping track of individual hashtag probabilities, // as well as a probability distribution of number of hashtags. (fun to get some stats on that, see if it's poisson-distributed) ViewData["Screenname"] = screenname; var auth = new SingleUserAuthorizer { CredentialStore = new SingleUserInMemoryCredentialStore { ConsumerKey = _consumerKey, ConsumerSecret = _consumerSecret, AccessToken = _accessToken, AccessTokenSecret = _accessTokenSecret } }; var twitterCtx = new TwitterContext(auth); var timeline = (twitterCtx.Status.Where(tweet => tweet.Type == StatusType.User && tweet.ScreenName == screenname && tweet.Count == tweetCount)) .ToList(); foreach (var tweet in timeline) { generator.ReadInput(tweet.Text); } int outputCount = 20; var outputList = new List<string>(); for (int i = 0; i < outputCount; i++) { outputList.Add(generator.GenerateOutput()); } //TODO add form //TODO use form data return View(outputList); }
/// <summary> /// Create simple Markov Generator to run tests with /// </summary> /// <returns></returns> public MarkovGenerator InitBaseMarkovGenerator() { MarkovGenerator gen = new MarkovGenerator(_simpleString, new GeneratorParams(){ Punctuation = _defaultPunctuation, SentenceEnd = _defaultSentenceEnd, Rand = _rand}) ; return gen ; }
public void GenerateEntities() { data = GameDataManager.instance.masterGalaxyData; GameDataManager.instance.ClearAllEntities(); GameDataManager.instance.ClearAllSpecies(); string[] speciesNames = MarkovGenerator.GenerateMarkovWord(StringLoader.GetAllStrings("SpeciesButterfly"), numberOfSpecies); for (int i = 0; i < numberOfSpecies; i++) { GameDataManager.instance.AddNewSpecies(SpeciesGenerator.GetSpecies(speciesNames[i])); } for (int i = 0; i < data.sectors.Length; i++) { for (int j = 0; j < data.sectors[0].Length; j++) { if (data.sectors[i][j].Owner == null && data.sectors[i][j].SystemCount > 0) { unoccupiedSectors.Add(data.sectors[i][j]); } } } List <List <SectorData> > partitions = GenerateSectorPartitions(unoccupiedSectors); string[] entityNames = MarkovGenerator.GenerateMarkovWord(StringLoader.GetAllStrings("StarNames"), partitions.Count); for (int i = 0; i < partitions.Count; i++) { float averageSystem = 0; float maxSystem = 0; float minSystem = 10000; float sumOfSquares = 0; foreach (SectorData d in partitions[i]) { averageSystem += d.SystemCount; sumOfSquares += d.SystemCount * d.SystemCount; if (d.SystemCount > maxSystem) { maxSystem = d.SystemCount; } if (d.SystemCount < minSystem) { minSystem = d.SystemCount; } } float totalSystem = averageSystem; averageSystem = averageSystem / partitions[i].Count; float sumOfSquaresAverage = sumOfSquares / partitions[i].Count; float standardDeviation = Mathf.Sqrt(sumOfSquaresAverage - (averageSystem * averageSystem)); Debug.Log("Total System:" + totalSystem + " averageSystem:" + averageSystem + " minSystem:" + minSystem + " maxSystem:" + maxSystem + " stdDeviation:" + standardDeviation); GalaxyEntity g = GetEntity(partitions[i]); g.name = entityNames[i]; Debug.Log(g.leader.FullName + " " + g.Government.governmentName + " " + g.Government.governmentCatagory); GameDataManager.instance.AddNewEntity(g); } entityList.Display(GameDataManager.instance.Entitites); speciesList.Display(GameDataManager.instance.Species); WorldMap.instance.ShowTerritory(); }
public MapGeneratorConfiguration( string UniqueKey, MarkovGenerator <char> NameGenerator, TerrainGeneratorConfiguration TerrainGenerator) { this.UniqueKey = UniqueKey; this.NameGenerator = NameGenerator; this.TerrainGenerator = TerrainGenerator; }
public static Species[] GetMultipleSpecies(int number) { Species[] species = new Species[number]; string[] names = MarkovGenerator.GenerateMarkovWord(StringLoader.GetAllStrings("SpeciesButterfly"), 400); for (int i = 0; i < number; i++) { species[i] = GetSpecies(names[i]); } return(species); }
static MarkovGenerator TimeMarkovConstructor() { Stopwatch timer = new Stopwatch(); timer.Start(); MarkovGenerator gen = new MarkovGenerator(System.IO.File.ReadAllText("PrideAndPrejudice.txt")); timer.Stop(); double baseGenTime = timer.ElapsedMilliseconds / 1000.0; Console.WriteLine(string.Format("Time to generate a new Markov Gen: {0:0.00} seconds", baseGenTime)); return(gen); }
public void Test_Constructor_Happy() { MarkovGenerator gen = new MarkovGenerator("Test Markov Gen More words typing here") ; CollectionAssert.AreEquivalent(gen.Punctuation, _defaultPunctuation) ; CollectionAssert.AreEquivalent(gen.SentenceEnd, _defaultSentenceEnd) ; gen = new MarkovGenerator("Test Markov Gen", new GeneratorParams() {Punctuation = new List<char>{'a', 'b'}, SentenceEnd = new List<char> {'c', 'd'}}) ; CollectionAssert.AreEquivalent(gen.Punctuation, new List<char>{'a', 'b'}) ; CollectionAssert.AreEquivalent(gen.SentenceEnd, new List<char> {'c', 'd'}) ; }
public async Task ChatMarkov([Remainder] string options = "[300] {5}") { await Context.Message.DeleteAsync(); int fetch = (Regex.IsMatch(options, @"\[(.+?)\]")) ? Convert.ToInt32(Regex.Matches(options, @"\[(.+?)\]")[0].Groups[1].Value) : 100; int minLength = (Regex.IsMatch(options, @"\{(.+?)\}")) ? Convert.ToInt32(Regex.Matches(options, @"\{(.+?)\}")[0].Groups[1].Value) : 5; var markovGenerator = new MarkovGenerator(Context.Channel.GetMessagesAsync(fetch).Flatten().Result.Reverse().Select(msg => msg.Content).Aggregate((i, j) => i + ". " + j)); //var markovGenerator = new MarkovGenerator(new ChannelUtils().GetMessagesHugeAsync(Context.Channel, fetch).Result.Select(msg => msg.Content).Aggregate((i, j) => i + " " + j)); await ReplyAsync(markovGenerator.GenerateSentence(minLength)); }
public void Test_GenerateSentence_CorrectStart_CorrectEnd() { MarkovGenerator gen = InitBaseMarkovGenerator(); bool thisIsAStart = false; bool isThisAStart = false; bool grammarShouldWorkStart = false; bool dotEnd = false; bool questionEnd = false; bool exclamationEnd = false; //Verify all the sentences starts and ends are used for (int i = 0; i < 30; i++) { string currSentence = gen.GenerateSentence(0); //sentence starts if (currSentence.StartsWith("This is a")) { thisIsAStart = true; } else if (currSentence.StartsWith("Is this a")) { isThisAStart = true; } else if (currSentence.StartsWith("Grammar should work")) { grammarShouldWorkStart = true; } //sentence ends if (currSentence.EndsWith(".")) { dotEnd = true; } else if (currSentence.EndsWith("?")) { questionEnd = true; } else if (currSentence.EndsWith("!")) { exclamationEnd = true; } } Assert.IsTrue(thisIsAStart); Assert.IsTrue(isThisAStart); Assert.IsTrue(grammarShouldWorkStart); Assert.IsTrue(dotEnd); Assert.IsTrue(questionEnd); Assert.IsTrue(exclamationEnd); }
public void TestMarkovSerialization() { var m = new MarkovGenerator(MarkovRuleType.XrayChar, 3); var xm = m.ToXml(); var mm = new MarkovGenerator().FromXML(xm); mm.Source = "This and that are some. More of the. Oh, whatever the that, then. You know this? This is what I mean. That or that and or of yes."; Console.WriteLine(mm.Munged); Console.ReadKey(); }
//Log replies and respond with a random reply public static async Task Markov(string message, SocketGuildChannel channel, int frequency) { string binFilePath = $"Servers\\{channel.Guild.Id.ToString()}\\{channel.Guild.Id.ToString()}"; Markov mkv = new Markov(); try { mkv.LoadChainState(binFilePath); } catch { } //Sanitize message content string newMessage = message; var links = newMessage.Split("\t\n ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Where(s => s.StartsWith("http://") || s.StartsWith("www.") || s.StartsWith("https://") || s.StartsWith("@")); foreach (var link in links) { newMessage = newMessage.Replace(link, ""); } if (newMessage != "" && Moderation.IsPublicChannel(channel)) { mkv.Feed(newMessage); } mkv.SaveChainState(binFilePath); var socketChannel = (ISocketMessageChannel)channel; Random rnd = new Random(); string markov = MarkovGenerator.Create(mkv); int runs = 0; while (markov.Length < UserSettings.BotOptions.MarkovMinimumLength(channel.Guild.Id) && runs < 20) { markov = MarkovGenerator.Create(mkv); runs++; } if (rnd.Next(1, 100) <= frequency) { if (!UserSettings.BotOptions.MarkovBotChannelOnly(channel.Guild.Id)) { await socketChannel.SendMessageAsync(markov); } else if (channel.Id == UserSettings.Channels.BotChannelId(channel.Guild.Id)) { await socketChannel.SendMessageAsync(markov); } } return; }
public void TestContBWL() { var hmm = BuildContHMM(); var learntHmm = BuildContInitHMM(); var mg = new MarkovGenerator(hmm); var training = mg.GenerateSequences(200, 100); var bwl = new TrainBaumWelch(learntHmm, training); var klc = new KullbackLeiblerDistanceCalculator(); bwl.Iteration(5); learntHmm = (HiddenMarkovModel)bwl.Method; var e = klc.Distance(learntHmm, hmm); Assert.IsTrue(e < 0.01); }
public void TestDiscKMeans() { var hmm = BuildDiscHMM(); var mg = new MarkovGenerator(hmm); var sequences = mg.GenerateSequences(200, 100); var trainer = new TrainKMeans(hmm, sequences); var klc = new KullbackLeiblerDistanceCalculator(); trainer.Iteration(5); var learntHmm = (HiddenMarkovModel)trainer.Method; var e = klc.Distance(learntHmm, hmm); Assert.IsTrue(e < 0.05); }
public static MarkovGenerator <char> GenerateLanguage(uint PrefixLength, string ExamplePath) { var g = new MarkovGenerator <char>(PrefixLength); var parentheticals = new Regex("\\(.*\\)"); var capitals = new Regex("[A-Z- ]*"); foreach (var line in File.ReadAllLines(ExamplePath, Encoding.UTF8)) { var name = line.ToLower(); if (name.Length == 0) { continue; } name = parentheticals.Replace(name, ""); name = capitals.Replace(name, ""); name = name.Trim(); g.AddSequence(name); } return(g); }
public void Test_GenerateWords_CorrectNumber() { MarkovGenerator gen = InitBaseMarkovGenerator(); List<char> correctSplit = new List<char>(); correctSplit.Add(' '); correctSplit.AddRange(_defaultSentenceEnd); correctSplit.AddRange(_defaultPunctuation); string[] correctWords = _simpleString.Split(correctSplit.ToArray()); string[] correctWordsLower = new string[correctWords.Length] ; for(int i = 0 ; i < correctWords.Length ; i++) { correctWordsLower[i] = correctWords[i].ToLowerInvariant() ; } string[] words = gen.GenerateWords(20).Split(new char[]{' '}); Assert.AreEqual(20, words.Length); foreach (string word in words) { CollectionAssert.DoesNotContain(_defaultPunctuation, word); CollectionAssert.DoesNotContain(_defaultSentenceEnd, word); CollectionAssert.Contains(correctWordsLower, word); } }
public void SetUp() { // no parm = default keysize of 2 //_textGenerator = new MarkovGenerator(); _textGenerator = new MarkovGenerator(2); }
public void Test_GetNumWords_NegativeNumWords() { MarkovGenerator gen = InitBaseMarkovGenerator() ; Assert.Throws<Exceptions.InvalidArguments>(delegate { gen.GenerateWords(-2); }); }
public void SetUp() { _textGenerator = new MarkovGenerator(); }
public void SetUp() { _textGenerator = new MarkovGenerator(); _filePath = string.Format(@"{0}\AllsWellThatEndsWell.txt", Assembly.GetExecutingAssembly().Directory()); }
public void keySize_zero_throws_error() { var _ = new MarkovGenerator(0); }
public void Test_GenerateSentence_TooManyMinWords() { MarkovGenerator gen = InitBaseMarkovGenerator(); Assert.Throws<Exceptions.InvalidArguments>(delegate { gen.GenerateSentence(Defs.MAX_SENTENCE_LENGTH + 1); }); }
public void keySize_six_throws_error() { var _ = new MarkovGenerator(6); }