github地址: https://github.com/hongfuli/elasticsearch-analysis-jieba

基于 jiebaelasticsearch 中文分词插件。

集成到ElasticSearch

git clone git@github.com:hongfuli/elasticsearch-analysis-jieba.git
cd elasticsearch-analysis-jieba
mvn package

把release/elasticsearch-analysis-jieba-{version}.zip文件解压到 elasticsearch 的 plugins 目录下,重启elasticsearch即可。

直接使用Tokenizer分词

可直接使用 com.github.hongfuli.jieba.Tokenizer 对文本字符进行分词,方法参数完全和 jieba python 一致。

imort com.github.hongfuli.jieba.Tokenizer

Tokenizer t = new Tokenizer();
t.cut("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。", false, true);

集成到Lucene

import com.github.hongfuli.jieba.lucene.JiebaAnalyzer;

Analyzer analyzer = new JiebaAnalyzer();
try(TokenStream ts = analyzer.tokenStream("field", "这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")) {
StringBuilder b = new StringBuilder();
CharTermAttribute termAtt = ts.getAttribute(CharTermAttribute.class);
PositionIncrementAttribute posIncAtt = ts.getAttribute(PositionIncrementAttribute.class);
PositionLengthAttribute posLengthAtt = ts.getAttribute(PositionLengthAttribute.class);
OffsetAttribute offsetAtt = ts.getAttribute(OffsetAttribute.class);
assertNotNull(offsetAtt);
ts.reset();
int pos = -1;
while (ts.incrementToken()) {
pos += posIncAtt.getPositionIncrement();
b.append(termAtt);
b.append(" at pos=");
b.append(pos);
if (posLengthAtt != null) {
b.append(" to pos=");
b.append(pos + posLengthAtt.getPositionLength());
}
b.append(" offsets=");
b.append(offsetAtt.startOffset());
b.append('-');
b.append(offsetAtt.endOffset());
b.append('\n');
}
ts.end();
return b.toString();
}

最新文章

  1. DPA 9.1.85 升级到DPA 10.0.352流程
  2. [WebService]之DTD
  3. MSSQLSERVER数据库- 打开表出现目录名无效
  4. es6小技巧
  5. 常用Linux VPS/服务器SSH连接工具 - Xshell下载与使用
  6. Coursera, Machine Learning, Neural Networks: Representation - week4/5
  7. Dubbox:来自当当网的SOA服务框架
  8. Java知多少(90)菜单
  9. PHP操作数据库函数比较
  10. Linux服务器部署系列之七—OpenLDAP篇
  11. 2017-2018-2 20155315《网络对抗技术》Exp4:恶意代码分析
  12. Python :random 随机数生成
  13. MySQL Group Replication 介绍
  14. 洛谷P1528 切蛋糕 [搜索,二分答案]
  15. 使用postman实现半自动化
  16. ccf201703-2 STLlist
  17. SQL Server 使用分区函数实现查询优化
  18. Office加载项对Excel进行读写操作
  19. scrapy爬虫 函数间传值简易教程
  20. A norm is a function. 范数是函数。

热门文章

  1. redis介绍 (8) window 下redis的集群(cluster命令)
  2. (网页)the server responded with a status of 403 (Forbidden)
  3. 消除TortoiseSVN 检出到(checkout)桌面上显示一堆问号
  4. [Kali_Debian] 清除无用的库文件(清理系统,洁癖专用)-布布扣-bubuko.com - Google Chrome
  5. 前端使用 validate , 根据条件进行动态的验证添加
  6. Parameter infoDTOs of type T from private T com.ListVO.setInfoDTOs is not resolvable to a concrete type.
  7. 【17】有关python面向对象编程的提高【多继承、多态、类属性、动态添加与限制添加属性与方法、@property】
  8. css实现不定高度的元素垂直居中问题
  9. Android中消息系统模型和Handler Looper
  10. mini2440裸机试炼之—RTC闹钟中断,节拍中断