String[] keywords =new String[] { "奸","强奸", "性感", "性欲", "性爱", "欲望", "激情", "狂", "联系", "色诱", "评", "骚"};
//初始化敏感词数据结构
TreeNode root= TreeNode.markNode(keywords);
//敏感词过滤器
WordFilter filterService = new WordFilter(root);
//解析存在的敏感词token
LinkedList<WordParser.WordToken> list= filterService.parser(str);
for(WordParser.WordToken token:list){
System.out.println(token);
}
//过滤敏感词处理
WordFilter filterService = new WordFilter(root);
System.out.println(filterService.filter(str));
基于Btree数据结构算法实现敏感词
源代码托管在github: https://github.com/kevinLuan/word_filter