Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain represents a Markov Chain.
When a Chain is built, it maintains the state space and state transistions in a map of indexes, where each index refers to an index of a corresponding slice of tokens.
The Chain also contains a slice of indexes for the first token found in every sentence in the corpus. These are used to begin generated phrases.
To map indexes to the actual tokens Indexes are used.
func NewChain ¶
NewChain creates a new Chain.
A Chain uses a prefix length l to determine how many tokens (words) to consider when deciding on the next token in a generated phrase.
func (*Chain) Build ¶
Build consumes from a reader and first builds an index of all tokens read. Then is re-reads from the reader using the built index to construct a mapping between prefixes and suffixes.
The underlying data stream should contain phrases separated by \n.
func (*Chain) Generate ¶
Generate uses the Markov chain to generate a phrase with a maximum length of l.
func (*Chain) MustGenerate ¶
MustGenerate panics if Generate returns an error.