[][src]Crate gmarkov_lib

A library that provides Markov chain data structures.

The MarkovChain structure allows you to feed in several sequences of items and get out a sequence that looks very similar, but is randomly generated.

This is the library to my CLI app gmarkov. (Coming soon!)

Example

extern crate gmarkov_lib;
 
use std::fs::File;
use std::io::{Result, BufRead, BufReader};
use gmarkov_lib::MarkovChain;
 
fn main() -> Result<()> {
    let mut chain = MarkovChain::with_order::<char>(2);
 
    let reader = BufReader::new(File::open("/usr/share/dict/words")?);
    for line in reader.lines() {
        chain.feed(line?.chars());
    }
 
    println!("New word: {}", chain.into_iter().collect::<String>());
 
    Ok(())
}

The short program above will create a Markov chain of order 2, then feed it every word in the dictionary (/usr/bin/dict/words), then print out one new random word.

Structs

MarkovChain

The Markov Chain data structure

MarkovIterator

An iterator that produces the values of a Markov chain