如何在不区分大小写的情况下检查Hunspell中的拼写 [英] How to check spelling in Hunspell with case insensitive

查看:101
本文介绍了如何在不区分大小写的情况下检查Hunspell中的拼写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在制作一个桌面应用程序(C#),用于检查输入单词的拼写.我正在使用通过NuGet添加到我的项目中的Hunspell.我有2个文件aff文件和dic文件.

Hi I am making a desktop application (C#) that checks the spelling of the inputted word. I am using Hunspell which I added to my project using NuGet. I have 2 files the aff file and the dic file.

using (Hunspell english = new Hunspell("en_US.aff", "en_US.dic"))
{
    bool isExist = english.Spell("THesis");
}

isExist等于false,因为在我的.dic文件中,正确的拼写是论文".即使我习惯了.lower()并输入专有名称,isExist也变为false.

isExist is equal to false because in my .dic file the correct spelling is "thesis". Even I use to .lower() and input proper names the isExist become false.

您能帮我解决这个问题吗?

Can you help me in solving this?

推荐答案

鉴于Hunspell似乎不支持不区分大小写的拼写检查,您可能需要考虑略微调整算法:

Given that Hunspell does not appear to support case-insensitive spelling checks, you might want to consider adapting your algorithm slightly:

给出THesis,您可以尝试:

bool isExist = false;

using (Hunspell english = new Hunspell("en_US.aff", "en_US.dic"))
{
    TextInfo textInfo = new CultureInfo("en-US",false).TextInfo;
    isExist =      english.Spell("THesis") 
                 | english.Spell(textInfo.ToLower("THesis") 
                 | english.Spell(textInfo.ToUpper("THesis")) 
                 | english.Spell(textInfo.ToTitleCase("THesis"))
}

这将依次从逻辑上检查"THesis","thesis","THESIS"和"Thesis",如果其中任何一种拼写有效,则返回true,这由

This will in turn logically check "THesis", "thesis", "THESIS" and "Thesis" and return true if any of those spellings is valid, courtesy of the logical OR operator.

对于canada来说,这同样可行,因为ToTitleCase()方法至少可以保证匹配.

Similarly for canada, this would work, as the ToTitleCase() method would at least guarantee a match.

这应该适用于大多数单个单词(包括所有大写字母的首字母缩写词).

This should work for most single words (including all caps acronyms).

这篇关于如何在不区分大小写的情况下检查Hunspell中的拼写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆