houbb / sensitive-word

👮‍♂️The sensitive word tool for java.(敏感词/违禁词/违法词/脏词。基于 DFA 算法实现的高性能 java 敏感词过滤工具框架。请勿发布涉及政治、广告、营销、翻墙、违反国家法律法规等内容。高性能敏感词检测过滤组件,附带繁体简体互换,支持全角半角互换,汉字转拼音,模糊搜索等功能。)
https://houbb.github.io/opensource/sensitive-word
Apache License 2.0
4.1k stars 545 forks source link

自定义敏感词innerWordMap构建时 key 为null 导致无法匹配 #28

Closed netyjq closed 1 year ago

netyjq commented 1 year ago
public class MyWordDeny implements IWordDeny {

    @Override
    public List<String> deny() {
        return Arrays.asList("舅舅, AA, 双标, fire, 游戏, navicat, QQ, 双规".split(","));
    }

}
IWordDeny wordDeny = WordDenys.chains(WordDenys.system(), new MyWordDeny());
IWordAllow wordAllow = WordAllows.chains(WordAllows.system(), new MyWordAllow());
SensitiveWordBs sensitiveWordBs = SensitiveWordBs.newInstance()
        .wordAllow(wordAllow)
        .wordDeny(wordDeny)// 各种其他配置
        .init();// init() 初始化敏感词字典

final String text = "这是一条测试的QQ 猫砂";
// 输出测试结果
System.out.println("敏感词:" + sensitiveWordBs.findAll(text).toString());

output: []

houbb commented 1 year ago

应该不是 null 的问题。

1)【 QQ】这是用逗号分割后的敏感词列表。 2)匹配内容是没有匹配的,因为例子中为【QQ 】

这种问题建议自己 debug 下。