当前位置: 首页 > news >正文

网站支付宝支付接口申请wordpress侧边栏折叠

网站支付宝支付接口申请,wordpress侧边栏折叠,手机浏览器app下载,套路网站怎么做的在现代的互联网应用中#xff0c;敏感词过滤已成为一个必不可少的功能#xff0c;尤其是在社交媒体、评论审核等需要保证内容健康的场景下。本文将基于开源库https://github.com/houbb/sensitive-word#xff0c;详细讲解如何通过自定义敏感词库和工具类实现高效的敏感词过滤…在现代的互联网应用中敏感词过滤已成为一个必不可少的功能尤其是在社交媒体、评论审核等需要保证内容健康的场景下。本文将基于开源库https://github.com/houbb/sensitive-word详细讲解如何通过自定义敏感词库和工具类实现高效的敏感词过滤功能。 1. 项目依赖 首先需要引入 sensitive-word 相关的 Maven 依赖 dependencygroupIdcom.github.houbb/groupIdartifactIdsensitive-word/artifactIdversion1.4.1/version /dependency2. 配置敏感词过滤组件 下面是核心的敏感词过滤配置代码通过 SensitiveWordBs 构建过滤器并加载自定义敏感词和允许词。 配置类代码 package cn.yujky.study.sensitive.config;import cn.yujky.study.sensitive.service.impl.MyWordAllowImpl; import cn.yujky.study.sensitive.service.impl.MyWordDenyImpl; import com.github.houbb.sensitive.word.bs.SensitiveWordBs; import com.github.houbb.sensitive.word.support.allow.WordAllows; import com.github.houbb.sensitive.word.support.deny.WordDenys; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;gframework.context.annotation.Configuration;/*** 敏感词配置*/ Slf4j Configuration public class SensitiveWordConfig {Autowiredprivate MyWordDenyImpl myWordDeny;Autowiredprivate MyWordAllowImpl myWordAllow;/*** 初始化敏感词过滤器** return 配置好的敏感词过滤引导类*/Beanpublic SensitiveWordBs sensitiveWordBs() {log.info(本地敏感词库初始化中...);SensitiveWordBs init SensitiveWordBs.newInstance().wordDeny(WordDenys.chains(WordDenys.defaults(), myWordDeny)).wordAllow(WordAllows.chains(WordAllows.defaults(), myWordAllow)).init();log.info(本地敏感词库初始化完成);return init;} }3 自定义敏感词库 通过实现 WordDeny 和 WordAllow 接口可以分别配置屏蔽词和允许词。以下是示例代码 3.1 自定义屏蔽词MyWordDenyImpl package cn.yujky.study.sensitive.service.impl;import com.github.houbb.sensitive.word.api.IWordDeny; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.stereotype.Service;import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.List;/*** name: MyWordDeny* description: p/p* author: yujky* date: 2024/12/27 11:18*/ Slf4j Service AllArgsConstructor public class MyWordDenyImpl implements IWordDeny {private final ResourceLoader resourceLoader;Overridepublic ListString deny() {// 加载resource目录下的sensiticeWord.txt文本中的敏感词Resource resource resourceLoader.getResource(classpath:sensiticeWord.txt);// 将文件内容读取为字符串try {String content null;content new String(Files.readAllBytes(Paths.get(resource.getURI())));log.info(敏感词库加载完成敏感词数量为{}, content.split(\\n).length);log.info(敏感词库加载完成敏感词\\n {}, content);// 按换行分割return Arrays.stream(content.split(\\n)).distinct().toList();} catch (IOException e) {throw new RuntimeException(e);}} }这里的敏感词库我是直接放在resource目录下的sensiticeWord.txt文本中你也可以改为从数据库或者其他存储工具中读取 3.2 自定义允许词MyWordAllowImpl package cn.yujky.study.sensitive.service.impl;import com.github.houbb.sensitive.word.api.IWordAllow; import org.springframework.stereotype.Service;import java.util.Arrays; import java.util.List;/*** name: MyWordAllowImpl* description: p/p* author: yujky* date: 2024/12/27 11:20*/ Service public class MyWordAllowImpl implements IWordAllow {Overridepublic ListString allow() {return Arrays.asList(五星红旗);} }4. 清洗文本工具类 在敏感词检测前通常需要对文本进行预处理例如移除特殊字符、表情符号等。以下是清洗文本的工具类示例代码 package cn.yujky.study.sensitive;Slf4j public class SensitiveTextCleaner {/*** 移除 Emoji 表情** param text 输入文本* return 清洗后的文本*/public static String removeEmojis(String text) {String emojiRegex [\\x{1F600}-\\x{1F64F}\\x{1F300}-\\x{1F5FF}\\x{1F680}-\\x{1F6FF}\\x{1F700}-\\x{1F77F}\\x{1F780}-\\x{1F7FF}\\x{1F800}-\\x{1F8FF}\\x{1F900}-\\x{1F9FF}\\x{1FA00}-\\x{1FA6F}\\x{1FA70}-\\x{1FAFF}\\x{2600}-\\x{26FF}\\x{2700}-\\x{27BF}];return text.replaceAll(emojiRegex, );}/*** 移除特殊字符** param text 输入文本* return 清洗后的文本*/public static String removeSpecialCharacters(String text) {return text.replaceAll([^a-zA-Z0-9\u4e00-\u9fa5], );}/*** 综合清洗文本移除表情与特殊字符** param text 输入文本* return 清洗后的文本*/public static String cleanText(String text) {text removeEmojis(text); // 移除 Emojitext removeSpecialCharacters(text); // 移除特殊字符return text.trim().toLowerCase(); // 转小写并去除多余空格} }5. 敏感词过滤测试 在 Spring Boot 项目中通过单元测试验证过滤功能以下为完整的测试代码 package cn.yujky.study.sensitive;import com.github.houbb.sensitive.word.bs.SensitiveWordBs; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;Slf4j SpringBootTest class YujkySensitiveApplicationTests {Autowiredprivate SensitiveWordBs sensitiveWordBs;Testvoid contextLoads() {String text 操他;String cleanText SensitiveTextCleaner.cleanText(text);log.info(原文本: {}, 清洗后文本: {}, text, cleanText);// 检查是否包含敏感词boolean containsOriginal sensitiveWordBs.contains(text);boolean containsCleaned sensitiveWordBs.contains(cleanText);log.info(是否包含敏感词原文本: {}, containsOriginal);log.info(是否包含敏感词清洗后文本: {}, containsCleaned);// 控制台输出System.out.println(原文本检测结果: containsOriginal);System.out.println(清洗后文本检测结果: containsCleaned);} }5.1 测试结果示例 假设敏感词库中包含 “操” 和 “他” 原文本: 操他, 清洗后文本: 操他 是否包含敏感词原文本: false 是否包含敏感词清洗后文本: true这里建议对原文本以及清洗后的文本都进行一次检测增加敏感词的检测力度 如果你在开发过程中有其他需求或问题欢迎交流 https://web.yujky.cn/ 用户名cxks 密码 cxks123
http://www.hkea.cn/news/14507215/

相关文章:

  • 网站开发电脑设置平台公司经营范围
  • 手机怎么做钓鱼网站wordpress 主机安装教程
  • 网站测评必须做章丘建设局网站
  • 网站上展示手机页面是怎么做的wordpress获取特定尺寸特征图像
  • 中小企业做网站贷款网站建设维护成本
  • wordpress 修改页面内容如何利用seo赚钱
  • dw网页制作试题谷歌优化seo
  • 教育网站制作服务手机项目工作室
  • 江西宗杰建设工程有限公司网站泉州 网站建设
  • 交互式多媒体网站开发html5网站制作编辑源码
  • 找做网站技术人员郑州网站排名公司
  • 毕节网站开发上海网页设计
  • 云南网站建设维修公司百度灰色关键词排名
  • 定制做网站费用邯郸企业网站制作
  • 做的网站没流量如何做律师网站
  • 企业网站建设费用会计分录男人最爱的做网站
  • 建行个人网站免费的旅游网站模板
  • 做网站的地方wordpress用vps搭建
  • 网站开发人员兼职免费博客 wordpress
  • 做网站用什么国外的空间比较好网站的建设步骤
  • 做头像的网站横杆带字网站建设资金方案
  • 手机网站整站源码下载百度seo排名优化提高流量
  • 实搜石家庄网站建设小程序快速排名网站系统
  • 网站建设外包注意事项软文广告范例大全
  • 河北中太建设集团有限公司网站创建全国文明城市工作要求
  • wordpress建站教程百科传奇世界官网电脑版
  • 网站更新和维护怎么做粉色博客wordpress
  • 网站cdn自己做建立自己网站要多少钱
  • 如何寻找做网站的客户免费网站制作作业
  • 常州手机网站建设用html做的美食网站