Struct markov::Chain
[−]
[src]
pub struct Chain<T> where T: Chainable {
// some fields omitted
}
A generic Markov chain for almost any type. This uses HashMaps internally, and so Eq and Hash are both required.
Methods
impl<T> Chain<T> where T: Chainable
[src]
fn new() -> Chain<T>
Constructs a new Markov chain.
fn order(&mut self, order: usize) -> &mut Chain<T>
Choose a specific Markov chain order. The order is the number of previous tokens to use as the index into the map.
fn is_empty(&self) -> bool
Determines whether or not the chain is empty. A chain is considered empty if nothing has been fed into it.
fn feed(&mut self, tokens: Vec<T>) -> &mut Chain<T>
Feeds the chain a collection of tokens. This operation is O(n) where n is the number of tokens to be fed into the chain.
fn generate(&self) -> Vec<Rc<T>>
Generates a collection of tokens from the chain. This operation is O(mn) where m is the length of the generated collection, and n is the number of possible states from a given state.
fn generate_from_token(&self, token: T) -> Vec<Rc<T>>
Generates a collection of tokens from the chain, starting with the given token. This operation is O(mn) where m is the length of the generated collection, and n is the number of possible states from a given state. This returns an empty vector if the token is not found.
fn iter(&self) -> InfiniteChainIterator<T>
Produces an infinite iterator of generated token collections.
fn iter_for(&self, size: usize) -> SizedChainIterator<T>
Produces an iterator for the specified number of generated token collections.
impl Chain<String>
[src]
fn feed_str(&mut self, string: &str) -> &mut Chain<String>
Feeds a string of text into the chain.
fn feed_file(&mut self, path: &Path) -> &mut Chain<String>
Feeds a properly formatted file into the chain. This file should be formatted such that each line is a new sentence. Punctuation may be included if it is desired.
fn generate_str(&self) -> String
Generates a random string of text.
fn generate_str_from_token(&self, string: &str) -> String
Generates a random string of text starting with the desired token. This returns an empty string if the token is not found.
fn str_iter(&self) -> InfiniteChainStringIterator
Produces an infinite iterator of generated strings.
fn str_iter_for(&self, size: usize) -> SizedChainStringIterator
Produces a sized iterator of generated strings.