SpellChecker class

Namespace Runic.Spelling in Runic.Spelling 0.23.0-preview.1

public sealed class SpellChecker

Checks spelling with one Hunspell dictionary and the words the application and the user know. Safe to use from several threads. A dictionary is read once and shared by every checker of it.

Remarks

Words are runs of letters, with apostrophes (straight or curly) and hyphens between letters. A word of words joined by hyphens, such as sea-glass, is right when each part is, and each wrong part is marked on its own.

Not checked: the ranges the caller names, web and mail addresses, words with digits, single letters, and words of up to SpellChecker.AcronymLength letters all in capitals, such as NATO.

Fields

AcronymLength

public const int AcronymLength = 6

The longest word all in capitals that is taken as an abbreviation and not checked.

Properties

Dictionary

public SpellingDictionary Dictionary { get; }

The dictionary it checks with.

Methods

Check

public IReadOnlyList<Misspelling> Check(string text, IReadOnlyList<SpellingRange>? skip = null)

The words text spells wrong, in its order, outside skip.

Parameters

text

The text, such as a message or a paragraph.

skip

Ranges of text not to check, such as placeholders and markup, in any order; they may overlap. A word is never taken across one: the text on each side is checked on its own.

Exceptions

ArgumentOutOfRangeException

A range is not inside text.

IsKnown

public bool IsKnown(string word)

Whether word is spelled right: a known word, the user's, or the dictionary's; or one the checker does not check, such as an abbreviation.

LoadAsync

public static Task<SpellChecker> LoadAsync(SpellingDictionary dictionary, SpellCheckerOptions? options = null, CancellationToken cancellationToken = default)

Reads dictionary, or takes it from an earlier read, and makes a checker of it.

Exceptions

IOException

Its files could not be read.

InvalidDataException

A downloaded dictionary's files are not the ones it was installed with; download it again.

Suggest

public IReadOnlyList<string> Suggest(string word)

What word may have been meant as: the known and the user's words close to it first, then the dictionary's suggestions; at most eight.

WithKnownWords

public SpellChecker WithKnownWords(IEnumerable<string> knownWords)

A checker of the same dictionary and user's words that knows knownWords in place of this one's known words, such as when a project's words change.