Documentation
¶
Index ¶
- Variables
- type Alphabet
- type Doc
- 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 ¶
This section is empty.
Variables ¶
View Source
var DefaultAlphabet = Alphabet{
Letters: "abcdefghijklmnopqrstuvwxyz",
Length: 26,
}
View Source
var ErrUnknownWord = fmt.Errorf("unknown word")
Functions ¶
This section is empty.
Types ¶
type Alphabet ¶
type Alphabet struct { // Letters to use in alphabet. Duplicates are not allowed Letters string // Length bit count to encode alphabet // If it is less than rune count in letters then // several letters will be encoded as one bit. // It decreases database size for a bit // but drastically reduces search performance in large dictionaries Length int }
type OptionFunc ¶
type OptionFunc func(m *Spellchecker) error
OptionFunc option setter
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 Alphabet, 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.