Nhunspell C# 将单词添加到字典中
我已成功使用 NHunspell 将拼写检查合并到我的 C# 项目中。我想做的实际上是向字典文件添加一个单词。在 NHunspell 内部有一种方法可以做到这一点,我相信如下:
// Add the word to the dictionary and carry on
using (Hunspell hunspell = new Hunspell(@"Dictionaries/en_GB.aff", @"Dictionaries/en_GB.dic"))
{
hunspell.Add("wordToAdd");
}
但是当我使用这个方法时,它似乎实际上没有做任何事情。有人能指出我做错了什么吗?
谢谢
I have managed to incorporate spell checking into my C# project using NHunspell. What I would like to do is actually add a word to the dictionary file. There is a method to do this inside of NHunspell which I believe is as follows:
// Add the word to the dictionary and carry on
using (Hunspell hunspell = new Hunspell(@"Dictionaries/en_GB.aff", @"Dictionaries/en_GB.dic"))
{
hunspell.Add("wordToAdd");
}
When I use this however it does not appear to actually do anything. Would anyone be able to suggest what it is I am doing wrong?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有意识到使用 .Add() 方法添加单词只允许在 Hunspell 对象处于活动状态时使用该单词。该单词实际上并未添加到外部词典文件中。我解决这个问题的方法是使用自定义字典文件。当用户添加单词时,该单词将存储在新的自定义词典文件中。现在,当调用我的主要拼写检查器函数时,在检查任何单词之前,都会使用 .Add() 方法添加自定义词典中的所有单词。希望这有帮助。
I did not realise that adding a word using the .Add() method only allows that word to be used while the Hunspell object is alive. The word is not actually added to the external dictionary file. The way I combated this problem was to make use of a custom dictionary file. When a word is added by the user this word is stored in the new custom dictionary file. Now when my main spell checker function is called, before any words are checked all the words which are in the custom dictionary are added using the .Add() method. Hope this helps.
在字典中添加单词只需使用
StreamWriter
的WriteLine()
在任何文本文件中添加新单词即可。Adding a word in the dictionary is simply append new word in any text file using
WriteLine()
ofStreamWriter
.