使用C#NHunspell如何检查单词?

时间:2013-03-06 16:19:55

标签: c# spell-checking hunspell nhunspell

使用C#NHunspell,我如何检查单词是否拼写正确,如果不正确拼写是什么?

我已将NHunspell.dll导入项目中。并查看了the documentation

但是阅读文档有点新意,很难知道从哪里开始。有人可以举例说明如何拼写单词拼写正确吗?基本上我需要一个NHunspell的Helloworld。

1 个答案:

答案 0 :(得分:8)

using (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 );
    }
}

来自文章http://www.codeproject.com/Articles/43495/Spell-Check-Hyphenation-and-Thesaurus-for-NET-with