[][src]Struct markov::Chain

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

A generic Markov chain for almost any type. In particular, elements of the chain must be Eq, Hash, and Clone.

Implementations

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

pub fn new() -> Chain<T>[src]

Constructs a new Markov chain.

pub fn of_order(order: usize) -> Chain<T>[src]

Creates a new Markov chain of the specified order. The order is the number of previous tokens to use for each mapping in the chain. Higher orders mean that the generated text will more closely resemble the training set. Increasing the order can yield more realistic output, but typically at the cost of requiring more training data.

pub fn is_empty(&self) -> bool[src]

Determines whether or not the chain is empty. A chain is considered empty if nothing has been fed into it.

pub fn feed<S: AsRef<[T]>>(&mut self, tokens: S) -> &mut Chain<T>[src]

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.

pub fn generate(&self) -> Vec<T>[src]

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.

pub fn generate_from_token(&self, token: T) -> Vec<T>[src]

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.

pub fn iter(&self) -> InfiniteChainIterator<T>

Important traits for InfiniteChainIterator<'a, T>

impl<'a, T> Iterator for InfiniteChainIterator<'a, T> where
    T: Chainable + 'a, 
type Item = Vec<T>;
[src]

Produces an infinite iterator of generated token collections.

pub fn iter_for(&self, size: usize) -> SizedChainIterator<T>

Important traits for SizedChainIterator<'a, T>

impl<'a, T> Iterator for SizedChainIterator<'a, T> where
    T: Chainable + 'a, 
type Item = Vec<T>;
[src]

Produces an iterator for the specified number of generated token collections.

pub fn graph(&self) -> Graph<Vec<Option<T>>, f64>[src]

Create a graph using petgraph from the markov chain.

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

pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>[src]

Saves the current chain to the specified path.

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

pub fn load<P: AsRef<Path>>(path: P) -> Result<Chain<T>>[src]

Loads a chain from the specified path.

impl Chain<String>[src]

pub fn feed_str(&mut self, string: &str) -> &mut Chain<String>[src]

Feeds a string of text into the chain.

pub fn feed_file<P: AsRef<Path>>(
    &mut self,
    path: P
) -> Result<&mut Chain<String>>
[src]

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.

pub fn generate_str(&self) -> String[src]

Generates a random string of text.

pub fn generate_str_from_token(&self, string: &str) -> String[src]

Generates a random string of text starting with the desired token. This returns an empty string if the token is not found.

pub fn str_iter(&self) -> InfiniteChainStringIterator[src]

Produces an infinite iterator of generated strings.

pub fn str_iter_for(&self, size: usize) -> SizedChainStringIterator[src]

Produces a sized iterator of generated strings.

Trait Implementations

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

impl<'de, T> Deserialize<'de> for Chain<T> where
    T: Chainable,
    T: Deserialize<'de>, 
[src]

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

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

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

Auto Trait Implementations

impl<T> RefUnwindSafe for Chain<T> where
    T: RefUnwindSafe

impl<T> Send for Chain<T> where
    T: Send

impl<T> Sync for Chain<T> where
    T: Sync

impl<T> Unpin for Chain<T> where
    T: Unpin

impl<T> UnwindSafe for Chain<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,