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

相关文章

HTML5 getUserMedia API网页录音实现指南示例小结

《HTML5getUserMediaAPI网页录音实现指南示例小结》本教程将指导你如何利用这一API,结合WebAudioAPI,实现网页录音功能,从获取音频流到处理和保存录音,整个过程将逐步... 目录1. html5 getUserMedia API简介1.1 API概念与历史1.2 功能与优势1.3

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

Java实现删除文件中的指定内容

《Java实现删除文件中的指定内容》在日常开发中,经常需要对文本文件进行批量处理,其中,删除文件中指定内容是最常见的需求之一,下面我们就来看看如何使用java实现删除文件中的指定内容吧... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细介绍3.1 Ja

SpringBoot3应用中集成和使用Spring Retry的实践记录

《SpringBoot3应用中集成和使用SpringRetry的实践记录》SpringRetry为SpringBoot3提供重试机制,支持注解和编程式两种方式,可配置重试策略与监听器,适用于临时性故... 目录1. 简介2. 环境准备3. 使用方式3.1 注解方式 基础使用自定义重试策略失败恢复机制注意事项

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

在Windows上使用qemu安装ubuntu24.04服务器的详细指南

《在Windows上使用qemu安装ubuntu24.04服务器的详细指南》本文介绍了在Windows上使用QEMU安装Ubuntu24.04的全流程:安装QEMU、准备ISO镜像、创建虚拟磁盘、配置... 目录1. 安装QEMU环境2. 准备Ubuntu 24.04镜像3. 启动QEMU安装Ubuntu4

使用Python和OpenCV库实现实时颜色识别系统

《使用Python和OpenCV库实现实时颜色识别系统》:本文主要介绍使用Python和OpenCV库实现的实时颜色识别系统,这个系统能够通过摄像头捕捉视频流,并在视频中指定区域内识别主要颜色(红... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间详解

Windows下C++使用SQLitede的操作过程

《Windows下C++使用SQLitede的操作过程》本文介绍了Windows下C++使用SQLite的安装配置、CppSQLite库封装优势、核心功能(如数据库连接、事务管理)、跨平台支持及性能优... 目录Windows下C++使用SQLite1、安装2、代码示例CppSQLite:C++轻松操作SQ

PostgreSQL中MVCC 机制的实现

《PostgreSQL中MVCC机制的实现》本文主要介绍了PostgreSQL中MVCC机制的实现,通过多版本数据存储、快照隔离和事务ID管理实现高并发读写,具有一定的参考价值,感兴趣的可以了解一下... 目录一 MVCC 基本原理python1.1 MVCC 核心概念1.2 与传统锁机制对比二 Postg

SpringBoot整合Flowable实现工作流的详细流程

《SpringBoot整合Flowable实现工作流的详细流程》Flowable是一个使用Java编写的轻量级业务流程引擎,Flowable流程引擎可用于部署BPMN2.0流程定义,创建这些流程定义的... 目录1、流程引擎介绍2、创建项目3、画流程图4、开发接口4.1 Java 类梳理4.2 查看流程图4