Using Custom Dictionary to Hook up 3rd party Spell Checker Engine

If you are not satisified with the built in NetSpell or NHunspell Spell checker engine and if you want to hook up any 3rd party Spell checker engine, then you can do that too. The editor offers an interface named ISpellCheckerEngine. You can simply implement this interface using your 3rd party Spell checker engine. After that, you need to set the property SpellCheckOptions.CustomSpellCheckerEngine = an instance of the implementation of ISpellCheckerEngine. Also, you need to set the SpellChecker property = Custom within Spell Checker Option.

C#

public interface ISpellCheckerEngine
{
    /// <summary>
    /// Initialize engine using specified <see cref="dictionaryPath"/> and <see cref="affixPath"/>
    /// </summary>
    /// <param name="dictionaryPath">Relative or rooted dictionary file path</param>
    /// <param name="affixPath">Relative or rooted affix file path</param>
    /// <param name="userDictionaryPath">Relative or rooted user dictionary path (or null if user dictionary disabled)</param>
    void Initialize(string dictionaryPath, string affixPath, string userDictionaryPath);

    /// <summary>
    /// Spell <see cref="word"/>
    /// </summary>
    /// <param name="word">Word to check</param>
    /// <returns><value>true</value> if the word is correct, <value>false</value>otherwise</returns>
    bool Spell(string word);

    /// <summary>
    /// Suggest words, that are similar to <see cref="word"/>
    /// </summary>
    /// <param name="word"></param>
    /// <param name="max">Maximum number of suggestions to return</param>
    /// <returns></returns>
    IEnumerable<string> Suggest(string word, int? max = null);

    /// <summary>
    /// Add new word into user dictionary
    /// </summary>
    /// <param name="word"></param>
    void AddToUserDictionary(string word);

    /// <summary>
    /// Clear all engine resources
    /// </summary>
    void Dispose();
}

VB

Public Interface ISpellCheckerEngine
	''' <summary>
	''' Initialize engine using specified <see cref="dictionaryPath"/> and <see cref="affixPath"/>
	''' </summary>
	''' <param name="dictionaryPath">Relative or rooted dictionary file path</param>
	''' <param name="affixPath">Relative or rooted affix file path</param>
	''' <param name="userDictionaryPath">Relative or rooted user dictionary path (or null if user dictionary disabled)</param>
	Sub Initialize(dictionaryPath As String, affixPath As String, userDictionaryPath As String)

	''' <summary>
	''' Spell <see cref="word"/>
	''' </summary>
	''' <param name="word">Word to check</param>
	''' <returns><value>true</value> if the word is correct, <value>false</value>otherwise</returns>
	Function Spell(word As String) As Boolean

	''' <summary>
	''' Suggest words, that are similar to <see cref="word"/>
	''' </summary>
	''' <param name="word"></param>
	''' <param name="max">Maximum number of suggestions to return</param>
	''' <returns></returns>
	Function Suggest(word As String, Optional max As System.Nullable(Of Integer) = Nothing) As IEnumerable(Of String)

	''' <summary>
	''' Add new word into user dictionary
	''' </summary>
	''' <param name="word"></param>
	Sub AddToUserDictionary(word As String)

	''' <summary>
	''' Clear all engine resources
	''' </summary>
	Sub Dispose()
End Interface

Custom spell checker

C#

private void Window1_OnLoaded(object sender, RoutedEventArgs e)
{
    wpfHtmlEditor1.SpellCheckOptions.CustomSpellCheckerEngine = new CustomSpellCheckerEngine();
}

VB

Private Sub Window1_OnLoaded(sender As Object, e As RoutedEventArgs)
	wpfHtmlEditor1.SpellCheckOptions.CustomSpellCheckerEngine = New CustomSpellCheckerEngine()
End Sub

These are the 3 steps you need to follow in order to hook up the 3rd party Spell checker Engine. You will find a working sample of a demo implementation of ISpellCheckerEngine in the download package's Sample Projects folder (Sample Projects\Custom Spell Checker). Please check that sample project to fully understand how you can implement the interface.

Custom spell checker in samples folder

Last updated on May 30, 2015