Documentation
¶
Index ¶
- func SearchPaths() []string
- type Checker
- type GoSpell
- func (s *GoSpell) AddWordRaw(word string) bool
- func (s *GoSpell) ForEachWord(fn func(word string) bool)
- func (s *GoSpell) HasWord(word string) bool
- func (s *GoSpell) InputConversion(raw []byte) string
- func (s *GoSpell) MaxWordLen() int
- func (s *GoSpell) SetSuggester(suggester Suggestions) error
- func (s *GoSpell) Spell(word string) bool
- func (s *GoSpell) Suggest(word string, limit int) ([]Suggestion, error)
- func (s *GoSpell) WordCount() int
- type LevenshteinOptions
- type LevenshteinSuggester
- type MutationOptions
- type MutationSuggester
- type Suggestion
- type SuggestionSource
- type Suggestions
- type SymSpellOptions
- type SymSpellSuggester
- type TrigramOptions
- type TrigramSuggester
- type WordList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SearchPaths ¶
func SearchPaths() []string
SearchPaths returns the ordered list of directories to search for named dictionaries. DICPATH (colon-separated, hunspell convention) is read first; standard system locations are appended as fallback. Callers may prepend their own tool-specific paths before passing the result to Open or OpenSupplement.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker combines a base GoSpell dictionary with zero or more WordLists. WordLists are consulted before the base dictionary: the first forbidden match rejects the word; the first allowed match accepts it; otherwise the base dictionary decides.
func NewChecker ¶
NewChecker creates a Checker backed by base.
func (*Checker) AddWordList ¶
AddWordList appends wl to the active word lists.
func (*Checker) InputConversion ¶
InputConversion applies the base dictionary's ICONV rules to raw input.
func (*Checker) RemoveWordList ¶
RemoveWordList removes wl from the active word lists by pointer identity.
func (*Checker) Suggest ¶
func (c *Checker) Suggest(word string, limit int) ([]Suggestion, error)
Suggest returns spelling suggestions. The base dictionary suggester provides the primary results; active WordLists are scanned with brute-force edit distance and merged into the final set.
Known limitation: words in active WordLists are not indexed by the base suggester. Only the brute-force scan covers them, which is fast given typical WordList sizes.
type GoSpell ¶
type GoSpell struct {
// contains filtered or unexported fields
}
GoSpell is main struct
func NewGoSpell ¶
NewGoSpell creates a GoSpell from Hunspell AFF and DIC file paths.
func NewGoSpellReader ¶
NewGoSpellReader creates a GoSpell from io.Readers for Hunspell AFF and DIC data.
func Open ¶
Open finds and loads a named base dictionary (.aff + .dic pair) by searching paths in order. name is a bare dictionary name ("en_US"), an absolute path, or a relative path containing a separator. The ".aff" or ".dic" extension is stripped if present. Returns a descriptive error if no matching pair is found in any of the provided paths.
func (*GoSpell) AddWordRaw ¶
AddWordRaw adds a single word to the internal dictionary without modifications. Returns true if added, false if already present.
func (*GoSpell) ForEachWord ¶
ForEachWord calls fn for every word in the dictionary. Iteration stops early if fn returns false.
func (*GoSpell) InputConversion ¶
InputConversion does any character substitution before checking based on the ICONV stanza in the AFF file.
func (*GoSpell) MaxWordLen ¶
MaxWordLen returns the longest loaded dictionary word length.
func (*GoSpell) SetSuggester ¶
func (s *GoSpell) SetSuggester(suggester Suggestions) error
SetSuggester configures the suggestion engine and initializes it from the current dictionary contents.
type LevenshteinOptions ¶
type LevenshteinOptions struct {
MaxDistance int
}
LevenshteinOptions controls the default brute-force suggestion engine.
type LevenshteinSuggester ¶
type LevenshteinSuggester struct {
// contains filtered or unexported fields
}
LevenshteinSuggester is a simple reference implementation that scans every loaded dictionary word and ranks candidates by edit distance.
func NewLevenshteinSuggester ¶
func NewLevenshteinSuggester(opts LevenshteinOptions) *LevenshteinSuggester
NewLevenshteinSuggester creates a brute-force suggester backed by agnivade/levenshtein.
func (*LevenshteinSuggester) Init ¶
func (s *LevenshteinSuggester) Init(src SuggestionSource) error
Init snapshots the current dictionary words.
func (*LevenshteinSuggester) Suggest ¶
func (s *LevenshteinSuggester) Suggest(word string, limit int) ([]Suggestion, error)
Suggest returns the best matches ordered by edit distance, then score, then lexicographic order.
type MutationOptions ¶
type MutationOptions struct {
CandidateCap int
}
MutationOptions controls the query-time mutation suggester.
type MutationSuggester ¶
type MutationSuggester struct {
// contains filtered or unexported fields
}
MutationSuggester generates one-edit candidates from the query word and checks each candidate directly against the dictionary. It does not build an inverted index up front.
func NewMutationSuggester ¶
func NewMutationSuggester(opts MutationOptions) *MutationSuggester
NewMutationSuggester creates a mutation-based suggester.
func (*MutationSuggester) Init ¶
func (s *MutationSuggester) Init(src SuggestionSource) error
Init stores the suggestion source for later membership checks.
func (*MutationSuggester) Suggest ¶
func (s *MutationSuggester) Suggest(word string, limit int) ([]Suggestion, error)
Suggest returns the best matches ordered by edit distance, then keyboard penalty, then lexicographic order.
type Suggestion ¶
Suggestion is a ranked candidate returned by a suggestion engine.
type SuggestionSource ¶
type SuggestionSource interface {
ForEachWord(func(word string) bool)
HasWord(word string) bool
WordCount() int
MaxWordLen() int
}
SuggestionSource provides read-only access to a loaded dictionary so a suggester can build indexes or other internal structures.
type Suggestions ¶
type Suggestions interface {
Init(src SuggestionSource) error
Suggest(word string, limit int) ([]Suggestion, error)
}
Suggestions is the pluggable suggestion engine interface used by GoSpell.
type SymSpellOptions ¶
SymSpellOptions controls the delete-index suggestion engine.
type SymSpellSuggester ¶
type SymSpellSuggester struct {
// contains filtered or unexported fields
}
SymSpellSuggester implements a SymSpell-style delete index.
The dictionary is indexed once by storing every word under the strings that can be produced by deleting up to MaxDistance runes from the first PrefixLength runes. Queries use the same delete generation to recover a small candidate set, which is then reranked by edit distance.
func NewSymSpellSuggester ¶
func NewSymSpellSuggester(opts SymSpellOptions) *SymSpellSuggester
NewSymSpellSuggester creates a delete-index suggester.
func (*SymSpellSuggester) Init ¶
func (s *SymSpellSuggester) Init(src SuggestionSource) error
Init snapshots the dictionary words and builds the delete index.
func (*SymSpellSuggester) Suggest ¶
func (s *SymSpellSuggester) Suggest(word string, limit int) ([]Suggestion, error)
Suggest returns the best matches ordered by edit distance, then word.
type TrigramOptions ¶
TrigramOptions controls the hashed-trigram suggestion engine.
type TrigramSuggester ¶
type TrigramSuggester struct {
// contains filtered or unexported fields
}
TrigramSuggester builds a hashed trigram inverted index once and then narrows candidates by postings-list overlap before reranking with Levenshtein.
func NewTrigramSuggester ¶
func NewTrigramSuggester(opts TrigramOptions) *TrigramSuggester
NewTrigramSuggester creates a trigram-index suggester.
func (*TrigramSuggester) Init ¶
func (s *TrigramSuggester) Init(src SuggestionSource) error
Init snapshots the dictionary and builds the trigram postings index.
func (*TrigramSuggester) Suggest ¶
func (s *TrigramSuggester) Suggest(word string, limit int) ([]Suggestion, error)
Suggest returns the best matches ordered by edit distance, then trigram score.
type WordList ¶
type WordList struct {
// contains filtered or unexported fields
}
WordList is a small overlay of allowed and forbidden words used as a per-context supplement to a base GoSpell dictionary. Multiple WordLists can be active simultaneously; see Checker. Loading policy — global or per-document — is the caller's responsibility.
Format (one entry per line):
# comment word → allowed *word → forbidden
func NewWordList ¶
NewWordList parses a WordList from r.
func NewWordListFile ¶
NewWordListFile parses a WordList from a file.
func NewWordListFromDic ¶
NewWordListFromDic parses a Hunspell .dic file from r and returns the word stems as an allowed WordList. The word-count header line is skipped; affix flags (the part after '/') are stripped from each entry.
This is distinct from NewWordList, which parses the personal word list format (plain words or *word for forbidden entries). Use NewWordListFromDic when loading a raw Hunspell .dic file as a vocabulary supplement.
func OpenSupplement ¶
OpenSupplement finds and loads a .dic-only domain supplement (no .aff file) by searching paths in order. The result is a WordList ready to attach to a Checker. Supplement dictionaries extend the vocabulary of a base dictionary with domain-specific terms (medical, legal, technical) without affix processing. Encoding is assumed UTF-8; for non-UTF-8 supplements use a full base dictionary (.aff + .dic) as the first entry instead.
func (*WordList) IsForbidden ¶
IsForbidden reports whether word is in the forbidden set.