平时工作学习中,对于单词拼写检查也是很常见的需求。 一直没找到特别好用的版本,就自己写一个。方便以后拓展和他人使用。
本项目用于英文单词拼写检查。
word-checker
JDK1.7 及其以后
本项目已经上传到 maven 仓库,直接引入即可
<dependency> <groupId>com.github.houbb</groupId> <artifactId>word-checker</artifactId> <version>0.0.1</version> </dependency>结果为
spelling错误提示支持 i18N
可以迅速判断当前单词是否拼写错误
可以返回最佳匹配结果
可以返回纠正匹配列表,支持指定返回列表的大小
英文单词支持自行定义
中文单词的拼写是否正确功能添加
备注
所有方法为 EnWordChecker 类下。
功能方法参数返回值备注判断单词拼写是否正确isCorrect(string)待检测的单词boolean返回最佳纠正结果correct(string)待检测的单词String如果没有找到可以纠正的单词,则返回其本身判断单词拼写是否正确correctList(string)待检测的单词List返回所有匹配的纠正列表判断单词拼写是否正确correctList(string, int limit)待检测的单词, 返回列表的大小返回指定大小的的纠正列表列表大小 <= limit参见 EnWordCheckerTest.java
/** * 是否拼写正确 */ @Test public void isCorrectTest() { final String hello = "hello"; final String speling = "speling"; Assert.assertTrue(EnWordChecker.getInstance().isCorrect(hello)); Assert.assertFalse(EnWordChecker.getInstance().isCorrect(speling)); } /** * 返回最佳匹配结果 */ @Test public void correctTest() { final String hello = "hello"; final String speling = "speling"; Assert.assertEquals("hello", EnWordChecker.getInstance().correct(hello)); Assert.assertEquals("spelling", EnWordChecker.getInstance().correct(speling)); } /** * 默认纠正匹配列表 * 1. 默认返回所有 */ @Test public void correctListTest() { final String word = "goo"; List<String> stringList = EnWordChecker.getInstance().correctList(word); Assert.assertTrue(stringList.size() > 0); } /** * 默认纠正匹配列表 * 1. 默认返回所有 */ @Test public void correctListTest() { final String word = "goo"; List<String> stringList = EnWordChecker.getInstance().correctList(word); Assert.assertTrue(stringList.size() > 0); }Words 提供的原始英语单词数据。
ENABLE word list
spell-correct
spellchecking