Nhunspell C # Adding a Word to a Dictionary

I 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 way to do this inside NHunspell, which I believe looks like this:

// 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, it doesn't seem to be doing anything. Can anyone tell me what I'm doing wrong?

thanks

+4
source share
2 answers

I did not understand that adding a word using the .Add () method allows you to use this word only if the Hunspell object is alive. The word is not added to the external dictionary file. The way to deal with this problem was to use a custom dictionary file. When a word is added by the user, this word is stored in a new user dictionary file. Now, when my main spell-checking function is called, before all words are checked, all words that are in the user dictionary are added using the .Add () method. Hope this helps.

+9
source

Adding a word to the dictionary simply adds a new word to any text file using WriteLine() of StreamWriter .

 private void button1_Click(object sender, EventArgs e) { FileWriter(txtDic.Text, txtWord.Text, true); txtWord.Clear(); MessageBox.Show("Success..."); } public static void FileWriter(string filePath, string text, bool fileExists) { if (!fileExists) { FileStream aFile = new FileStream(filePath, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(aFile); sw.WriteLine(text); sw.Close(); aFile.Close(); } else { FileStream aFile = new FileStream(filePath, FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(aFile); sw.WriteLine(text+"/3"); sw.Close(); aFile.Close(); //System.IO.File.WriteAllText(filePath, text); } } 
+1
source

Source: https://habr.com/ru/post/1397783/


All Articles