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(start: T, end: T) -> Chain<T>

Constructs a new Markov chain using the given tokens as the marked starting and ending points for generation.

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<T> Chain<T> where T: Decodable + Chainable
[src]

fn load(path: &Path) -> Result<Chain<T>>

Loads a chain from a JSON file at the specified path.

fn load_utf8(path: &str) -> Result<Chain<T>>

Loads a chain from a JSON file using a string path.

impl<T> Chain<T> where T: for<'a> Encodable + Chainable
[src]

fn save(&self, path: &Path) -> Result<()>

Saves a chain to a JSON file at the specified path.

fn save_utf8(&self, path: &str) -> Result<()>

Saves a chain to a JSON file using a string path.

impl Chain<String>
[src]

fn for_strings() -> Chain<String>

Creates a new Chain intended specifically for strings. This uses the Unicode start of text and end of text control characters as the starting and ending tokens for the chain.

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.

Trait Implementations

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

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

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

fn eq(&self, __arg_0: &Chain<T>) -> bool

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

fn ne(&self, __arg_0: &Chain<T>) -> bool

This method tests for !=.

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

fn decode<__DT: Decoder>(__arg_0: &mut __DT) -> Result<Chain<T>, __DT::Error>

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

fn encode<__ST: Encoder>(&self, __arg_0: &mut __ST) -> Result<(), __ST::Error>