C#开源之敏感词检测过滤组件

描述

一款高性能敏感词(非法词/脏字)检测过滤组件,附带繁体简体互换,支持全角半角互换,汉字转拼音,模糊搜索等功能。

同时支持多种语言,C#、golang、java、javascript、python

参数

来源:GitHub(3100) https://github.com/toolgood/ToolGood.Words

示例

非法词(敏感词)检测类:StringMatch、StringMatchEx、WordsMatch、WordsMatchEx。

支持部分正则表达式类型:.(点)?(问号) [](方括号) (|)(括号与竖线)

string s = “.[中美]国|国人|zg人”; string test = “我是中国人”; WordsMatch wordsSearch = new WordsMatch(); wordsSearch.SetKeywords(s.Split(‘|’)); var b = wordsSearch.ContainsAny(test); Assert.AreEqual(true, b); var f = wordsSearch.FindFirst(test); Assert.AreEqual(“是中国”, f.Keyword); var alls = wordsSearch.FindAll(test); Assert.AreEqual(“是中国”, alls[0].Keyword); Assert.AreEqual(“.[中美]国”, alls[0].MatchKeyword); Assert.AreEqual(1, alls[0].Start); Assert.AreEqual(3, alls[0].End); Assert.AreEqual(0, alls[0].Index);//返回索引Index,默认从0开始 Assert.AreEqual(“国人”, alls[1].Keyword); Assert.AreEqual(2, alls.Count); var t = wordsSearch.Replace(test, ‘*’); Assert.AreEqual(“我****”, t);

繁体简体互换、全角半角互换、数字转成中文大写、拼音操作

// 转成简体 WordsHelper.ToSimplifiedChinese(“我愛中國”); WordsHelper.ToSimplifiedChinese(“我愛中國”,1);// 港澳繁体 转 简体 WordsHelper.ToSimplifiedChinese(“我愛中國”,2);// 台湾正体 转 简体 // 转成繁体 WordsHelper.ToTraditionalChinese(“我爱中国”); WordsHelper.ToTraditionalChinese(“我爱中国”,1);// 简体 转 港澳繁体 WordsHelper.ToTraditionalChinese(“我爱中国”,2);// 简体 转 台湾正体 // 转成全角 WordsHelper.ToSBC(“abcABC123”); // 转成半角 WordsHelper.ToDBC(“abcABC123”); // 数字转成中文大写 WordsHelper.ToChineseRMB(12345678901.12); // 中文转成数字 WordsHelper.ToNumber(“壹佰贰拾叁亿肆仟伍佰陆拾柒万捌仟玖佰零壹元壹角贰分”); // 获取全拼 WordsHelper.GetPinyin(“我爱中国”);//WoAiZhongGuo WordsHelper.GetPinyin(“我爱中国”,”,”);//Wo,Ai,Zhong,Guo WordsHelper.GetPinyin(“我爱中国”,true);//WǒÀiZhōngGuó // 获取首字母 WordsHelper.GetFirstPinyin(“我爱中国”);//WAZG // 获取全部拼音 WordsHelper.GetAllPinyin(‘传’);//Chuan,Zhuan // 获取姓名 WordsHelper.GetPinyinForName(“单一一”)//ShanYiYi WordsHelper.GetPinyinForName(“单一一”,”,”)//Shan,Yi,Yi WordsHelper.GetPinyinForName(“单一一”,true)//ShànYīYī

PinyinMatch:方法有SetKeywords、SetIndexs、Find、FindIndex。

PinyinMatch:方法有SetKeywordsFunc、SetPinyinFunc、SetPinyinSplitChar、Find。

string s = “北京|天津|河北|辽宁|吉林|黑龙江|山东|江苏|上海|浙江|安徽|福建|江西|广东|广西|海南|河南|湖南|湖北|山西|内蒙古|宁夏|青海|陕西|甘肃|新疆|四川|贵州|云南|重庆|西藏|香港|澳门|台湾”; PinyinMatch match = new PinyinMatch(); match.SetKeywords(s.Split(‘|’).ToList()); var all = match.Find(“BJ”); Assert.AreEqual(“北京”, all[0]); Assert.AreEqual(1, all.Count); all = match.Find(“北J”); Assert.AreEqual(“北京”, all[0]); Assert.AreEqual(1, all.Count); all = match.Find(“北Ji”); Assert.AreEqual(“北京”, all[0]); Assert.AreEqual(1, all.Count); all = match.Find(“S”); Assert.AreEqual(“山东”, all[0]); Assert.AreEqual(“江苏”, all[1]); var all2 = match.FindIndex(“BJ”); Assert.AreEqual(0, all2[0]); Assert.AreEqual(1, all.Count);

结尾

一款支持多语言的敏感词检测过滤组件,同时支持一些拼音、简繁体常规操作,主要针对一些中文语言语法的相关内容。

郑重声明:本文内容及图片均整理自互联网,不代表本站立场,版权归原作者所有,如有侵权请联系管理员(admin#wlmqw.com)删除。
(0)
用户投稿
上一篇 2022年6月16日
下一篇 2022年6月16日

相关推荐

联系我们

联系邮箱:admin#wlmqw.com
工作时间:周一至周五,10:30-18:30,节假日休息