spellcheck

package
v12.120.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package spellcheck provides spellcheck based on Damerau–Levenshtein distance algorithm

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model struct {
	Threshold int // Score threshold (default: 2)
	// contains filtered or unexported fields
}

Model is spellcheck model struct

func Train

func Train(words []string) *Model

Train trains words by given string slice

Example
name := "Frida"
names := []string{"Jakalyn", "Freda", "Micayla", "Knightley", "Shun"}

model := Train(names)

fmt.Printf("%s → %s\n", name, model.Correct(name))
Output:

Frida → Freda

func (*Model) Correct

func (m *Model) Correct(word string) string

Correct corrects given value

Example
name := "Frida"
names := []string{"Jakalyn", "Freda", "Micayla", "Knightley", "Shun"}

model := Train(names)

fmt.Printf("%s → %s\n", name, model.Correct(name))
Output:

Frida → Freda

func (*Model) Suggest

func (m *Model) Suggest(word string, max int) []string

Suggest suggests words for given word or word part

Example
name := "azi"
names := []string{"Thorin", "Akhai", "Payden", "Ghazi", "Rey", "Axel", "Sahily", "Azriel"}

model := Train(names)

fmt.Printf("%s → %s\n", name, model.Suggest(name, 3))
Output:

Jump to

Keyboard shortcuts

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