【问题标题】:How to install Hunspell for C# application?如何为 C# 应用程序安装 Hunspell?
【发布时间】:2021-10-02 09:53:53
【问题描述】:

我想在基于 Windows 的 C# 应用程序中实现拼写检查和字典。在 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

【问题讨论】:

  • nuget 包最后一次更新是 2015 年,主页和源代码似乎不存在。我会认为这是已弃用且不再维护
  • @Sascha 如果可能的话,您能否建议一些替代 URL 以在 C# 中实现相同的功能。
  • 如果你看一下hunspell project page,那里有一些词典的链接。
  • @phuzi 我试过cgit.freedesktop.org/libreoffice/dictionaries/tree/en/en_US.dic,但我无法下载 .aff 和 .dic 文件。
  • 从那个链接有一个指向普通文件的链接,尝试下载它!

标签: c# .net visual-studio hunspell nhunspell


【解决方案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);
    }

结果:

【讨论】:

  • 谢谢,但不幸的是它不适合我。我下载了文件并用正确的扩展名重命名。但在建议中,值始终为空。
  • @Ask_SO,你可以从here下载这两个文件。
  • J Jun - 你能简单解释一下 AFF 文件的用途吗?即使任何参考链接也可以。
猜你喜欢
  • 1970-01-01
  • 2017-10-01
  • 2011-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-30
相关资源
最近更新 更多