亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Java數(shù)據(jù)敏感詞轉(zhuǎn)換成符號的方法詳解

 更新時(shí)間:2024年03月28日 10:00:02   作者:QPiker  
在某個(gè)論壇下用戶可以隨意留言,為了防止不法分子在網(wǎng)上任意沖浪,需要對一些敏感詞匯進(jìn)行一些校驗(yàn),所以這篇文章給大家介紹了Java數(shù)據(jù)敏感詞轉(zhuǎn)換成符號的方法,需要的朋友可以參考下

Java數(shù)據(jù)敏感詞轉(zhuǎn)換成符號

在某個(gè)論壇下用戶可以隨意留言,為了防止不法分子在網(wǎng)上任意沖浪,需要對一些敏感詞匯進(jìn)行一些校驗(yàn)。在這里使用一個(gè)高性能敏感詞工具sensitive-word。

maven

<!--     數(shù)據(jù)脫敏   -->
        <dependency>
            <groupId>com.github.houbb</groupId>
            <artifactId>sensitive-word</artifactId>
            <version>0.13.1</version>
        </dependency>

直接使用

	    String str1 = "我他媽的沒有說過臟話";
        String replace1 = SensitiveWordHelper.replace(str1);
        System.out.println("原始數(shù)據(jù):" + str1);
        System.out.println("脫敏數(shù)據(jù):" + replace1);
// 原始數(shù)據(jù):我他媽的沒有說過臟話
// 脫敏數(shù)據(jù):我***沒有說過臟話

結(jié)合Spring使用

拓展已脫敏詞匯

@Component
public class MyWordDeny implements IWordDeny {

    @Override
    public List<String> deny() {
        return Arrays.asList("盧本偉沒有開掛","我的發(fā)");
    }
}

拓展排除脫敏詞匯

@Component
public class MyWordAllow implements IWordAllow {
    @Override
    public List<String> allow() {
        return Arrays.asList("廢物","辣雞");
    }
}

配置類

@Configuration
public class SpringSensitiveWordConfig {

    /**
     * 排除敏感詞
     */
    @Resource
    private MyWordAllow myWordAllow;

    /**
     * 拓展敏感詞
     */
    @Resource
    private MyWordDeny myWordDeny;


    /**
     * 初始化引導(dǎo)類
     * WordAllows.chains 在原作者詞匯數(shù)據(jù)庫進(jìn)行拓展
     * WordDenys.chains 同上
     */
    @Bean
    public SensitiveWordBs sensitiveWordBs() {
        return SensitiveWordBs.newInstance()
                .wordAllow(WordAllows.chains(WordAllows.defaults(), myWordAllow))
                .wordDeny(WordDenys.chains(WordDenys.defaults(), myWordDeny))
                .init();
    }
}

測試調(diào)用

@SpringBootTest(classes = QpikerAdminApplication.class)
@RunWith(SpringRunner.class)
public class SensitiveTest {

    /**
     * 數(shù)據(jù)脫敏
     */
    @Resource
    private SpringSensitiveWordConfig springSensitiveWordConfig;

    @Test
    public void wordSensitive(){
        String str = "誰他媽的是廢物?,我盧本偉沒有開掛真的,1824176666,我的發(fā)你是小辣雞";
        System.out.println("原始數(shù)據(jù):" + str);
        String replace = springSensitiveWordConfig.sensitiveWordBs().replace(str);
        System.out.println("脫敏數(shù)據(jù):" + replace);
    }
}

輸出結(jié)果

原始數(shù)據(jù):誰他媽的是廢物?,我盧本偉沒有開掛真的,18241766666,他媽的,我的發(fā)你是小辣雞
脫敏數(shù)據(jù):誰***是廢物?,我*******真的,***********,***,***你是小辣雞

'廢物' 被加到排除脫敏數(shù)據(jù)中,結(jié)果沒被替換
'盧本偉沒有開掛' 被加到已脫敏數(shù)據(jù)中,結(jié)果被替換

真沒有意說臟話,希望各大網(wǎng)友們構(gòu)建一個(gè)文明網(wǎng)絡(luò)世界。

到此這篇關(guān)于Java數(shù)據(jù)敏感詞轉(zhuǎn)換成符號的示例代碼的文章就介紹到這了,更多相關(guān)Java敏感詞轉(zhuǎn)換成符號內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論