TXSpell
Not every text that needs checking is in a window. A service that validates form input, a batch job that checks documents before they are published, or the server behind the Document Editor of TX Text Control .NET Server needs spell checking without dialogs or menus. TXSpell is the class for that: the spell checking engine of TX Spell .NET without a user interface.
What TXSpell Is
The class is TXTextControl.Proofing.TXSpell. It checks text, creates suggestions, hyphenates words, looks up synonyms and detects languages, with the same language data as the TXSpellChecker component. It has no dialogs, no context menu items and no events: your code calls a method and reads the result.
The Two Classes compares it with TXSpellChecker. Use TXSpellChecker when a Windows Forms control shows the text; the class description in the reference recommends it for text components. Use TXSpell everywhere else.
Where It Runs
TXSpell is in TXSpell.dll, the assembly that all TX Spell .NET packages share. The package TXTextControl.TXSpell.Core.SDK contains only this assembly, its German resources, the license file and the US English language data. It targets .NET 8 and doesn't depend on TX Text Control or any other package, so it runs in:
- console applications, services and ASP.NET Core applications;
- on Windows and on Linux, for example in a Docker container;
- together with the
ServerTextControland the Document Editor of TX Text Control .NET Server.
The setup of TX Spell .NET for Windows Forms provides the package through the package source Text Control Offline Packages. Without TX Text Control, an application that uses it is published without a target runtime. The blog article Document Editor with TX Spell .NET on Linux using ASP.NET Core runs it in a Linux container.
How You Work With It
- Create an instance and call Create. It loads the language data; before it, every check throws an exception that asks for it.
- Call a method: Check, CreateSuggestions, GetHyphenationPoints, CreateSynonyms or DetectLanguageScopes.
- Read the result from the matching property, such as IncorrectWords or Suggestions.
TXSpell doesn't implement IDisposable, so it needs no using statement. With TX Text Control .NET Server, assign the instance to the SpellChecker property of a ServerTextControl, which then finds the misspelled words and hyphenates documents in code.
Example
A console application that checks a sentence and prints suggestions for each misspelled word needs only a few lines: create a TXSpell, call Create, Check the text and CreateSuggestions for each entry of IncorrectWords. Checking Text in Code builds this application step by step, from creating the project to running it, shows its output and uses it in a .NET Framework project, too.
Key Members
| Member | Purpose |
|---|---|
| Create | Loads the language data; call it first |
| Check, IncorrectWords | Check a text, and the words found |
| CreateSuggestions, Suggestions | Suggestions for a word |
| IgnoreWord, IgnoreCase | Which words are skipped |
| Dictionaries, Language | The dictionaries, and the default one |
| GetHyphenationPoints, HyphenationLists | Hyphenation points of a word |
| CreateSynonyms, SynonymLists | Synonyms of a word |
| DetectLanguageScopes, LanguageScopes | The languages of a text |
| DictionariesDirectoryPath | The folder of the dictionaries, and like it the folders of the other language data |
The TXSpell reference lists all members.
Next Steps
- Checking Text in Code: the console application, step by step.
- Incorrect Words and Suggestions: the results of
CheckandCreateSuggestions. - Hyphenating Text in Code: hyphenation points of words.
- TXSpellChecker: the component with a user interface.