ToolGood.Words是一款高性能非法词(敏感词)检测组件,附带繁体简体互换,支持全角半角互换,获取拼音首字母,获取拼音字母等功能。
非法词(敏感词)检测类有:StringSearch、WordsSearch、IllegalWordsSearch、IllegalWordsQuickSearch
StringSearch
WordsSearch
IllegalWordsSearch
IllegalWordsQuickSearch
示例代码:
string s = "中国|国人|zg人"; string test = "我是中国人"; StringSearch iwords = new StringSearch(); iwords.SetKeywords(s.Split('|')); var b = iwords.ContainsAny(test); Assert.AreEqual(true, b); var f = iwords.FindFirst(test); Assert.AreEqual("中国", f); var all = iwords.FindAll(test); Assert.AreEqual("中国", all[0]); Assert.AreEqual("国人", all[1]); Assert.AreEqual(2, all.Count); var str = iwords.Replace(test, '*'); Assert.AreEqual("我是***", str);
StringSearch.ContainsAny的效率是正则IsMatch的1.5W倍。
Regex.Matches的运行方式跟IQueryable的类似,只返回MatchCollection,还没有计算。
TrieFilter,FastFilter为其他网友算法,来源请看文档。
自带多音词库,不带分词功能,特殊情况下会出现拼音错误。
var py = WordsHelper.GetPinYin("快乐,乐清"); Assert.AreEqual("KuaiLe,YueQing", py);
开源地址:
码云: https://git.oschina.net/toolgood/ToolGood.Words
GitHub: https://github.com/toolgood/ToolGood.Words