nlp

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidModel = fmt.Errorf(`Mismatch between model configuration and persisted model.`)

Functions

func Clean

func Clean(input string) string

Clean returns the lower-case representation of input with whitespace trimmed and normalized to a single 0x20 (SPC) character.

func CleanToken

func CleanToken(input string) string

CleanToken calls Clean on input, then removes all non-alphanumeric characters from it. The result is useful for seeding a PRNG in a way that disregards punctuation and case.

func IsLower

func IsLower(s string) bool

Determines whether all alphabetic characters of s are lower case.

func IsTitle

func IsTitle(s string) bool

Determines whether all words of s are title case.

func IsUpper

func IsUpper(s string) bool

Determines whether all alphabetic characters of s are upper case.

func LoadModels

func LoadModels(dirname string) (map[string]Model, error)

func SaveModel

func SaveModel(m Model, path string, basename string) error

func ToSameCase

func ToSameCase(s string, like string) string

Converts s to the same case as like. Handles upper, lower, and title case.

Types

type DictDefinition

type DictDefinition struct {
}

type DictModel

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

func NewDictModel

func NewDictModel() *DictModel

func (*DictModel) MarshalText

func (m *DictModel) MarshalText() ([]byte, error)

func (*DictModel) Recognize

func (m *DictModel) Recognize(input string) float64

func (*DictModel) Train

func (m *DictModel) Train(input string)

func (*DictModel) UnmarshalText

func (m *DictModel) UnmarshalText(b []byte) error

type Generator

type Generator interface {
	Generate(seed string) string
}

type MarkovDefinition

type MarkovDefinition struct {
	// Lookback memory length for state transition table.
	// Higher order uses more memory but (might!) improve generation accuracy.
	Order int
	// Tokenization mode: " " or "".
	Delim string
}

type MarkovModel

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

func NewMarkovModel

func NewMarkovModel(order int, separator string) *MarkovModel

func (*MarkovModel) Generate

func (m *MarkovModel) Generate(seed string) string

Generate derives a random string deterministically from the seed. The length is guaranteed to be between the min and max lengths seen during training.

func (*MarkovModel) MarshalJSON

func (m *MarkovModel) MarshalJSON() ([]byte, error)

func (*MarkovModel) Recognize

func (m *MarkovModel) Recognize(input string) float64

func (*MarkovModel) Train

func (m *MarkovModel) Train(input string)

func (*MarkovModel) UnmarshalJSON

func (m *MarkovModel) UnmarshalJSON(b []byte) error

func (*MarkovModel) Validate

func (m *MarkovModel) Validate(md MarkovDefinition) error

type MatchDefinition

type MatchDefinition struct{}

type MatchModel

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

func NewMatchModel

func NewMatchModel(patterns []*regexp.Regexp) *MatchModel

func (*MatchModel) MarshalText

func (m *MatchModel) MarshalText() ([]byte, error)

func (*MatchModel) Recognize

func (m *MatchModel) Recognize(input string) float64

func (*MatchModel) Train

func (m *MatchModel) Train(input string)

func (*MatchModel) UnmarshalText

func (m *MatchModel) UnmarshalText(b []byte) error

type Model

type Model interface {
	Recognize(input string) float64
	Train(input string)
}

func LoadModel

func LoadModel(filename string) (Model, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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