Documentation ¶
Index ¶
- Constants
- Variables
- type OptionFunc
- type Spellchecker
- func (m *Spellchecker) Add(words ...string)
- func (m *Spellchecker) AddFrom(input io.Reader) error
- 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) WithOpts(opts ...OptionFunc) error
Constants ¶
View Source
const DefaultAlphabet = "abcdefghijklmnopqrstuvwxyz"
View Source
const DefaultMaxErrors = 2
Variables ¶
View Source
var ErrUnknownWord = fmt.Errorf("unknown word")
Functions ¶
This section is empty.
Types ¶
type OptionFunc ¶
type OptionFunc func(m *Spellchecker) error
OptionFunc option setter
func WithMaxErrors ¶ added in v0.1.0
func WithMaxErrors(maxErrors int) OptionFunc
WithMaxErrors set maxErrors, which is a max diff in bits betweeen the "search word" and a "dictionary word". i.e. one simple symbol replacement (problam => problem ) is a two-bit difference
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 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 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) ([]string, error)
Suggest find top n suggestions for the word
func (*Spellchecker) WithOpts ¶
func (s *Spellchecker) WithOpts(opts ...OptionFunc) error
WithOpt set spellchecker options
Click to show internal directories.
Click to hide internal directories.