Documentation ¶
Overview ¶
Package spell provides functions for spell check and correction. It wraps https://github.com/sajari/fuzzy as the core spelling engine.
A single globally usable spelling dictionary is managed.
Index ¶
- Constants
- func CheckLexLine(src []rune, tags lexer.Line) lexer.Line
- func Edits1(word string) []string
- func Levenshtein(a, b *string) int
- type Dict
- type Model
- type Pair
- type SpellData
- func (sp *SpellData) AddWord(word string)
- func (sp *SpellData) CheckWord(word string) ([]string, bool)
- func (sp *SpellData) DeleteWord(word string)
- func (sp *SpellData) IgnoreWord(word string)
- func (sp *SpellData) OpenUser() error
- func (sp *SpellData) OpenUserCheck() error
- func (sp *SpellData) ResetLearnTime()
- func (sp *SpellData) SaveUser() error
- func (sp *SpellData) SaveUserIfLearn() error
Constants ¶
const SaveAfterLearnIntervalSecs = 20
SaveAfterLearnIntervalSecs is number of seconds since dict file has been opened / saved above which model is saved after learning.
Variables ¶
This section is empty.
Functions ¶
func CheckLexLine ¶
CheckLexLine returns the Lex regions for any words that are misspelled within given line of text with existing Lex tags -- automatically excludes any Code token regions (see token.IsCode). Token is set to token.TextSpellErr on returned Lex's
func Levenshtein ¶
Calculate the Levenshtein distance between two strings
Types ¶
type Dict ¶ added in v0.2.1
type Dict map[string]struct{}
func NewDictFromList ¶ added in v0.2.1
NewDictFromList makes a new dictionary from given list (slice) of words
func OpenDict ¶ added in v0.2.1
OpenDict opens a dictionary list of words from a simple one-word-per-line list
func OpenDictFS ¶ added in v0.2.1
OpenDictFS opens a dictionary list of words from a simple one-word-per-line list, from given filesystem
type Model ¶
type Model struct { // list of all words, combining Base and User dictionaries Dict Dict // user dictionary of additional words UserDict Dict // words to ignore for this session Ignore Dict // map of misspelled word to potential correct spellings Suggest map[string][]string // depth of edits to include in Suggest map (2 is only sensible value) Depth int sync.RWMutex }
Model is the full data model
func (*Model) AddWord ¶ added in v0.2.1
AddWord adds a new word to user dictionary, and generates new suggestions for it
func (*Model) EditsMulti ¶
Edits at any depth for a given term. The depth of the model is used
type SpellData ¶ added in v0.2.1
type SpellData struct { // UserFile is path to user's dictionary where learned words go UserFile string // contains filtered or unexported fields }
var Spell *SpellData
Spell is the global shared spell
func (*SpellData) CheckWord ¶ added in v0.2.1
CheckWord checks a single word and returns suggestions if word is unknown. bool is true if word is in the dictionary, false otherwise.
func (*SpellData) DeleteWord ¶ added in v0.2.1
DeleteWord removes word from dictionary, in case accidentally added
func (*SpellData) IgnoreWord ¶ added in v0.2.1
IgnoreWord adds the word to the Ignore list
func (*SpellData) OpenUserCheck ¶ added in v0.2.1
OpenUserCheck checks if the current user dict file has been modified since last open time and re-opens it if so.
func (*SpellData) ResetLearnTime ¶ added in v0.2.1
func (sp *SpellData) ResetLearnTime()
func (*SpellData) SaveUser ¶ added in v0.2.1
SaveUser saves the user dictionary note: this will overwrite any existing file; be sure to have opened the current file before making any changes.
func (*SpellData) SaveUserIfLearn ¶ added in v0.2.1
SaveUserIfLearn saves the user dictionary if learning has occurred since last save / open. If no changes also checks if file has been modified and opens it if so.