Skip to content

alehano/typograph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Typograph Package

A comprehensive text correction package for Go that combines spell checking with punctuation and grammar correction.

Features

  • Spell Checking: Uses fuzzy matching to suggest corrections for misspelled words
  • Punctuation Correction: Fixes spacing around punctuation marks
  • Capitalization: Properly capitalizes sentences and after periods
  • Article Correction: Fixes "a" vs "an" usage
  • Sentence Structure: Improves overall text flow and readability

Installation

go get github.com/sajari/fuzzy

Usage

Basic Usage

package main

import (
    "fmt"
    "your-module/typograph"
)

func main() {
    // Create a new typograph instance
    tg := typograph.New()

    // Add words to the dictionary
    words := []string{"hello", "world", "example", "text"}
    tg.AddWords(words)

    // Correct text
    text := "hello world this is an test"
    corrected := tg.CorrectText(text)
    fmt.Println(corrected) // "Hello world this is a test."
}

Advanced Usage

// Check if a word is correct
isCorrect := tg.IsCorrect("helo") // false

// Get suggestions for a word
suggestions := tg.GetSuggestions("helo", 3) // ["hello"]

// Correct comprehensive text
text := "i hope this email reaches you in good health, after careful consideration,i have decided to take the difficult decision of resigning from my post.to be honest this was not an easy decision."
corrected := tg.CorrectText(text)
// Result: "I hope this email reaches you in good health, after careful consideration have decided to take the difficult decision of resigning from my post. To be honest this was not an easy decision."

API Reference

New()

Creates a new Typograph instance with default settings.

AddWords(words []string)

Adds words to the spellchecker dictionary.

CorrectText(text string) string

Performs comprehensive text correction including spelling, punctuation, and grammar.

IsCorrect(word string) bool

Checks if a word is spelled correctly.

GetSuggestions(word string, maxSuggestions int) []string

Returns spelling suggestions for a word.

Dependencies

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages