C#检查一个单词是否在英文字典中?

Eso*_*ack 2 c# dictionary spell-checking

我试图通过一个单词列表,并确定每个单词是否是一个有效的英语单词(对于拼字游戏).我不知道如何处理这个问题,我是否必须找到所有英文单词的文本文件,然后使用文件读取和解析方法手动构建数据结构,如trie或hashmap - 或者我可以在某处找到premade ?最简单的方法是什么?

Oza*_*ler 7

您可以使用NetSpell库进行检查.可以使用以下命令轻松地通过Nuget Console安装它

PM> Install-Package NetSpell
Run Code Online (Sandbox Code Playgroud)

然后,循环显示单词并使用库检查它们

NetSpell.SpellChecker.Dictionary.WordDictionary oDict = new NetSpell.SpellChecker.Dictionary.WordDictionary(); 

oDict.DictionaryFile = "en-US.dic"; 
oDict.Initialize();
string wordToCheck = "door";
NetSpell.SpellChecker.Spelling oSpell = new NetSpell.SpellChecker.Spelling(); 

oSpell.Dictionary = oDict; 
if(!oSpell.TestWord(wordToCheck))
{
    //Word does not exist in dictionary
    ...
}
Run Code Online (Sandbox Code Playgroud)