当前位置:首页 > 编程笔记 > 正文
已解决

springboot集成jieba分词

来自网友在路上 156856提问 提问时间:2023-09-27 13:07:34阅读次数: 56

最佳答案 问答题库568位专家为你答疑解惑

pom:

<dependency><groupId>com.huaban</groupId><artifactId>jieba-analysis</artifactId><version>1.0.2</version>
</dependency>

test:

public void demo() {String content = "知吾煮牛奶锅";JiebaSegmenter segmenter = new JiebaSegmenter();List<String> result = segmenter.sentenceProcess(content);System.out.println("分词:" + result);
}-- [知吾煮, 牛奶, 锅]

自定义分词:

在项目resources 下创建文件 dicts/jieba.dict, 添加 “奶锅  802 n” ,想要优先展示自定义的词 可提高自定义的词频权重。

 public void demo() {String content = "知吾煮牛奶锅";JiebaSegmenter segmenter = new JiebaSegmenter();List<String> result = segmenter.sentenceProcess(content);System.out.println("分词:" + result);// Path path = Paths.get("D:\\data\\test\\test.txt");Path path = Paths.get(new File(getClass().getClassLoader().getResource("dicts/jieba.dict").getPath()).getAbsolutePath());WordDictionary.getInstance().loadUserDict(path);List<String> result2 = segmenter.sentenceProcess(content);System.out.println("自定义分词:" + result2);}-- 分词:[知吾煮, 牛奶, 锅]
-- 自定义分词:[知吾煮, 牛, 奶锅]

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"springboot集成jieba分词":http://eshow365.cn/6-14685-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!