微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何为 C# 应用程序安装 Hunspell?

如何解决如何为 C# 应用程序安装 Hunspell?

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

Code Project Reference URL

Error

解决方法

根据我的测试,您可以从以下链接下载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);
    }

结果:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。