1

我想在基于 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 的正确方法吗?

代码项目参考 URL

错误

4

1 回答 1

1

根据我的测试,您可以aff & .dic files从以下链接下载:

en_US.aff

en_US.dic

点击点击后,我们应该右键保存为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);
    }

结果:

在此处输入图像描述

于 2021-07-27T02:31:24.887 回答