apdplat.word.WordSegmenter分词功能使用自有词库,实现过滤功能,可是实际上,导致的结果差强人意,没办法只能使用JDK的自带过滤的功能

本文主要是介绍apdplat.word.WordSegmenter分词功能使用自有词库,实现过滤功能,可是实际上,导致的结果差强人意,没办法只能使用JDK的自带过滤的功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

WOrd的分词功能,自定义的词库,可以使用自定义的,可是实际上自带的词库实在是无法删除,导致的分词的效果很差劲


import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.apdplat.word.WordSegmenter;
import org.apdplat.word.dictionary.DictionaryFactory;
import org.apdplat.word.segmentation.Word;
import org.apdplat.word.util.WordConfTools;import java.util.ArrayList;
import java.util.List;/********************************************* 模块名称: 主要功能是做标题分词的操作,工具类* 功能说明: * 开发人员:  * 开发时间:2020/8/29 12:21   * v1.0.0.0 2020/8/29-01    *******************************************/public class WordPartitionUtils {public static void main(String[] args) {//分词效果加载词库DictionaryFactory.getDictionary().clear();List<String> parameterList = new ArrayList<>();parameterList.add("对决");DictionaryFactory.getDictionary().addAll(parameterList);//词典WordConfTools.set("dic.path", "classpath:word/custom.txt");//词性标注数据WordConfTools.set("part.of.speech.dic.path", "classpath:word/part_of_speech.txt");//词性说明数据WordConfTools.set("part.of.speech.des.path", "classpath:word/part_of_speech_des.txt");//二元模型WordConfTools.set("bigram.path", "classpath:word/bigram.txt");//三元模型WordConfTools.set("trigram.path", "classpath:word/trigram.txt");//停用词词典WordConfTools.set("stopwords.path", "classpath:word/stopwords.txt");//用于分割词的标点符号WordConfTools.set("punctuation.path", "classpath:word/punctuation.txt");//百家姓WordConfTools.set("surname.path", "classpath:word/surname.txt");//数量词WordConfTools.set("quantifier.path", "classpath:word/quantifier.txt");//     WordConfTools.forceOverride("classpath:custom.txt");
//        WordConfTools.set("dic.path", "classpath:dic.txt,classpath:custom.txt");DictionaryFactory.reload();String title = "<刺猬索尼克>曝正片片段,音速小子上演高萌对决";List<Word> list = WordSegmenter.seg(title);String value = WordConfTools.get("dic.path");System.out.println(JSON.toJSONString(list));System.out.println("value =" + value);}/*** 针对【标题不含QYJC(企业简称) 且 标题不含负面关键词 且 标题不含重要关键词 且 dsCode为转化率低于50%的栏目】进行过滤** @param title  入参 标题* @param dsCode 资讯的编码* @return false 不满足条件,true满足条件*/public Boolean isContionWord(String title, String dsCode, List<String> parameterDsCodeList) {Boolean wordFlag = false;List<Word> list = WordSegmenter.seg(title);for (Word word : list) {if (word.getPartOfSpeech() != null && word.getPartOfSpeech().getPos().equals("i")) {if (StringUtils.isNotBlank(word.getText())) { //匹配上的关键字wordFlag = true;
//                    log.error("【Word分词标题为】:{},【匹配上关键字】:{}", title, word.getText());} else {
//                    log.error("【Word分词标题为】:{},【匹配关键字-无】", title);}break;}}if (wordFlag && parameterDsCodeList.contains(dsCode)) {return true;}return false;}

运行结果:

SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
[{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"des":"未知","pos":"i"},"synonym":[],"text":"刺"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"$ref":"$[0].partOfSpeech"},"synonym":[],"text":"猬"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"des":"","pos":"nr"},"synonym":[],"text":"索尼克"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"$ref":"$[0].partOfSpeech"},"synonym":[],"text":"曝"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"$ref":"$[0].partOfSpeech"},"synonym":[],"text":"正"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"$ref":"$[0].partOfSpeech"},"synonym":[],"text":"片"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"$ref":"$[0].partOfSpeech"},"synonym":[],"text":"片段"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"$ref":"$[0].partOfSpeech"},"synonym":[],"text":"音"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"$ref":"$[0].partOfSpeech"},"synonym":[],"text":"速"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"$ref":"$[0].partOfSpeech"},"synonym":[],"text":"小"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"$ref":"$[0].partOfSpeech"},"synonym":[],"text":"子"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"$ref":"$[0].partOfSpeech"},"synonym":[],"text":"上演"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"des":"","pos":"nr"},"synonym":[],"text":"高萌对"},{"acronymPinYin":"","antonym":[],"frequency":0,"fullPinYin":"","partOfSpeech":{"$ref":"$[0].partOfSpeech"},"synonym":[],"text":"决"}]
value =classpath:word/custom.txt

使用Word分词来实现文本的过滤,效果耗时是单位数;

 

使用JDK的过滤stream流式来实现文本的过滤,效果耗时是单位数;差异不大

SELECTt.keyword AS '标题',t.tag_count AS '耗时(毫秒)',t.tags AS '过滤方式',t.remark AS '返回匹配结果',t.is_add AS '结果0 false 1 true',t.xwbt AS '返回结果',t.mtcc AS '数据编码',t.update_time AS '操作时间'
FROMtbm_news_log t where  t.tags='WORD'
ORDER BYt.id DESC   limit 1000;
SELECTt.keyword AS '标题',t.tag_count AS '耗时(毫秒)',t.tags AS '过滤方式',t.remark AS '返回匹配结果',t.is_add AS '结果0 false 1 true',t.xwbt AS '返回结果',t.mtcc AS '数据编码',t.update_time AS '操作时间'
FROMtbm_news_log t where  t.tags='JDKCONTAINS'
ORDER BYt.id DESC  limit 1000;

 

综上是redis先缓存8万条数据,然后进行过滤,

测试1000条数据的标题过滤效果如截图,差异不明显。

 

 

依赖pom.xml

 

<!-- https://mvnrepository.com/artifact/com.janeluo/ikanalyzer -->
<dependency><groupId>com.janeluo</groupId><artifactId>ikanalyzer</artifactId><version>2012_u6</version><exclusions><exclusion><artifactId>lucene-queryparser</artifactId><groupId>org.apache.lucene</groupId></exclusion><exclusion><artifactId>lucene-core</artifactId><groupId>org.apache.lucene</groupId></exclusion><exclusion><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId></exclusion></exclusions>
</dependency><dependency><groupId>org.apdplat</groupId><artifactId>word</artifactId><version>${apdplat.word.version}</version><exclusions><exclusion><artifactId>lucene-queryparser</artifactId><groupId>org.apache.lucene</groupId></exclusion><exclusion><artifactId>lucene-core</artifactId><groupId>org.apache.lucene</groupId></exclusion><exclusion><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId></exclusion><exclusion><groupId>org.apache.lucene</groupId><artifactId>lucene-analyzers-common</artifactId></exclusion></exclusions>
</dependency>

 

这篇关于apdplat.word.WordSegmenter分词功能使用自有词库,实现过滤功能,可是实际上,导致的结果差强人意,没办法只能使用JDK的自带过滤的功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1045888

相关文章

使用Python删除Excel中的行列和单元格示例详解

《使用Python删除Excel中的行列和单元格示例详解》在处理Excel数据时,删除不需要的行、列或单元格是一项常见且必要的操作,本文将使用Python脚本实现对Excel表格的高效自动化处理,感兴... 目录开发环境准备使用 python 删除 Excphpel 表格中的行删除特定行删除空白行删除含指定

深入理解Go语言中二维切片的使用

《深入理解Go语言中二维切片的使用》本文深入讲解了Go语言中二维切片的概念与应用,用于表示矩阵、表格等二维数据结构,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习吧... 目录引言二维切片的基本概念定义创建二维切片二维切片的操作访问元素修改元素遍历二维切片二维切片的动态调整追加行动态

Linux下删除乱码文件和目录的实现方式

《Linux下删除乱码文件和目录的实现方式》:本文主要介绍Linux下删除乱码文件和目录的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux下删除乱码文件和目录方法1方法2总结Linux下删除乱码文件和目录方法1使用ls -i命令找到文件或目录

prometheus如何使用pushgateway监控网路丢包

《prometheus如何使用pushgateway监控网路丢包》:本文主要介绍prometheus如何使用pushgateway监控网路丢包问题,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录监控网路丢包脚本数据图表总结监控网路丢包脚本[root@gtcq-gt-monitor-prome

SpringBoot+EasyExcel实现自定义复杂样式导入导出

《SpringBoot+EasyExcel实现自定义复杂样式导入导出》这篇文章主要为大家详细介绍了SpringBoot如何结果EasyExcel实现自定义复杂样式导入导出功能,文中的示例代码讲解详细,... 目录安装处理自定义导出复杂场景1、列不固定,动态列2、动态下拉3、自定义锁定行/列,添加密码4、合并

mybatis执行insert返回id实现详解

《mybatis执行insert返回id实现详解》MyBatis插入操作默认返回受影响行数,需通过useGeneratedKeys+keyProperty或selectKey获取主键ID,确保主键为自... 目录 两种方式获取自增 ID:1. ​​useGeneratedKeys+keyProperty(推

Spring Boot集成Druid实现数据源管理与监控的详细步骤

《SpringBoot集成Druid实现数据源管理与监控的详细步骤》本文介绍如何在SpringBoot项目中集成Druid数据库连接池,包括环境搭建、Maven依赖配置、SpringBoot配置文件... 目录1. 引言1.1 环境准备1.2 Druid介绍2. 配置Druid连接池3. 查看Druid监控

Python通用唯一标识符模块uuid使用案例详解

《Python通用唯一标识符模块uuid使用案例详解》Pythonuuid模块用于生成128位全局唯一标识符,支持UUID1-5版本,适用于分布式系统、数据库主键等场景,需注意隐私、碰撞概率及存储优... 目录简介核心功能1. UUID版本2. UUID属性3. 命名空间使用场景1. 生成唯一标识符2. 数

Linux在线解压jar包的实现方式

《Linux在线解压jar包的实现方式》:本文主要介绍Linux在线解压jar包的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux在线解压jar包解压 jar包的步骤总结Linux在线解压jar包在 Centos 中解压 jar 包可以使用 u

SpringBoot中如何使用Assert进行断言校验

《SpringBoot中如何使用Assert进行断言校验》Java提供了内置的assert机制,而Spring框架也提供了更强大的Assert工具类来帮助开发者进行参数校验和状态检查,下... 目录前言一、Java 原生assert简介1.1 使用方式1.2 示例代码1.3 优缺点分析二、Spring Fr