Struct markov_chain::Chain [] [src]

pub struct Chain<T> where
    T: Clone + Chainable
{ /* fields omitted */ }

A struct representing a markov chain.

A markov chain has an order, which determines how many items per node are held. The chain itself is a map of vectors, which point to a map of single elements pointing at a weight.

use markov_chain::Chain;
 
let mut chain = Chain::new(1); // 1 is the order of the chain
 
// Train the chain on some vectors
chain.train(vec![1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1])
    .train(vec![5, 4, 3, 2, 1]);
 
// Generate a sequence and print it out
let sequence = chain.generate();
println!("{:?} ", sequence);

Methods

impl<T> Chain<T> where
    T: Clone + Chainable
[src]

Initializes a new markov chain with a given order.

Examples

use markov_chain::Chain;
let chain: Chain<u32> = Chain::new(1);

Gets the order of the markov chain. This is static from chain to chain.

Trains a sentence on a string of items.

Examples

use markov_chain::Chain;
let mut chain = Chain::new(1);
let data = vec![10, 15, 20];
chain.train(data)
    .train(vec![]);

Merges this markov chain with another.

Examples

use markov_chain::Chain;
let mut chain1 = Chain::new(1);
let mut chain2 = chain1.clone();
chain1.train(vec![1, 2, 3]);
chain2.train(vec![2, 3, 4, 5, 6])
    .merge(&chain1);

Generates a string of items with no maximum limit. This is equivalent to generate_limit(-1).

Generates a string of items, based on the training, of up to N items. Specifying a maximum of -1 allows any arbitrary size of list.

impl Chain<String>
[src]

String-specific implementation of the chain. Contains some special string- specific functions.

Trains this chain on a single string. Strings are broken into words, which are split by whitespace and punctuation.

Generates a sentence, which are ended by "break" strings or null links. "Break" strings are: ., ?, !, .", !", ?", ,"

Generates a paragraph of N sentences. Each sentence is broken off by N spaces.

Trait Implementations

impl<T: Clone> Clone for Chain<T> where
    T: Clone + Chainable
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: PartialEq> PartialEq for Chain<T> where
    T: Clone + Chainable
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: Debug> Debug for Chain<T> where
    T: Clone + Chainable
[src]

Formats the value using the given formatter.