Documentation
¶
Index ¶
- Constants
- type AddOptions
- type FilterFunc
- type Match
- type SearchOptions
- type Spellchecker
- func (m *Spellchecker) Add(opts *AddOptions, words ...string)
- func (m *Spellchecker) AddFrom(opts *AddOptions, input io.Reader) error
- func (s *Spellchecker) Fix(opts *SearchOptions, word string) (string, bool)
- func (s *Spellchecker) IsCorrect(word string) bool
- func (m *Spellchecker) Save(w io.Writer) error
- func (s *Spellchecker) Suggest(opts *SearchOptions, word string, n int) SuggestionResult
- type SuggestionResult
Constants ¶
View Source
const DefaultAlphabet = "abcdefghijklmnopqrstuvwxyz"
View Source
const DefaultMaxErrors = 2
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddOptions ¶
type SearchOptions ¶
type SearchOptions struct {
// 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.
MaxErrors int
// 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.
FilterFunc FilterFunc
}
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(opts *AddOptions, words ...string)
Add adds provided words to the dictionary with a custom weight
func (*Spellchecker) AddFrom ¶
func (m *Spellchecker) AddFrom(opts *AddOptions, input io.Reader) error
AddFrom reads input, splits it with spellchecker splitter func and adds words to the dictionary
func (*Spellchecker) Fix ¶
func (s *Spellchecker) Fix(opts *SearchOptions, word string) (string, bool)
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(opts *SearchOptions, word string, n int) SuggestionResult
Suggest find top n suggestions for the word. Returns spellchecker scores along with words
type SuggestionResult ¶
Click to show internal directories.
Click to hide internal directories.