symspell

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

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

Go to latest
Published: Jun 19, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	N = 1024908267229
)

Variables

This section is empty.

Functions

func Distance

func Distance(a, b string, algorithm edlib.Algorithm) (int, error)

Types

type Suggestion

type Suggestion struct {
	Term      string // Term is the suggested correctly spelled word
	Distance  int    // Distance between searched for word and suggestion in terms of edits
	Frequency int    // Frequency of suggestion in the dictionary (a measure of how common the word is)
}

Suggestion contains a spelling suggestion

func NewSuggestion

func NewSuggestion(term string, dist, freq int) *Suggestion

NewSuggestion creates a new instance of a Suggestion

func (*Suggestion) GetHashCode

func (s *Suggestion) GetHashCode() int

GetHashCode does something, need to figure out what exactly

func (*Suggestion) Less

func (s *Suggestion) Less(other *Suggestion) bool

Less returns true if other is less. False if equal or greater than

func (*Suggestion) ShallowCopy

func (s *Suggestion) ShallowCopy() *Suggestion

ShallowCopy creates a copy of the suggestion

func (*Suggestion) String

func (s *Suggestion) String() string

String implements the stringer interface

type Suggestions

type Suggestions []*Suggestion

Suggestions exists to implement the sort interface

func NewSuggestions

func NewSuggestions() Suggestions

NewSuggestions returns an empty Suggestions set

func (Suggestions) Clear

func (s Suggestions) Clear()

Clear the contents of the suggestions list

func (Suggestions) Len

func (s Suggestions) Len() int

Len returns the length of the Suggestions array

func (Suggestions) Less

func (s Suggestions) Less(i, j int) bool

Less compares two Suggestion items and returns true if the first is less than the second, false for equal or greater

func (Suggestions) Swap

func (s Suggestions) Swap(i, j int)

Swap the positions of two Suggestion in the array

type SymSpell

type SymSpell struct {
	Verbosity verb.Verbosity

	MaxEditDistance int
	PrefixLength    int
	CountThreshold  int
	InitialCapacity int
	CompactLevel    int
	CompactMask     uint
	MaxWordLength   int

	DistanceAlgorithm edlib.Algorithm

	// Dictionary that contains a mapping of lists of suggested correction words to the hashCodes
	// of the original words and the deletes derived from them. Collisions of hashCodes is tolerated,
	// because suggestions are ultimately verified via an edit distance function.
	// A list of suggestions might have a single suggestion, or multiple suggestions.
	Deletes map[int][]string
	// Dictionary of unique correct spelling words, and the frequency count for each word.
	Words map[string]int
	// Dictionary of unique words that are below the count threshold for being considered correct spellings.
	BelowThresholdWords map[string]int

	BigRams        map[string]int
	BigRamCountMin int
}

func NewSymSpell

func NewSymSpell(initialCapacity, maxEditDistance, prefixLength, countThreshold, compactLevel int) (*SymSpell, error)

func NewSymSpellDefault

func NewSymSpellDefault() (*SymSpell, error)

func (*SymSpell) CommitStaged

func (s *SymSpell) CommitStaged(staging *staging.Stage[string])

func (*SymSpell) CreateDictionary

func (s *SymSpell) CreateDictionary(corpus io.Reader) bool

func (*SymSpell) CreateDictionaryFile

func (s *SymSpell) CreateDictionaryFile(corpus string) bool

func (*SymSpell) CreateEntry

func (s *SymSpell) CreateEntry(word string, count int, stage *staging.Stage[string]) (bool, error)

func (*SymSpell) DeleteInSuggestionPrefix

func (s *SymSpell) DeleteInSuggestionPrefix(del string, delLen int, suggestion string, suggestionLen int) bool

DeleteInSuggestionPrefix checks whether all delete chars are present in the suggestion prefix in correct order, otherwise this is just a hash collision

func (*SymSpell) Edits

func (s *SymSpell) Edits(word string, editDistance int, deleteWords mapset.Set[string]) mapset.Set[string]

Edits creates a set of inexpensive and language independent edits only deletes, no transposes, replacements, or inserts replaces and inserts are expensive and language dependent (Chinese has 70,000 Unicode Han characters)

func (*SymSpell) EditsPrefix

func (s *SymSpell) EditsPrefix(word string) mapset.Set[string]

func (*SymSpell) EntryCount

func (s *SymSpell) EntryCount() int

func (*SymSpell) LoadBigramDictionary

func (s *SymSpell) LoadBigramDictionary(corpus io.Reader) bool

func (*SymSpell) LoadBigramDictionaryFile

func (s *SymSpell) LoadBigramDictionaryFile(corpus string) bool

func (*SymSpell) LoadDictionary

func (s *SymSpell) LoadDictionary(corpus io.Reader) bool

func (*SymSpell) LoadDictionaryFile

func (s *SymSpell) LoadDictionaryFile(corpus string) bool

func (*SymSpell) Lookup

func (s *SymSpell) Lookup(input string, verbosity verb.Verbosity, maxEditDistance int, includeUnknown bool) (Suggestions, error)

func (*SymSpell) LookupCompound

func (s *SymSpell) LookupCompound(input string) *Suggestions

LookupCompound supports compound aware automatic spelling correction of multi-word input strings with three cases: 1. mistakenly inserted space into a correct word led to two incorrect terms 2. mistakenly omitted space between two correct words led to one incorrect combined term 3. multiple independent input terms with/without spelling errors

func (*SymSpell) LookupCompoundWithEditDistance

func (s *SymSpell) LookupCompoundWithEditDistance(input string, editDistance int) *Suggestions

func (*SymSpell) LookupDefault

func (s *SymSpell) LookupDefault(input string, verbosity verb.Verbosity) (Suggestions, error)

func (*SymSpell) LookupEditDistance

func (s *SymSpell) LookupEditDistance(input string, verbosity verb.Verbosity, maxEditDistance int) (Suggestions, error)

func (*SymSpell) ParseWords

func (s *SymSpell) ParseWords(text string) []string

ParseWords creates a non-unique wordlist from sample text language independent (e.g. works with Chinese characters)

func (*SymSpell) PurgeBelowThresholdWords

func (s *SymSpell) PurgeBelowThresholdWords()

func (*SymSpell) WordCount

func (s *SymSpell) WordCount() int

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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