优化TokenizerEngine使用IK分词器支持并发

This commit is contained in:
Looly 2023-12-14 17:44:57 +08:00
parent 90772da8d9
commit 9bb370c476
2 changed files with 5 additions and 8 deletions

View File

@ -2,7 +2,7 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.24(2023-12-13)
# 5.8.24(2023-12-14)
### 🐣新特性
* 【cache 】 Cache增加get重载可自定义超时时间issue#I8G0DL@Gitee
@ -12,6 +12,7 @@
* 【extra 】 SpringUtil增加getProperty重载pr#1122@Gitee
* 【core 】 FileTypeUtil增加null判断issue#3419@Github
* 【core 】 DateUtil.parse支持毫秒时间戳issue#I8NMP7@Gitee
* 【extra 】 优化TokenizerEngine使用IK分词器支持并发pr#3427@Github
### 🐞Bug修复
* 【core 】 修复LocalDateTime#parseDate未判断空问题问题issue#I8FN7F@Gitee

View File

@ -1,10 +1,8 @@
package cn.hutool.extra.tokenizer.engine.ikanalyzer;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.tokenizer.Result;
import cn.hutool.extra.tokenizer.TokenizerEngine;
import org.wltea.analyzer.cfg.Configuration;
import org.wltea.analyzer.core.IKSegmenter;
/**
@ -15,27 +13,25 @@ import org.wltea.analyzer.core.IKSegmenter;
*/
public class IKAnalyzerEngine implements TokenizerEngine {
private final IKSegmenter seg;
/**
* 构造
*/
public IKAnalyzerEngine() {
this(new IKSegmenter(null, true));
}
/**
* 构造
*
* @param seg {@link IKSegmenter}
* @deprecated 并发问题导致无法共用IKSegmenter因此废弃
*/
@Deprecated
public IKAnalyzerEngine(IKSegmenter seg) {
this.seg = seg;
}
@Override
public Result parse(CharSequence text) {
IKSegmenter copySeg = new IKSegmenter(null, (Configuration) ReflectUtil.getFieldValue(this.seg, "cfg"));
final IKSegmenter copySeg = new IKSegmenter(null, true);
copySeg.reset(StrUtil.getReader(text));
return new IKAnalyzerResult(copySeg);
}