Search code examples
c#.netmaui

I am trying to check if a word exists in the English dictionary using C# on .NET


I am currently using NetSpell but I am running into many FileNotFound exceptions when I run the code:

NetSpell.SpellChecker.Spelling spellCheck = new NetSpell.SpellChecker.Spelling(); 
spellCheck.Dictionary = dict; 

if (!spellCheck.TestWord(wordIn)) 
{ 
    return false; 
} 

return true;

Any idea where I am going wrong? The library does now initialise correctly (had a couple of issues with that before), I am open to suggestions for other libraries as well as potential fixes :) TIA.


Solution

  • I managed to solve this problem with symspell. Download it from nuget, then use this code:

    var symSpell = new SymSpell();
    
    string dictionaryPath = "frequency_dictionary_en_82_765.txt";
    symSpell.LoadDictionary(dictionaryPath, 0, 1);
    
    var suggestions = symSpell.Lookup("YOUR WORD", SymSpell.Verbosity.Closest, 1);
    
    if (suggestions[0].distance == 0)
    {
        // word found !
    }
    else
    {
        // word not found
    }
    

    By installing the package it will put 2 txt files in your project. Move them into the folder of the executable file. (bin/Debug/net8.0/)