Crates.io | markovgen |
lib.rs | markovgen |
version | 0.2.0 |
source | src |
created_at | 2024-05-15 08:38:48.745443 |
updated_at | 2024-05-15 20:02:10.544565 |
description | A library for building markov chain graphs from text datasets and performantly generating text sequences by traversing them, includes an accompanying CLI application. |
homepage | |
repository | https://github.com/sysrqmagician/markovgen |
max_upload_size | |
id | 1240788 |
size | 109,305 |
A library for building markov chain graphs from text datasets and performantly generating text sequences by traversing them.
benches/
)cargo run -r -F serde --bin markovcli
src/bin/example.rs
:
use std::sync::Arc;
use markovgen::*;
const NAME_DATASET: &str = "Tim\nTom\nThomas\nNathan\nNina\nTiara\nTyra\nTyrone";
const SEQUENCE_START: char = '\x01';
const SEQUENCE_END: char = '\x02';
fn main() {
let mut constructor = GraphConstructor::new();
NAME_DATASET.lines().for_each(|l| {
l.chars().fold(SEQUENCE_START, |acc, x| {
constructor.register_sequence(acc, x);
x
});
constructor.register_sequence(l.chars().last().unwrap(), SEQUENCE_END);
});
let graph = Arc::new(constructor.construct());
let mut stepper = GraphStepper::new(
graph,
GraphStepperConfiguration {
start_char: Some(SEQUENCE_START),
min_length: Some(3),
},
)
.unwrap();
// Step until reaching a "dead end" vertex, with a timeout of 16 steps.
println!("{}", stepper.step_until_end_state(16).unwrap());
}
Running this should yield something like:
$ cargo run --bin example
Ninathom