Documentation
¶
Index ¶
- Constants
- type AddOptionFunc
- type FilterFunc
- type Match
- type SearchOptionFunc
- type Spellchecker
- func (m *Spellchecker) Add(word string, opts ...AddOptionFunc)
- func (m *Spellchecker) AddFrom(input io.Reader, opts ...AddOptionFunc) error
- func (m *Spellchecker) AddMany(words []string, opts ...AddOptionFunc)
- func (s *Spellchecker) IsCorrect(word string) bool
- func (m *Spellchecker) Save(w io.Writer) error
- func (s *Spellchecker) Suggest(word string, n int, opts ...SearchOptionFunc) SuggestionResult
- type SuggestionResult
Constants ¶
const DefaultAlphabet = "abcdefghijklmnopqrstuvwxyz"
const DefaultMaxErrors = 2
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddOptionFunc ¶
type AddOptionFunc func(opts *addOptions)
func AddWithSplitter ¶
func AddWithSplitter(splitter bufio.SplitFunc) AddOptionFunc
AddWithSplitter sets a splitter func for AddFrom() reader
func AddWithWeight ¶
func AddWithWeight(weight uint) AddOptionFunc
AddWithWeight sets weight for added words. The weight increases the likelihood that the word will be chosen as a correction.
type FilterFunc ¶
FilterFunc compares the source word with a candidate word. It returns the candidate's score and a boolean flag. If the flag is false, the candidate will be completely filtered out.
type SearchOptionFunc ¶
type SearchOptionFunc func(opts *searchOptions)
func SuggestWithFilterFunc ¶
func SuggestWithFilterFunc(f FilterFunc) SearchOptionFunc
SuggestWithFilterFunc set a FilterFunc
func SuggestWithMaxErrors ¶
func SuggestWithMaxErrors(maxErrors int) SearchOptionFunc
SuggestWithMaxErrors sets the maximum allowed difference in bits between the "search word" and a "dictionary word". - deletion is a 1-bit change (proble → problem) - insertion is a 1-bit change (problemm → problem) - substitution is a 2-bit change (problam → problem) - transposition is a 0-bit change (problme → problem)
It is not recommended to set this value greater than 2, as it can significantly affect performance.
type Spellchecker ¶
type Spellchecker struct {
// contains filtered or unexported fields
}
func Load ¶
func Load(reader io.Reader) (*Spellchecker, error)
Load reads spellchecker data from the provided reader and decodes it
func New ¶
func New(alphabet string) (*Spellchecker, error)
func (*Spellchecker) Add ¶
func (m *Spellchecker) Add(word string, opts ...AddOptionFunc)
Add adds provided word to the dictionary
func (*Spellchecker) AddFrom ¶
func (m *Spellchecker) AddFrom(input io.Reader, opts ...AddOptionFunc) error
AddFrom reads input, splits it with spellchecker splitter func and adds words to the dictionary
func (*Spellchecker) AddMany ¶
func (m *Spellchecker) AddMany(words []string, opts ...AddOptionFunc)
AddMany adds provided words to the dictionary
func (*Spellchecker) IsCorrect ¶
func (s *Spellchecker) IsCorrect(word string) bool
IsCorrect check if provided word is in the dictionary
func (*Spellchecker) Save ¶
func (m *Spellchecker) Save(w io.Writer) error
Save encodes spellchecker data and writes it to the provided writer
func (*Spellchecker) Suggest ¶
func (s *Spellchecker) Suggest(word string, n int, opts ...SearchOptionFunc) SuggestionResult
Suggest find top n suggestions for the word. Returns spellchecker scores along with words