psd做成网站,c2c电子商务网站需具备哪些业务功能,百度浏览器打开,赣州网站建设哪家好122014-12-13 22:05:54 08:00 1在牛客网 http://www.nowcoder.com 用户在我们网站提交的评论#xff0c;我们会进行敏感词过滤#xff0c;其算法是基于有限状态机DFA过滤的。 我觉得可以用敏感词过滤的方法来查找的用户ID。 (用户ID就是好多敏感词)#xff0c; 具体的代码…122014-12-13 22:05:54 08:00 1在牛客网 http://www.nowcoder.com 用户在我们网站提交的评论我们会进行敏感词过滤其算法是基于有限状态机DFA过滤的。 我觉得可以用敏感词过滤的方法来查找的用户ID。 (用户ID就是好多敏感词) 具体的代码如下/*** 过滤敏感词** param text* return*/public String filter(String text) {if (StringUtils.isBlank(text)) {return text;}String replacement DEFAULT_REPLACEMENT;StringBuilder result new StringBuilder();DFATreeNode tempNode rootNode;int begin 0; // 回滚数int position 0; // 当前比较的位置while (position text.length()) {char c text.charAt(position);// 空格直接跳过if (isSymbol(c)) {position;continue;}tempNode tempNode.getSubNode(c);// 当前位置的匹配结束if (tempNode null) {// 以begin开始的字符串不存在敏感词result.append(text.charAt(begin));// 跳到下一个字符开始测试position begin 1;begin position;// 回到树初始节点tempNode rootNode;} else if (tempNode.isKeywordEnd()) {// 发现敏感词 从begin到position的位置用replacement替换掉result.append(replacement);position position 1;begin position;tempNode rootNode;} else {position;}}result.append(text.substring(begin));return result.toString();}