markov_strings

Crates.iomarkov_strings
lib.rsmarkov_strings
version0.1.5
sourcesrc
created_at2021-03-27 16:47:05.703273
updated_at2021-12-29 12:39:25.612735
descriptionA simplistic Markov chain text generator
homepagehttps://github.com/scambier/markov-strings-rust
repositoryhttps://github.com/scambier/markov-strings-rust
max_upload_size
id374295
size26,084
Simon Cambier (scambier)

documentation

README

markov_strings

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.

Usage

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();
Commit count: 2

cargo fmt