spellcheck

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package spellcheck provides a fully offline spell- and grammar-checking engine. Every language pack — its dictionary and grammar rules — is embedded into the binary, so no text ever leaves the process.

Dictionaries under dict/ are word-frequency lists derived from the OpenSubtitles corpus (hermitdave/FrequencyWords, MIT-licensed). The frequency counts double as a ranking signal for spelling suggestions.

Adding a language: drop a "<code>.txt" frequency list under dict/, add a newXxx() constructor returning a *Language, and register it in init().

Index

Constants

View Source
const (
	TypeSpelling    = "spelling"
	TypeGrammar     = "grammar"
	TypePunctuation = "punctuation"
	TypeStyle       = "style"
)

Issue types reported to callers.

View Source
const DefaultLanguage = "en"

DefaultLanguage is used when a request omits or names an unknown language.

Variables

This section is empty.

Functions

func WordCount

func WordCount(text string) int

WordCount counts word tokens in text (language-independent).

Types

type Dictionary

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

Dictionary is a lazily-loaded word→frequency map. It backs two operations: membership testing (is a token a real word?) and ranking candidate corrections by how common the word is. Words are stored lowercased.

type Issue

type Issue struct {
	Offset       int
	Length       int
	Text         string
	Type         string
	Rule         string
	Message      string
	Replacements []string
}

Issue is a single detected problem in the input text. Offsets and lengths are expressed in runes so the frontend can map them onto the original string.

func Check

func Check(text, lang string) ([]Issue, string)

Check runs spelling and grammar checks over text in the given language. It returns the issues, the resolved language code, and (for symmetry with other engines) an error slot that is currently always nil.

type Language

type Language struct {
	Code  string
	Label string
	// contains filtered or unexported fields
}

Language is a self-contained pack: a dictionary, a spelling corrector built on it, and an ordered set of grammar rules.

type LanguageInfo

type LanguageInfo struct {
	Code  string
	Label string
}

LanguageInfo is the public description of an available language.

func Languages

func Languages() []LanguageInfo

Languages lists the available languages in registration order.

Jump to

Keyboard shortcuts

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