Documentation ¶
Overview ¶
Package markov generates string sequences.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StringsChain ¶
type StringsChain struct {
// contains filtered or unexported fields
}
StringsChain is a Markov chain of strings.
Example (Sentences) ¶
sentences := []string{ "squirrels are members of the family Sciuridae", "squirrels are indigenous to the Americas, Eurasia, and Africa", "the earliest known squirrels date from the Eocene period", } c := NewStringsChain(1, 0) for _, s := range sentences { c.Feed(strings.Split(s, " ")) } for n := 0; n < 3; n++ { fmt.Println(strings.Join(c.Generate(), " ")) }
Output: squirrels are indigenous to the family Sciuridae squirrels are members of the family Sciuridae the earliest known squirrels date from the family Sciuridae
Example (Words) ¶
words := []string{ "albatross", "alligator", "antelope", } c := NewStringsChain(2, 0) for _, s := range words { c.Feed(strings.Split(s, "")) } for n := 0; n < 3; n++ { fmt.Println(strings.Join(c.Generate(), "")) }
Output: albator antelope alligatross
func NewStringsChain ¶
func NewStringsChain(order int, randSeed int64) *StringsChain
NewStringsChain returns a new StringsChain of the given order.
func (*StringsChain) ExportState ¶
func (c *StringsChain) ExportState(w io.Writer) error
ExportState exports the state of the chain. The state of the PRNG is not exported.
func (*StringsChain) Feed ¶
func (c *StringsChain) Feed(seq []string)
Feed feeds the chain with the given sequence of strings.
func (*StringsChain) Generate ¶
func (c *StringsChain) Generate() []string
Generate generates a sequence of strings based on those fed.
func (*StringsChain) ImportState ¶
func (c *StringsChain) ImportState(r io.Reader) error
ImportState imports the given state. The state of the PRNG is unchanged.
func (*StringsChain) String ¶
func (c *StringsChain) String() string
String returns the chain visualised.
Click to show internal directories.
Click to hide internal directories.