markov

package module
v0.0.0-...-fad3ca8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 4 Imported by: 0

README

Markov

A Go port of scambier/markov-strings, for use in Markov Chain Discord bots.

LICENSE

LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Corpus

type Corpus map[string][]*Fragment

Corpus contains data that makes up the Markov chain.

type Fragment

type Fragment struct {
	Words string
	Refs  []string
}

Fragment contains fragmented data used to form a sentence.

type GenerateOption

type GenerateOption func(*generateOptions)

GenerateOption is used to configure a Markov chain's generation settings.

func WithFilter

func WithFilter(fn func(*Result) bool) GenerateOption

WithFilter sets the filter used for generation.

func WithMaxTries

func WithMaxTries(mt int) GenerateOption

WithMaxTries sets the allotted number of attempts for a generation.

func WithPRNG

func WithPRNG(fn func() int) GenerateOption

WithPRNG sets the pseudo-random number generator used for generation.

type Markov

type Markov struct {
	// contains filtered or unexported fields
}

Markov represents a Markov chain which can be trained and used to generate sentences.

func New

func New(opts ...Option) *Markov

New creates a new Markov chain with the given options.

func (*Markov) AddData

func (m *Markov) AddData(ctx context.Context, data []string)

AddData adds the given data to the corpus.

func (*Markov) Generate

func (m *Markov) Generate(ctx context.Context, opts ...GenerateOption) (*Result, error)

Generate generates a sentence using the data it's been trained on.

type Option

type Option func(*Markov)

Option is used to configure a Markov chain.

func WithStateSize

func WithStateSize(ss int) Option

WithStateSize sets the size of a Markov chain's state.

func WithStore

func WithStore(s Store) Option

type Result

type Result struct {
	String string
	Score  int
	Refs   []string
	Tries  int
}

Result contains data pertaining to a generation.

type Store

type Store interface {
	StartWords(context.Context) []*Fragment
	SetStartWords(context.Context, []*Fragment)
	EndWords(context.Context) []*Fragment
	SetEndWords(context.Context, []*Fragment)
	Corpus(context.Context) Corpus
	SetCorpus(context.Context, Corpus)

	Import(context.Context, *Structure)
	Export(context.Context) *Structure
}

type Structure

type Structure struct {
	Corpus     Corpus
	StartWords []*Fragment
	EndWords   []*Fragment
}

Structure represents the internal structure of a Markov chain and is used to import & export data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL