中英文拼写检测纠正开源项目使用入门 word-checker 1.1.0
项目简介
word-checker 本项目用于单词拼写检查。支持英文单词拼写检测,和中文拼写检测。
特性说明
可以迅速判断当前单词是否拼写错误
可以返回最佳匹配结果
可以返回纠正匹配列表,支持指定返回列表的大小
错误提示支持 i18n
支持大小写、全角半角格式化处理
支持自定义词库
内置 27W+ 的英文词库
支持指定英文的编辑距离
支持基本的中文拼写检测
变更日志
快速开始
JDK 版本
Jdk 1.7+
maven 引入
<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>word-checker</artifactId>
<version>1.1.0</version>
</dependency>
测试案例
会根据输入,自动返回最佳纠正结果。
final String speling = "speling";
Assert.assertEquals("spelling", WordCheckerHelper.correct(speling));
核心 api 介绍
核心 api 在 WordCheckerHelper 工具类下。
WordCheckers 工具类提供了长文本中英文混合的自动纠正功能,当然也支持单个单词。
| 功能 | 方法 | 参数 | 返回值 | 备注 |
|---|---|---|---|---|
| 文本拼写是否正确 | isCorrect(string) | 待检测的文本 | boolean | 全部正确,才会返回 true |
| 返回最佳纠正结果 | correct(string) | 待检测的单词 | String | 如果没有找到可以纠正的文本,则返回其本身 |
| 判断文本拼写是否正确 | correctMap(string) | 待检测的单词 | Map<String, List<String>> |
返回所有匹配的纠正列表 MAP |
| 判断文本拼写是否正确 | correctMap(string, int limit) | 待检测的文本, 返回列表的大小 | 返回指定大小的的纠正列表 MAP | 列表大小 <= limit |
| 判断文本拼写是否正确 | correctList(string) | 待检测的单词 | List<String> |
返回所有匹配的纠正列表 |
| 判断文本拼写是否正确 | correctList(string, int limit) | 待检测的文本, 返回列表的大小 | 返回指定大小的的纠正列表 | 列表大小 <= limit |
英文测试例子
是否拼写正确
final String hello = "hello";
final String speling = "speling";
Assert.assertTrue(WordCheckerHelper.isCorrect(hello));
Assert.assertFalse(WordCheckerHelper.isCorrect(speling));
返回最佳匹配结果
final String hello = "hello";
final String speling = "speling";
Assert.assertEquals("hello", WordCheckerHelper.correct(hello));
Assert.assertEquals("spelling", WordCheckerHelper.correct(speling));
默认纠正匹配列表
final String word = "goox";
List<String> stringList = WordCheckerHelper.correctList(word);
Assert.assertEquals("[good, goo, goon, goof, gook, goop, goos, gox, goog, gool, goor]", stringList.toString());
指定纠正匹配列表大小
final String word = "goox";
final int limit = 2;
List<String> stringList = WordCheckerHelper.correctList(word, limit);
Assert.assertEquals("[good, goo]", stringList.toString());
中文拼写纠正
是否拼写正确
final String right = "正确";
final String error = "万变不离其中";
Assert.assertTrue(WordCheckerHelper.isCorrect(right));
Assert.assertFalse(WordCheckerHelper.isCorrect(error));
返回最佳匹配结果
final String right = "正确";
final String error = "万变不离其中";
Assert.assertEquals("正确", WordCheckerHelper.correct(right));
Assert.assertEquals("万变不离其宗", WordCheckerHelper.correct(error));
默认纠正匹配列表
final String word = "万变不离其中";
List<String> stringList = WordCheckerHelper.correctList(word);
Assert.assertEquals("[万变不离其宗]", stringList.toString());
指定纠正匹配列表大小
final String word = "万变不离其中";
final int limit = 1;
List<String> stringList = WordCheckerHelper.correctList(word, limit);
Assert.assertEquals("[万变不离其宗]", stringList.toString());
长文本中英文混合
情景
实际拼写纠正的话,最佳的使用体验是用户输入一个长文本,并且可能是中英文混合的。
然后实现上述对应的功能。
拼写是否正确
final String hello = "hello 你好";
final String speling = "speling 你好 以毒功毒";
Assert.assertTrue(WordCheckers.isCorrect(hello));
Assert.assertFalse(WordCheckers.isCorrect(speling));
返回最佳纠正结果
final String hello = "hello 你好";
final String speling = "speling 你好以毒功毒";
Assert.assertEquals("hello 你好", WordCheckers.correct(hello));
Assert.assertEquals("spelling 你好以毒攻毒", WordCheckers.correct(speling));
判断文本拼写是否正确
每一个词,对应的纠正结果。
final String hello = "hello 你好";
final String speling = "speling 你好以毒功毒";
Assert.assertEquals("{hello=[hello], =[ ], 你=[你], 好=[好]}", WordCheckers.correctMap(hello).toString());
Assert.assertEquals("{ =[ ], speling=[spelling, spewing, sperling, seeling, spieling, spiling, speeling, speiling, spelding], 你=[你], 好=[好], 以毒功毒=[以毒攻毒]}", WordCheckers.correctMap(speling).toString());
判断文本拼写是否正确
同上,指定最多返回的个数。
final String hello = "hello 你好";
final String speling = "speling 你好以毒功毒";
Assert.assertEquals("{hello=[hello], =[ ], 你=[你], 好=[好]}", WordCheckers.correctMap(hello, 2).toString());
Assert.assertEquals("{ =[ ], speling=[spelling, spewing], 你=[你], 好=[好], 以毒功毒=[以毒攻毒]}", WordCheckers.correctMap(speling, 2).toString());
格式化处理
有时候用户的输入是各式各样的,本工具支持对于格式化的处理。
大小写
大写会被统一格式化为小写。
final String word = "stRing";
Assert.assertTrue(WordCheckerHelper.isCorrect(word));
全角半角
全角会被统一格式化为半角。
final String word = "string";
Assert.assertTrue(WordCheckerHelper.isCorrect(word));
自定义英文词库
文件配置
你可以在项目资源目录创建文件 resources/data/define_word_checker_en.txt
内容如下:
my-long-long-define-word,2
my-long-long-define-word-two
不同的词独立一行。
每一行第一列代表单词,第二列代表出现的次数,二者用逗号 , 隔开。
次数越大,在纠正的时候返回优先级就越高,默认值为 1。
用户自定义的词库优先级高于系统内置词库。
测试代码
我们在指定了对应的单词之后,拼写检测的时候就会生效。
final String word = "my-long-long-define-word";
final String word2 = "my-long-long-define-word-two";
Assert.assertTrue(WordCheckerHelper.isCorrect(word));
Assert.assertTrue(WordCheckerHelper.isCorrect(word2));
自定义中文词库
文件配置
你可以在项目资源目录创建文件 resources/data/define_word_checker_zh.txt
内容如下:
默守成规 墨守成规
使用英文空格分隔,前面是错误,后面是正确。
后期 Road-Map
支持英文分词,处理整个英文句子
支持中文分词拼写检测
引入中文纠错算法,同音字和形近字处理。
支持中英文混合拼写检测
技术鸣谢
Words 提供的原始英语单词数据。
开源地址
https://github.com/houbb/word-checker/ 欢迎大家 fork+star ~~~
中英文拼写检测纠正开源项目使用入门 word-checker 1.1.0的更多相关文章
- Work Time Manager【开源项目】- 创建自己日志组件 2.0重构
Hello all , 我又回来了 这次我们真是开始来聊聊开源项目里,小而有用的模块或者组件的开发思想. 同时,软件已经更新到1.60的版本了,支持新用户注册,可以不再使用统一的test账户了. 您可 ...
- 每周开源项目分享-年轻人的第一个OAuth2.0 Server:hydra
年轻人的第一个OAuth2.0 Server:hydra hydra 是什么呢? OpenID Connect certified OAuth2 Server - cloud native, secu ...
- j2ee开源项目——IT学习者博客(itxxzblog v1.0)
大家好,我是IT学习者-螃蟹,已经有近一周的时间没有更新文章了,作为回报,今天起将更新一个大件,也就是螃蟹还在进行中的IT学习者博客. IT学习者博客的初期设计已经完成,功能也已经完成了大半,具备了当 ...
- .Net 开源项目 FreeRedis 实现思路之 - Redis 6.0 客户端缓存技术
写在开头 FreeRedis 是一款继 CSRedisCore 之后重写的 .NET redis 客户端开源组件,以 MIT 协议开源托管于 github,目前支持 .NET 5..NETCore 2 ...
- java 实现中英文拼写检查和错误纠正?可我只会写 CRUD 啊!
简单的需求 临近下班,小明忙完了今天的任务,正准备下班回家. 一条消息闪烁了起来. "最近发现公众号的拼写检查功能不错,帮助用户发现错别字,体验不错.给我们系统也做一个." 看着这 ...
- 自然语言处理工具:中文 word2vec 开源项目,教程,数据集
word2vec word2vec/glove/swivel binary file on chinese corpus word2vec: https://code.google.com/p/wor ...
- .NET平台开源项目速览(6)FluentValidation验证组件介绍与入门(一)
在文章:这些.NET开源项目你知道吗?让.NET开源来得更加猛烈些吧!(第二辑)中,给大家初步介绍了一下FluentValidation验证组件.那里只是概述了一下,并没有对其使用和强大功能做深入研究 ...
- Google Go 语言从入门到应用必备开源项目
Go 语言于 2009 年 11 月正式宣布推出,成为开放源代码项目,发展至今已经具有越来越广泛的影响力,今年更是在 TIOBE 编程语言排行榜中跻身 20 强.很多开发者也逐渐将目光投向这门语言,本 ...
- windows下nodejs express安装及入门网站,视频资料,开源项目介绍
windows下nodejs express安装及入门网站,视频资料,开源项目介绍,pm2,supervisor,npm,Pomelo,Grunt安装使用注意事项等总结 第一步:下载安装文件下载地址: ...
- NET平台开源项目速览(6)FluentValidation验证组件介绍与入门(转载)
原文地址:http://www.cnblogs.com/asxinyu/p/dotnet_Opensource_project_FluentValidation_1.html 阅读目录 1.基本介绍 ...
随机推荐
- a标签做锚点定位,有部分内容被置顶头部遮挡的解决方法
被遮挡的元素添加如下样式: /**这里假定头部高度是100px*/ position: relative;top: 100px;/**关键样式如下,我这里上面有加定位,如果没用定位,下面的数值需根据实 ...
- scala概述入门和项目创建
1.scala简介 (1).scala基于JVM,与JAVA完全兼容,具有跨平台.可移植性好.方便的垃圾回收等特性: (2).scala比JAVA更加面向对象: (3).scala是一门函数式编程语言 ...
- 移动端H5开发坑位指南
一.HTML方向 调用系统功能 使用<a>能快速调用移动设备的电话/短信/邮件三大通讯功能,使用<input>能快速调用移动设备的的图库/文件. 这些功能方便了页面与系统的交互 ...
- lvds接口
1.lvds就是差分信号接口,tft-lcd屏幕,一种常用的接口. 2.有3种标准,18bit, 24bit(JEIDA) 与 24bit(VESA) 详细看https://www.topwaydis ...
- mysql零基础-1
数据库概述 为什么要使用数据库 持久化 DB:数据库 DBMS:数据库管理系统 SQL:结构化查询语言 数据库与数据库管理系统关系 数据库管理系统(DBMS)可以管理多个数据库,一般开发人员会针对每一 ...
- mysql 的小问题
首先按下win+R 执行 services.msc 进入服务,查找到MySQL,点击停止服务,然后在控制台cmd进入本地的MySQL文件夹,我的文件名是mysql-8.0.26-winx64,进入后执 ...
- 圣诞树代码_HTML
这个冬天给TA栽不一样的圣诞树 直接上效果 <!DOCTYPE html> <html lang="en" > <head> <meta ...
- 攻防(一)tomcat CVE-2020-1938,ftp 21端口
TOMCAT kali自带POE msf6 > use auxiliary/admin/http/tomcat_ghostcat set RHOST 10.98.xx.xx msf6 auxil ...
- linux 中安装、更新和卸载软件
1.Aptitude aptitude 与 apt-get 一样,是 Debian 及其衍生系统中功能极其强大的包管理工具. 与 apt-get 不同的是,aptitude 在处理依赖问题上更佳一些. ...
- 在vscode中用tsc编译ts文件的时候报错,tsc : 无法加载文件,因为在此系统上禁止运行脚本;SecurityError
1. TypeScript安装成功,在C盘的Administrator目录下,运行 tsc -v 也可看到TypeScript的版本. 2. 但在vscode中的时候运行tsc 编译ts文件的时候报 ...