My Technical Notes

Tuesday, 20 June 2017

Spell Checking in C# using NetSpell

Using the NetSpell NuGet package, the following C# code, checks the spelling of the word `stop` using the English US dictionary. Check its NuGet package folder for a `dic` folder that contains different dictionaries.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CheckSpelling
{
    class Program
    {
        static void Main(string[] args)
        {
            var DICTIONARY_DIR = @"C:\_code\CheckSpelling\packages\NetSpell.2.1.7\dic";
            var usDictionary = new NetSpell.SpellChecker.Dictionary.WordDictionary()
            {
                DictionaryFolder = DICTIONARY_DIR,
                DictionaryFile = "en-US.dic"
            };

            usDictionary.Initialize();

            var usSpellChecker = new NetSpell.SpellChecker.Spelling
            {
                Dictionary = usDictionary
            };

            var correct = usSpellChecker.TestWord("stop");
        }
    }
}

No comments: