Help us shape the future of Go! Take the 2026 Go Developer Survey

spell

package
v3.25.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT, MIT Imports: 19 Imported by: 0

Documentation

Overview

Package spell is a pure-Go, high-performance spell checker based on Hunspell-compatible dictionaries.

Index

Constants

View Source
const (
	Prefix affixType = iota
	Suffix
)

specific Affix types

Variables

This section is empty.

Functions

func Expand added in v3.25.0

func Expand(word, flags string) ([]string, error)

Expand returns the words that word with the given affix flags, such as `failover` and `S`, generates under Vale's default affix file.

func ExpandWith added in v3.25.0

func ExpandWith(path, word, flags string) ([]string, error)

ExpandWith is Expand under the `.aff` file at path.

func Similarity added in v3.22.0

func Similarity(a, b string) float64

Similarity is the closeness of two spellings, from 0 to 1, as the suggester measures it.

Types

type Checker

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

Checker is a spell-checker based on multiple dictionaries.

func NewChecker

func NewChecker(options ...CheckerOption) (*Checker, error)

NewChecker creates a spell checker from multiple Hunspell-compatible dictionaries.

func (*Checker) AddWordListFile

func (m *Checker) AddWordListFile(name string) error

AddWordListFile reads in a word list file

func (*Checker) Convert

func (m *Checker) Convert(s string) string

Convert performs character substitutions (ICONV).

func (*Checker) Dict

func (m *Checker) Dict(i int) map[string]struct{}

Dict returns the underlying dictionary for the provided index.

func (*Checker) Ignored added in v3.22.0

func (m *Checker) Ignored() []string

Ignored names the `.aff` directives the loaded dictionaries use that the checker does not implement, sorted.

func (*Checker) Rank added in v3.22.0

func (m *Checker) Rank(word string) []Suggestion

Rank returns the closest spellings of word across the dictionaries, best first, at most six.

func (*Checker) Recase added in v3.25.0

func (m *Checker) Recase(word string) (string, bool)

Recase returns the spelling a dictionary has for word in another case, when there is exactly one: GitHub for github.

func (*Checker) Spell

func (m *Checker) Spell(word string) bool

Spell checks to see if a given word is in the internal dictionaries.

func (*Checker) Suggest

func (m *Checker) Suggest(word string) []string

Suggest returns a list of suggestions for a given word.

type CheckerOption

type CheckerOption func(opts *Options)

A CheckerOption is a setting that changes the checker-creation process.

func UsingDictionary

func UsingDictionary(name string) CheckerOption

UsingDictionary loads the given Hunspell-compatible dictionary.

func UsingDictionaryByPath

func UsingDictionaryByPath(dic, aff string) CheckerOption

UsingDictionaryByPath loads the given Hunspell-compatible dictionary using the given local paths.

func WithDefault

func WithDefault(load bool) CheckerOption

WithDefault specifies if Vale's default dictionary should be loaded.

func WithDefaultPath

func WithDefaultPath(path string) CheckerOption

WithDefaultPath specifies a path from which all dictionaries should be loaded.

func WithPath

func WithPath(path string) CheckerOption

WithPath specifies the location of Hunspell-compatible dictionaries.

type Options

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

Options controls the checker-creation process:

type Suggestion added in v3.22.0

type Suggestion struct {
	Word  string
	Score float64
}

A Suggestion is a candidate spelling and how close it is to the word, on the scale Similarity uses.

Jump to

Keyboard shortcuts

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