Documentation
¶
Overview ¶
Package spellio provides a trie structure for storing words and their frequencies and later spell checking and correction.
The trie is optimized for fast lookup and traversal. It is also optimized for space efficiency.
Index ¶
- type Engine
- func (e *Engine) CompleteWord(prefix string, limit int) []*Word
- func (e *Engine) CorrectWord(rawWord string, layout KeyboardLayout, limit int) []*Word
- func (e *Engine) CountWords() int
- func (e *Engine) FindWord(word string) (*Word, bool)
- func (e *Engine) GetNearbyWords(rawWord string, maxChanges int, layout KeyboardLayout) []NearbyWord
- func (e *Engine) GetWordsByPrefix(prefix string) []*Word
- func (e *Engine) Insert(word string)
- func (e *Engine) InsertFromText(reader io.Reader)
- func (e *Engine) OutputAllWords(writer io.Writer) error
- type KeyboardLayout
- type NearbyWord
- type Word
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
An Engine is a trie structure that stores information about words and their frequencies.
Zero value is a valid empty Engine.
func (*Engine) CompleteWord ¶
CompleteWord returns a list of words that start with the given prefix.
The list is sorted by frequency in descending order and can be limited by the given limit.
func (*Engine) CorrectWord ¶
func (e *Engine) CorrectWord(rawWord string, layout KeyboardLayout, limit int) []*Word
CorrectWord returns a list of words that are similar to the given word.
The list is sorted by the number of changes in ascending order and their frequency in descending order. The list can be limited by the given limit parameter.
The number of allowed changes is calculated as the length of the word divided by the 3.
func (*Engine) CountWords ¶
CountWords returns the number of words in the dictionary.
func (*Engine) FindWord ¶
FindWord will try to find a word in the Engine.
If the word is found, the Word and true are returned. If the word is not found, an empty Word and false are returned.
func (*Engine) GetNearbyWords ¶
func (e *Engine) GetNearbyWords(rawWord string, maxChanges int, layout KeyboardLayout) []NearbyWord
GetNearbyWords returns all words in the dictionary that are near the given word and can be transformed into it with the given number of changes.
func (*Engine) GetWordsByPrefix ¶
GetWordsByPrefix returns all words in the dictionary that start with the given prefix.
func (*Engine) Insert ¶
Insert adds a word to the Engine. If the word already exists, its frequency is incremented.
The word is converted to lowercase before being inserted.
func (*Engine) InsertFromText ¶
InsertFromText reads words from a reader and inserts them into the Engine.
Words will be separated by a space character, cleaned of non-alphabetic characters and converted to lowercase before being inserted.
type KeyboardLayout ¶ added in v0.2.0
A KeyboardLayout is a map of characters to characters that are nearby on the keyboard and are considered as possible replacements.
type NearbyWord ¶ added in v0.2.0
A NearbyWord contains the word and the number of changes required to transform it into the original word.