Table of Contents

Class SpellCorrection<T>

Namespace
AiDotNet.Postprocessing.Document
Assembly
AiDotNet.dll

SpellCorrection - Spell checking and correction for OCR output.

public class SpellCorrection<T> : PostprocessorBase<T, string, string>, IPostprocessor<T, string, string>, IDisposable

Type Parameters

T

The numeric type for calculations.

Inheritance
SpellCorrection<T>
Implements
Inherited Members

Remarks

SpellCorrection provides spell checking and automatic correction capabilities specifically designed for OCR output, which has different error patterns than normal typing errors.

For Beginners: OCR systems often misread characters, resulting in misspelled words. This tool corrects them:

  • Detects misspelled words
  • Suggests corrections based on edit distance
  • Uses context for better accuracy
  • Handles domain-specific vocabulary

Key features:

  • Edit distance-based suggestions
  • Custom dictionary support
  • Context-aware correction
  • OCR-specific error patterns

Example usage:

var corrector = new SpellCorrection<float>();
var corrected = corrector.Process(ocrText);

Constructors

SpellCorrection()

Creates a new SpellCorrection instance with default settings.

public SpellCorrection()

SpellCorrection(int)

Creates a new SpellCorrection instance with specified max edit distance.

public SpellCorrection(int maxEditDistance)

Parameters

maxEditDistance int

Maximum edit distance for suggestions.

Properties

SupportsInverse

Spell correction does not support inverse transformation.

public override bool SupportsInverse { get; }

Property Value

bool

Methods

AddToDictionary(IEnumerable<string>)

Adds multiple words to the custom dictionary.

public void AddToDictionary(IEnumerable<string> words)

Parameters

words IEnumerable<string>

AddToDictionary(string)

Adds a word to the custom dictionary.

public void AddToDictionary(string word)

Parameters

word string

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Releases resources used by the spell corrector.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

GetSuggestions(string, int)

Gets correction suggestions for a misspelled word.

public IList<string> GetSuggestions(string word, int maxSuggestions = 5)

Parameters

word string
maxSuggestions int

Returns

IList<string>

IsCorrect(string)

Checks if a word is spelled correctly.

public bool IsCorrect(string word)

Parameters

word string

Returns

bool

LoadDictionary(IEnumerable<string>)

Loads a custom dictionary from words.

public void LoadDictionary(IEnumerable<string> words)

Parameters

words IEnumerable<string>

ProcessCore(string)

Corrects spelling errors in the text.

protected override string ProcessCore(string input)

Parameters

input string

The text to correct.

Returns

string

The corrected text.

ValidateInput(string)

Validates the input text.

protected override void ValidateInput(string input)

Parameters

input string