5 releases

0.1.4 Mar 29, 2021
0.1.3 Mar 28, 2021
0.1.2 Mar 28, 2021
0.1.1 Mar 27, 2021
0.1.0 Mar 27, 2021

#248 in Text processing

44 downloads per month

GPL-3.0-only

26KB
353 lines

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();

Repository

The code is hosted on this Fossil repository.

To clone this project, install Fossil SCM, then:

$ mkdir markov_strings
$ cd markov_strings
$ fossil clone https://fossil.scambier.xyz/markovStringsRust markov_strings.fossil
$ fossil open markov_strings.fossil

Dependencies

~0.8–1.5MB
~33K SLoC