Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nhunspell C# Adding Word to Dictionary

I have managed to incorporate spell checking into my C# project using NHunspell. What I would like to do is actually add a word to the dictionary file. There is a method to do this inside of NHunspell which I believe is as follows:

// Add the word to the dictionary and carry on
using (Hunspell hunspell = new Hunspell(@"Dictionaries/en_GB.aff", @"Dictionaries/en_GB.dic"))
{
    hunspell.Add("wordToAdd");                
}

When I use this however it does not appear to actually do anything. Would anyone be able to suggest what it is I am doing wrong?

Thanks

like image 258
Jpin Avatar asked Dec 28 '22 05:12

Jpin


1 Answers

I did not realise that adding a word using the .Add() method only allows that word to be used while the Hunspell object is alive. The word is not actually added to the external dictionary file. The way I combated this problem was to make use of a custom dictionary file. When a word is added by the user this word is stored in the new custom dictionary file. Now when my main spell checker function is called, before any words are checked all the words which are in the custom dictionary are added using the .Add() method. Hope this helps.

like image 131
Jpin Avatar answered Jan 24 '23 18:01

Jpin