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
TThe 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
maxEditDistanceintMaximum edit distance for suggestions.
Properties
SupportsInverse
Spell correction does not support inverse transformation.
public override bool SupportsInverse { get; }
Property Value
Methods
AddToDictionary(IEnumerable<string>)
Adds multiple words to the custom dictionary.
public void AddToDictionary(IEnumerable<string> words)
Parameters
wordsIEnumerable<string>
AddToDictionary(string)
Adds a word to the custom dictionary.
public void AddToDictionary(string word)
Parameters
wordstring
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
disposingbool
GetSuggestions(string, int)
Gets correction suggestions for a misspelled word.
public IList<string> GetSuggestions(string word, int maxSuggestions = 5)
Parameters
Returns
IsCorrect(string)
Checks if a word is spelled correctly.
public bool IsCorrect(string word)
Parameters
wordstring
Returns
LoadDictionary(IEnumerable<string>)
Loads a custom dictionary from words.
public void LoadDictionary(IEnumerable<string> words)
Parameters
wordsIEnumerable<string>
ProcessCore(string)
Corrects spelling errors in the text.
protected override string ProcessCore(string input)
Parameters
inputstringThe text to correct.
Returns
- string
The corrected text.
ValidateInput(string)
Validates the input text.
protected override void ValidateInput(string input)
Parameters
inputstring