cn.hutool.extra.tokenizer.engine.mmseg.MmsegEngine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hutool-all Show documentation
Show all versions of hutool-all Show documentation
Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
package cn.hutool.extra.tokenizer.engine.mmseg;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.tokenizer.Result;
import cn.hutool.extra.tokenizer.TokenizerEngine;
import com.chenlb.mmseg4j.ComplexSeg;
import com.chenlb.mmseg4j.Dictionary;
import com.chenlb.mmseg4j.MMSeg;
import java.io.StringReader;
/**
* mmseg4j分词引擎实现
* 项目地址:https://github.com/chenlb/mmseg4j-core
*
* @author looly
*
*/
public class MmsegEngine implements TokenizerEngine {
private final MMSeg mmSeg;
/**
* 构造
*/
public MmsegEngine() {
final Dictionary dict = Dictionary.getInstance();
final ComplexSeg seg = new ComplexSeg(dict);
this.mmSeg = new MMSeg(new StringReader(""), seg);
}
/**
* 构造
*
* @param mmSeg 模式{@link MMSeg}
*/
public MmsegEngine(MMSeg mmSeg) {
this.mmSeg = mmSeg;
}
@Override
public Result parse(CharSequence text) {
this.mmSeg.reset(StrUtil.getReader(text));
return new MmsegResult(this.mmSeg);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy