问题描述
我想在我的基于 C# Windows 的应用程序中实现拼写检查和字典。在 Google 中,我发现 hunspell 是实现此功能的最佳选择之一。我已经按照以下 URL 中的建议使用 Visual Studio NuGet 安装了 nhunspell。但是当我尝试执行代码时,出现错误“找不到 AFF 文件:C:\TestProject\TestHunshell\bin\Debug\en_us.aff”
当我搜索已安装的 hunspell 包时,没有找到 .aff 和 .dic 文件。我不确定从哪里可以下载并安装或粘贴“en_us.aff”、“en_us.dic”文件到我的解决方案。
有人可以建议在 C# windows 应用程序中安装和实现 hunspell 的正确方法吗?
解决方法
根据我的测试,您可以从以下链接下载aff & .dic files
:
点击后,我们应该右键另存为txt文件。
然后,我们需要移动 .txt 以将其更改为扩展名 .aff 或 .dic。
最后,我们将两个文件移动到 project\bin\debug
文件夹。
这是我的测试代码和结果:
Hunspell hunspell = new Hunspell("en_US.aff","en_US.dic");
Console.WriteLine("Hunspell - Spell Checking Functions");
Console.WriteLine("¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯");
Console.WriteLine("Check if the word 'Recommendation' is spelled correct");
bool correct = hunspell.Spell("Recommendation");
Console.WriteLine("Recommendation is spelled " +
(correct ? "correct" : "not correct"));
Console.WriteLine("");
Console.WriteLine("Make suggestions for the word 'Recommendatio'");
List<string> suggestions = hunspell.Suggest("Recommendatio");
Console.WriteLine("There are " +
suggestions.Count.ToString() + " suggestions");
foreach (string suggestion in suggestions)
{
Console.WriteLine("Suggestion is: " + suggestion);
}
结果: