spellcheck

package module
v0.0.0-...-5584e1a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2023 License: MIT Imports: 4 Imported by: 2

README

spellcheck

Simple Spell Checker Package for Go

This is a simple spellchecker package for the Go programming language. It allows you to check the spelling of words in English. It also provides suggestions for misspelled words.

Installation

To install the package, simply run the following command:

go get github.com/makifdb/spellcheck

Usage

To use the package, simply import it into your project and create a new spellchecker instance. You can then use the spellchecker to check the spelling of words and get suggestions for misspelled words. You can also insert new words into the dictionary.

package main

import (
	"fmt"

	"github.com/makifdb/spellcheck"
)

func main() {
	// Init spellchecker
	sc, err := spellcheck.New()
	if err != nil {
		fmt.Println(err)
	}

	// Check spelling of a word
	ok := sc.SearchDirect("hllo")
	if !ok {
		fmt.Println("Word is misspelled or not in dictionary")
	}

	// Check spelling of a word and get suggestions
	ok, suggestions := sc.Search("hllo")
	if !ok {
		fmt.Println("Word is misspelled or not in dictionary")
		if len(suggestions) > 0 {
			fmt.Println("Did you mean: ", suggestions)
		}
	}

	// Insert a word into the dictionary
	sc.Insert("hllo")
}

License

This package is licensed under the MIT license. See the LICENSE file for more details.

Documentation

Index

Constants

View Source
const (
	// DEFAULT_ALPHABET is the default alphabet used for generating variations
	DEFAULT_ALPHABET = "abcdefghijklmnopqrstuvwxyz"
	// DEFAULT_REMOTE_WORDS_URL is the default url containing the words
	DEFAULT_REMOTE_WORDS_URL = "https://raw.githubusercontent.com/makifdb/spellcheck/main/words.txt"
	// DEFAULT_DEPTH is the default depth used for generating variations
	DEFAULT_DEPTH = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LetterNode

type LetterNode struct {
	// contains filtered or unexported fields
}

type Trie

type Trie struct {

	// mutex is used for locking the trie
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New() (*Trie, error)

New creates a new trie and populates it with the words

func (*Trie) Insert

func (t *Trie) Insert(word string)

Insert adds a word to the trie

func (*Trie) InsertReader

func (t *Trie) InsertReader(r io.Reader) *bufio.Scanner

InsertReader adds words from a reader to the trie

func (*Trie) Search

func (t *Trie) Search(word string) (bool, []string)

Search checks if a word is in the trie and returns with a list of suggestions

func (*Trie) SearchDirect

func (t *Trie) SearchDirect(word string) bool

SearchDirect checks if a word is in the trie

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL