2013-03-06 77 views
5

使用C#NHunspell,我該如何檢查單詞是否拼寫正確,如果不正確拼寫是什麼?使用C#NHunspell如何檢查單詞?

我已經將NHunspell.dll導入到項目中。並看了看the documentation

但是在閱讀文檔時有點新,很難知道從哪裏開始。有人可以提供一個關於如何檢查單詞是否拼寫正確的例子嗎?基本上我需要一個Helloworld來支持NHunspell。

+1

http://www.codeproject.com/Articles/33658/NHunspell-Hunspell-for-the-NET-platform – 2013-03-06 16:23:38

+1

另外,瀏覽單元測試:HTTP:/ /nhunspell.svn.sourceforge.net/viewvc/nhunspell/trunk/UnitTests/UnitTestsHunspell.cs?revision=81&view=markup – 2013-03-06 16:26:29

+0

我實際上已經結束了使用NetSpell,因爲它更容易實現。謝謝你! – rotaercz 2013-03-06 20:35:46

回答

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

+0

我們如何得到所有的單詞?我的意思是掃描dic文件的每一行,並獲得可以從該行生成的所有組合。我怎樣才能做到這一點? ty – MonsterMMORPG 2017-03-02 21:38:15

+0

https://www.codeproject.com/Articles/43495/Spell-Check-Hyphenation-and-Thesaurus-for-NET-with?msg=5368357#xx5368357xx – MonsterMMORPG 2017-03-02 21:53:46