Documentation
¶
Index ¶
- Constants
- Variables
- type FilterFunc
- type Match
- type OptionFunc
- type ScoreFuncdeprecated
- type Spellchecker
- func (m *Spellchecker) Add(words ...string)
- func (m *Spellchecker) AddFrom(input io.Reader) error
- func (m *Spellchecker) AddWeight(weight uint, words ...string)
- func (s *Spellchecker) Fix(word string) (string, error)
- func (s *Spellchecker) IsCorrect(word string) bool
- func (m *Spellchecker) Save(w io.Writer) error
- func (s *Spellchecker) Suggest(word string, n int) ([]string, error)
- func (s *Spellchecker) SuggestScore(word string, n int) SuggestionResult
- func (s *Spellchecker) WithOpts(opts ...OptionFunc) error
- type SuggestionResult
Constants ¶
const DefaultAlphabet = "abcdefghijklmnopqrstuvwxyz"
const DefaultMaxErrors = 2
Variables ¶
var ErrUnknownWord = fmt.Errorf("unknown word")
Functions ¶
This section is empty.
Types ¶
type FilterFunc ¶ added in v1.3.0
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 OptionFunc ¶
type OptionFunc func(s *Spellchecker) error
OptionFunc option setter
func WithFilterFunc ¶ added in v1.3.0
func WithFilterFunc(f FilterFunc) OptionFunc
WithFilterFunc set custom scoring function
func WithMaxErrors ¶ added in v0.1.0
func WithMaxErrors(maxErrors int) OptionFunc
WithMaxErrors sets maxErrors — 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.
func WithScoreFunc
deprecated
added in
v1.1.0
func WithScoreFunc(f ScoreFunc) OptionFunc
WithScoreFunc specify a function that will be used for scoring
Deprecated: use WithFilterFunc instead
func WithSplitter ¶
func WithSplitter(f bufio.SplitFunc) OptionFunc
WithSplitter set splitter func for AddFrom() reader
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, opts ...OptionFunc) (*Spellchecker, error)
func (*Spellchecker) Add ¶
func (m *Spellchecker) Add(words ...string)
Add adds provided words to the dictionary
func (*Spellchecker) AddFrom ¶
func (m *Spellchecker) AddFrom(input io.Reader) error
AddFrom reads input, splits it with spellchecker splitter func and adds words to the dictionary
func (*Spellchecker) AddWeight ¶ added in v1.2.0
func (m *Spellchecker) AddWeight(weight uint, words ...string)
AddWeight adds provided words to the dictionary with a custom weight
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) ([]string, error)
Suggest find top n suggestions for the word
func (*Spellchecker) SuggestScore ¶ added in v1.2.0
func (s *Spellchecker) SuggestScore(word string, n int) SuggestionResult
SuggestScore find top n suggestions for the word. Returns spellchecker scores along with words
func (*Spellchecker) WithOpts ¶
func (s *Spellchecker) WithOpts(opts ...OptionFunc) error
WithOpt set spellchecker options