importjavax.servlet.*;importjavax.servlet.annotation.WebFilter;importjava.io.IOException;@WebFilter("/*")publicclassWordFilterimplementsFilter{// 敏感词汇列表,可以根据需求扩展privatestaticfinal String[]SENSITIVE_WORDS={"敏感词1","敏感词2","敏感词3"};@OverridepublicvoiddoFilter(ServletRequest request,...
";Stringresult=SensitiveWordBs.newInstance().replace(text,'0'); Assert.assertEquals("0000迎风飘扬,000的画像屹立在000前。", result); 更多特性 后续的诸多特性,主要是针对各种针对各种情况的处理,尽可能的提升敏感词命中率。 这是一场漫长的攻防之战。 忽略大小写 finalStringtext="fuCK the bad words.";...
finalStringtext="fuCK the bad words.";Stringword = SensitiveWordBs.newInstance().findFirst(text); Assert.assertEquals("fuCK", word); AI代码助手复制代码 忽略半角圆角 finalStringtext="fuck the bad words.";Stringword = SensitiveWordBs.newInstance().findFirst(text); Assert.assertEquals("fuck", word...
String word = SensitiveWordBs.newInstance().findFirst(text); Assert.assertEquals("fuCK", word); 1. 2. 3. 4. 忽略半角圆角 final String text = "fuck the bad words."; String word = SensitiveWordBs.newInstance().findFirst(text); Assert.assertEquals("fuck", word); 1. 2. 3. 4. 后期road...
String word = SensitiveWordBs.newInstance().findFirst(text); Assert.assertEquals("fuCK", word); 忽略半角圆角 final String text = "fuck the bad words."; String word = SensitiveWordBs.newInstance().findFirst(text); Assert.assertEquals("fuck", word); ...
(){this.root=newTrieNode();}publicvoidinsert(Stringword){TrieNodenode=root;for(charc:word.toCharArray()){if(!node.getChild(c)){node.addChild(c);}node=node.getChild(c);}node.setEnd(true);// 表示某个敏感词的结束}}Trietrie=newTrie();for(Stringword:sensitiveWords){trie.insert(word);...
https://github.com/jkiss/sensitive-words 代码图数据文件如下: 二、敏感词实现原理基于二叉树排序 首先:query 日 ---> {本}、query 本 --->{人、鬼子}、query 人 --->{null}、query 鬼 ---> {子}。形如下结构: 三、敏感词过滤代码 封装工具类如下: ...
3. SensitiveWordFilter 这是一个专门为敏感词检测设计的 Java 库,基于 DFA 算法,简单易用。 GitHub 项目:SensitiveWordFilter 示例: Set<String> sensitiveWords = new HashSet<>(); sensitiveWords.add("敏感词1"); sensitiveWords.add("敏感词2"); ...
public static String shadowSensitive(String text) { StringBuffer sb = new StringBuffer(text); // filter sensitive words List<AhoCorasickDoubleArrayTrie.Hit<String>> hits = acdat.parseText(sb); // shadow sensitive words for (AhoCorasickDoubleArrayTrie.Hit<String> hit : hits) { ...
Java快速中文敏感词过滤,在15k敏感词库上的过滤速度超过50M字符每秒。. Contribute to ZHHUIer/sensitive-words development by creating an account on GitHub.