为了使wordBs起作用,可以使用SensitiveWordHelper的setWordBs方法将wordBs设置进去。修改后的代码如下:

public static String filterSensitiveWords(String input) {
    SensitiveWordBs wordBs = SensitiveWordBs.newInstance()
            .ignoreCase(true)
            .ignoreWidth(true)
            .ignoreNumStyle(true)
            .ignoreChineseStyle(true)
            .ignoreEnglishStyle(true)
            .ignoreRepeat(true)
            .enableNumCheck(false)
            .enableEmailCheck(true)
            .enableUrlCheck(true)
            .init();

    SensitiveWordHelper.setWordBs(wordBs);

    boolean isFalse = SensitiveWordHelper.contains(input);
    if (isFalse) {
        String result = SensitiveWordHelper.replace(input);
        return result;
    } else {
        return input;
    }
}

通过调用SensitiveWordHelper.setWordBs(wordBs)方法,将配置好的wordBs对象设置到SensitiveWordHelper中,这样SensitiveWordHelper在执行敏感词过滤操作时,就会使用wordBs中的规则进行判断。


原文地址: https://www.cveoy.top/t/topic/pdup 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录