Documentation
¶
Index ¶
- func AddDic(gs *GoSpell, name string, paths []string) error
- func SearchPaths() []string
- type Checker
- type GoSpell
- func (g *GoSpell) AddDictionaryFile(dicFile string) error
- func (g *GoSpell) AddDictionaryReader(dic io.Reader) error
- 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 MutationOptions
- type MutationSuggester
- type Suggestion
- type SuggestionSource
- type Suggestions
- type WordList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddDic ¶ added in v0.9.2
AddDic finds a .dic file by searching paths and merges it into gs using AddDictionaryFile. Affix rules from gs are reused, so inflected forms (e.g. "colors" from "color/S") are recognized. The .dic file must be UTF-8.
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) AddDictionaryFile ¶ added in v0.9.2
AddDictionaryFile opens dicFile and calls AddDictionaryReader.
func (*GoSpell) AddDictionaryReader ¶ added in v0.9.2
AddDictionaryReader merges an additional Hunspell .dic file into this GoSpell, applying the same affix rules as the base dictionary. The file must be UTF-8 encoded. The word-count header line is optional: if the first line cannot be parsed as an integer it is treated as a word entry.
Intended for load-time use; not safe for concurrent calls with Spell or Suggest.
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 MutationOptions ¶
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 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.