我想通过使用 Hunspell 在字典中添加一些自定义单词:
我从构造函数中的字典加载:
private readonly Hunspell _hunspell;
public NhunspellHelper()
{
_hunspell = new Hunspell(
HttpContext.Current.Server.MapPath("~/App_Data/en_US.aff"),
HttpContext.Current.Server.MapPath("~/App_Data/en_US.dic"));
}
此函数将一个新词添加到字典中:
public void AddToDictionary(string word)
{
_hunspell.Add(word); // or _hunspell.AddWithAffix(word, "aaa");
}
在我向字典中添加一个单词后,如果我在同一个请求中拼写这个单词:
_hunspell.Spell(word)
它返回true
,但如果我在另一个请求中拼写这个词,它会返回false
我检查了两个文件.aff
,.dic
我发现它在 之后没有改变_hunspell.Add(word);
,所以当发送另一个请求时,构造函数会从原始字典中创建一个新的 Hunspell 实例。
我的问题是:Nhunspell 是否将新单词添加到字典中并将其保存回物理文件(*.aff 或 *.dic),还是只是将其添加到内存中而不对字典文件执行任何操作?
我在字典中添加新单词时做错了吗?