Crates.io | markov_strings |
lib.rs | markov_strings |
version | 0.1.5 |
source | src |
created_at | 2021-03-27 16:47:05.703273 |
updated_at | 2021-12-29 12:39:25.612735 |
description | A simplistic Markov chain text generator |
homepage | https://github.com/scambier/markov-strings-rust |
repository | https://github.com/scambier/markov-strings-rust |
max_upload_size | |
id | 374295 |
size | 26,084 |
A simplistic, configurable, Markov chain text generator. Give it an array of strings, and it will output a randomly generated string.
This is a port of the npm library markov-strings, from the same author.
use markov_strings::*;
// Instantiate the generator
let mut markov = Markov::new();
// Optional: specify a state size
markov.set_state_size(3); // Default: 2
// Feed it data
let data: Vec<InputData> = vec![/* a lot of data */];
markov.add_to_corpus(data);
// Define a results filter
markov
.set_filter(|r| {
// A minimal relative score and number of references
// The thresholds are relative to your input
r.score > 5 && r.refs.len() > 2
// We want to generate random tweets
&& r.text.len() <= 280
// No mentions
&& !r.text.contains("@")
// No urls
&& !r.text.contains("http")
})
.set_max_tries(100);
let result: MarkovResult = markov.generate().unwrap();