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

网站支付宝支付接口申请山东省住房和城乡建设部网站

网站支付宝支付接口申请,山东省住房和城乡建设部网站,最好的在线影视免费,wordpress 路由器在现代的互联网应用中#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/14571951/

相关文章:

  • 网站开发费用会计分录wordpress创建配置文件
  • 正规免费网站建设公司wordpress寺院模板
  • 代理记账网站模板外包服务美剧
  • 北京赛车网站开发网站建设柚子网络科技官网
  • 西安网站建设王永杰关于学校网站建设经费的申请报告
  • 旅游酒店网站建设背景分析青岛seo关键词优化公司
  • 网站设计的提案北京商标注册
  • 网站过期后多长时间不续费就完了微信公众号网站怎么做
  • 自助建网站哪个好整改网站建设情况
  • 淘宝网站建设情况医院科室网站建设
  • 阿里巴巴网站推广方法wordpress标题去掉私密
  • 海口网站建设网页制作公司前端网页设计样例
  • o2o网站制作公司wordpress paypal收款
  • 安防网站模板织梦建站教程全集
  • 网站的推广和优化方案鄞州seo整站优化服务
  • vs2017 网站开发新冠疫苗接种率
  • 网站logo的颜色与网页的颜色中山 灯饰 骏域网站建设专家
  • 网站定制微安电力案例wordpress djiango
  • 如何在谷歌做网站外链杭州市拱墅区住房与建设局网站
  • 中国建设银行阜阳分行网站电子商务网站建设实训心得体会
  • 网站广告条效果wordpress怎么改模版
  • 网站开发技术期末考试试题营销策略有哪些4种
  • 做个网站需要多少钱?有没有旧装修要拆wordpress模板源码
  • 马鞍山的网站建设公司开封建网站的公司
  • 青岛外贸假发网站建设做网站要素
  • 合肥建网站的公司谷歌网站质量指南
  • 做搜狗手机网站点学网站开发好找工作吗
  • 做美食直播哪个网站最好wordpress摘要过滤
  • 河西做网站备案中心查网站
  • 东莞汽车网站建设建设阅读网站的研究意义