通过学习Lucene3.5.0的doc文档,对不同release版本 lucene版本的API改动做分析。最后找到了有价值的改动信息。

  • LUCENE-2302: Deprecated TermAttribute and replaced by a new CharTermAttribute. The change is backwards compatible, so mixed new/old TokenStreams all work on the same char[] buffer independent of which interface they use. CharTermAttribute has shorter method names and implements CharSequence and Appendable. This allows usage like Java's StringBuilder in addition to direct char[] access. Also terms can directly be used in places where CharSequence is allowed (e.g. regular expressions). (Uwe Schindler, Robert Muir)
  • 以上信息可以知道,原来的通过的方法已经不能够提取响应的Token了
    [java] view plaincopyprint?
    1. StringReader reader = new StringReader(s);
    2. TokenStream ts =analyzer.tokenStream(s, reader);
    3. TermAttribute ta = ts.getAttribute(TermAttribute.class);

    StringReader reader = new StringReader(s); TokenStream ts =analyzer.tokenStream(s, reader); TermAttribute ta = ts.getAttribute(TermAttribute.class);

  • 通过分析Api文档信息 可知,CharTermAttribute已经成为替换TermAttribute的接口
  • 因此我编写了一个例子来更好的从TokenStream中提取Token
  • [html] view plaincopyprint?
    1. package com.segment;
    2. import java.io.StringReader;
    3. import org.apache.lucene.analysis.Analyzer;
    4. import org.apache.lucene.analysis.Token;
    5. import org.apache.lucene.analysis.TokenStream;
    6. import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
    7. import org.apache.lucene.analysis.tokenattributes.TermAttribute;
    8. import org.apache.lucene.util.AttributeImpl;
    9. import org.wltea.analyzer.lucene.IKAnalyzer;
    10. public class Segment {
    11. public static String show(Analyzer a, String s) throws Exception {
    12. StringReader reader = new StringReader(s);
    13. TokenStream ts = a.tokenStream(s, reader);
    14. String s1 = "", s2 = "";
    15. boolean hasnext= ts.incrementToken();
    16. //Token t = ts.next();
    17. while (hasnext) {
    18. //AttributeImpl ta = new AttributeImpl();
    19. CharTermAttribute ta = ts.getAttribute(CharTermAttribute.class);
    20. //TermAttribute ta = ts.getAttribute(TermAttribute.class);
    21. s2 = ta.toString() + " ";
    22. s1 += s2;
    23. hasnext = ts.incrementToken();
    24. }
    25. return s1;
    26. }
    27. public String segment(String s) throws Exception {
    28. Analyzer a = new IKAnalyzer();
    29. return show(a, s);
    30. }
    31. public static void main(String args[])
    32. {
    33. String name = "我是俊杰,我爱编程,我的测试用例";
    34. Segment s = new Segment();
    35. String test = "";
    36. try {
    37. System.out.println(test+s.segment(name));
    38. } catch (Exception e) {
    39. // TODO Auto-generated catch block
    40. e.printStackTrace();
    41. }
    42. }
    43. }

基于Lucene3.5.0如何从TokenStream获得Token相关推荐

  1. 基于Lucene3.5.0怎样从TokenStream获得Token

    通过学习Lucene3.5.0的doc文档,对不同release版本号 lucene版本号的API修改做分析.最后找到了有价值的修改信息. LUCENE-2302: Deprecated TermAt ...

  2. Element 2.6.0 发布,基于 Vue 2.0 的桌面端组件库

    开发四年只会写业务代码,分布式高并发都不会还做程序员?   Element 2.6.0 发布了,Element 是一套为开发者.设计师和产品经理准备的基于 Vue 2.0 的桌面端组件库,提供了配套设 ...

  3. 深度学习实战—基于TensorFlow 2.0的人工智能开发应用

    作者:辛大奇 著 出版社:中国水利水电出版社 品牌:智博尚书 出版时间:2020-10-01 深度学习实战-基于TensorFlow 2.0的人工智能开发应用

  4. 谈谈基于OAuth 2.0的第三方认证 [上篇]

    对于目前大部分Web应用来说,用户认证基本上都由应用自身来完成.具体来说,Web应用利用自身存储的用户凭证(基本上是用户名/密码)与用户提供的凭证进行比较进而确认其真实身份.但是这种由Web应用全权负 ...

  5. 基于TensorFlow 2.0的中文深度学习开源书来了!GitHub趋势日榜第一,斩获2K+星

    十三 发自 凹非寺  量子位 报道 | 公众号 QbitAI TensorFlow 2.0 发布已有一个半月之久,你会用了吗? 近日,一个叫做深度学习开源书的项目在火了.GitHub趋势日榜排名全球第 ...

  6. 基于.Net 2.0 (C# 2.0, ASP.NET 2.0)的快速Web开发框架设计

    基于.Net 2.0 (C# 2.0, ASP.NET 2.0)的快速Web开发框架设计 整个Framework结构如下: Framework.Common - 常用组件(Design By Cont ...

  7. 基于stm32、0.96寸OLED实现的贪吃蛇小游戏(详细源码注释)

    简介:本实验基于stm32最小系统.0.96寸OLED(68*128)和摇杆实现一个经典的贪吃蛇小游戏.项目源码地址:点击下载. 硬件设计: 普通摇杆,0.96寸OLED 单色屏幕(SPI协议通讯), ...

  8. 基于stm32、0.96寸OLED实现的俄罗斯方块小游戏(详细源码注释)

    概述:本实验基于stm32最小系统.0.96寸OLED(68*128)和摇杆实现一个经典的俄罗斯方块小游戏.项目源码地址:点击下载. 硬件要求: 普通摇杆,两个电位器和一个开关组成,左右摇动控制一个电 ...

  9. 鸿蒙系统8xmax,华为8月9日发布基于安卓10.0全新系统:自主鸿蒙会同台亮相

    7月27日消息,对于即将开幕的华为开发者大会,华为终端官方再次给出消息称,在8月9日首天的大会上,他们将发布新一代基于Android Q(也叫做Android 10.0)的手机系统EMUI 10.0. ...

最新文章

  1. R语言plotly可视化:plotly可视化水平直方图(Horizontal Histogram)
  2. 【GPU推荐】高性价比GPU平台,3090赶紧入手!(11.11种草狂欢)
  3. python爬虫 小白轻松从0到1_小白学 Python 爬虫(1):开篇
  4. charles都踩过哪些坑_开水果店的你,踩过了哪些坑?
  5. 2015年上半年 软件设计师 上午试卷 综合知识-2
  6. python app mysql_Python 操作 MySQL 的5种方式
  7. C++第二次上机5-5
  8. Linux服务器的攻防技术
  9. Android - 应用程序的优先级和进程状态
  10. #翻译#将像素绘制到屏幕上
  11. 什么是技术档案(Technical Archives)?
  12. 服务器虚拟化技术有kvm,只用VMware开虚拟机?来了解一下更强大KVM虚拟化技术
  13. 用户登录 kibana 时,提示 “no permissions...” ,导致用户无法查看 log
  14. c语言运行后tecplot云图,tecplot执行fluent后处理截面云图显示-20210327085801.docx-原创力文档...
  15. 运营商常见的大数据业务学习笔记
  16. 计算机技术发展的一些随笔总结(我们需要思考)
  17. 三种样式的九九乘法表—C语言
  18. git初使用之配置-.gitconfig .gitignore
  19. 【2022最新Java面试宝典】—— Java并发编程面试题(123道含答案)
  20. Unity Atlas

热门文章

  1. [期末复习]路由交换考试题
  2. DVD支持的视频格式
  3. 解决selenium在IE11中文本输入太慢的问题
  4. windows更换应用程序图标
  5. Delphi Android 取App的名称。
  6. 鸿蒙APP开发入门到进阶 | 入门完整篇。
  7. asp.net asp:Repeater下的 asp:LinkButton CommandArgument点击事件
  8. .net mysql transactionscope_TransactionScope事务处理方法介绍及.NET Core中的注意事项
  9. php 图片印章_PHP实现印章输出
  10. 情商高就是说话让人舒服