linqy的个人博客分享 http://blog.sciencenet.cn/u/linqy

博文

获取Lucene分词的内容

已有 1554 次阅读 2017-10-24 11:45 |个人分类:Lucene|系统分类:科研笔记| Lucene, 分词

为了比较各类分词器的分词结果才能对的结果进行较

下面是获取获取Lucene分词的一段代码,返回的结果是list数组:

//获取字符串的分词结果
public static List<String> getAnalyseResult(String analyzeStr, Analyzer analyzer) {
List<String> response = new ArrayList<String>();
TokenStream tokenStream = null;
try {
tokenStream = analyzer.tokenStream("content", new StringReader(analyzeStr));
CharTermAttribute attr = tokenStream.addAttribute(CharTermAttribute.class);
tokenStream.reset();
while (tokenStream.incrementToken()) {
response.add(attr.toString());
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (tokenStream != null) {
try {
tokenStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return response;
}




https://blog.sciencenet.cn/blog-3134052-1082233.html

上一篇:java基于geotools开源包对shp文件的读取
下一篇:lucene的中词中采用mmseg4j分词,并建立索引和搜索
收藏 IP: 111.195.160.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-7 12:37

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部