Lucene分词器解析-代码篇
来源:互联网 发布:淘宝活动页面代码 编辑:程序博客网 时间:2024/06/08 03:47
</pre><pre code_snippet_id="1596031" snippet_file_name="blog_20160303_2_418520" name="code" class="java"><pre name="code" class="java">Lucene版本:5.2.1java版本:1.8测试时间:2016-3-3 16:04:57显示分词效果
public static void displayToken(String str,Analyzer a) {try {TokenStream stream = a.tokenStream("content",new StringReader(str));//创建一个属性,这个属性会添加流中,随着这个TokenStream增加CharTermAttribute cta = stream.addAttribute(CharTermAttribute.class);stream.reset();while(stream.incrementToken()) {System.out.print("["+cta+"]");}stream.end();System.out.println();} catch (IOException e) {e.printStackTrace();}}
//显示所有token过程
<span style="white-space:pre"></span>public static void displayAllTokenInfo(String str,Analyzer a) {try {TokenStream stream = a.tokenStream("content",new StringReader(str));//位置增量的属性,存储语汇单元之间的距离PositionIncrementAttribute pia = stream.addAttribute(PositionIncrementAttribute.class);//每个语汇单元的位置偏移量OffsetAttribute oa = stream.addAttribute(OffsetAttribute.class);//存储每一个语汇单元的信息(分词单元信息)CharTermAttribute cta = stream.addAttribute(CharTermAttribute.class);//使用的分词器的类型信息TypeAttribute ta = stream.addAttribute(TypeAttribute.class);stream.reset();for(;stream.incrementToken();) {System.out.print(pia.getPositionIncrement()+":");System.out.print(cta+"["+oa.startOffset()+"-"+oa.endOffset()+"]-->"+ta.type()+"\n");}} catch (Exception e) {e.printStackTrace();}}
@Test//测试工具类
public void test01() {Analyzer a1 = new StandardAnalyzer();Analyzer a2 = new StopAnalyzer();Analyzer a3 = new SimpleAnalyzer();Analyzer a4 = new WhitespaceAnalyzer();String txt = "this is GS/MC " +"My email is info@163.com,My QQ is 65356435";AnalyzerUtils.displayToken(txt, a1);AnalyzerUtils.displayToken(txt, a2);AnalyzerUtils.displayToken(txt, a3);AnalyzerUtils.displayToken(txt, a4);}
1 0
- Lucene分词器解析-代码篇
- lucene分词器解析
- lucene分词器分词
- lucene常用分词器——代码
- lucene分词器分词demo
- lucene(四) lucene分词器
- Lucene分词器(搜索关键字解析器)
- Lucene 分词器学习
- Lucene 自定义分词器
- lucene 分词器Analyzer
- Lucene Analyzer(分词器)
- Lucene分词器测试
- lucene 分词器
- Lucene-分词器
- lucene分词器
- Lucene 分词器
- Lucene中的分词器
- lucene分词器介绍
- super和this使用举例,以及方法覆盖和重载举例
- 模糊搜索(searchBar)
- 在centos上配置redis集群
- 重绘UITableViewCell分割线
- 关于时间显示为今天、昨天、星期一之类的格式问题
- Lucene分词器解析-代码篇
- Emacs折腾01-配置文件重定向
- 简单的spring使用反射实现属性赋值demo
- IOS开发选择图片(相机或者图库)
- Layout 的clone
- oracle--物化视图
- opencl:改造C++接口增加对内存编译(compile)的支持
- 使用NSThread让字体一个一个弹出
- mysql查询今天、昨天、上周