Lucene 4.6.1 java.lang.IllegalStateException: TokenStream contract violation
来源:互联网 发布:淘宝直通车行业点击率 编辑:程序博客网 时间:2024/06/05 18:29
这是旧代码在新版本Lucene中出现的异常,异常如下:
Exception in thread "main" java.lang.IllegalStateException: TokenStream contract violation: reset()/close() call missing, reset() called multiple times, or subclass does not call super.reset(). Please see Javadocs of TokenStream class for more information about the correct consuming workflow.
at org.apache.lucene.analysis.Tokenizer$1.read(Tokenizer.java:110)
at java.io.Reader.read(Reader.java:140)
at org.wltea.analyzer.core.AnalyzeContext.fillBuffer(AnalyzeContext.java:124)
at org.wltea.analyzer.core.IKSegmenter.next(IKSegmenter.java:122)
at org.wltea.analyzer.lucene.IKTokenizer.incrementToken(IKTokenizer.java:78)
at com.hankcs.train.IKHelper.parse(IKHelper.java:36)
at com.hankcs.train.AnalysisAdjuster.handleFile(AnalysisAdjuster.java:44)
at com.hankcs.train.AnalysisAdjuster.main(AnalysisAdjuster.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Process finished with exit code 1
旧代码:
IKAnalyzer ss =
new
IKAnalyzer();
StringReader reader =
new
StringReader(str);
try
{
TokenStream tokenStream = ss.tokenStream(
""
, reader);
while
(tokenStream.incrementToken())
{
CharTermAttribute termAttribute = tokenStream.getAttribute(CharTermAttribute.
class
);
System.out.println(termAttribute.toString());
}
}
catch
(IOException e)
{
e.printStackTrace();
}
根据新的API文档,调用TokenStream API的流程必须是:
The workflow of the new
TokenStream
API is as follows:
Instantiation of
TokenStream
/TokenFilter
s which add/get attributes to/from theAttributeSource
.The consumer calls
reset()
.The consumer retrieves attributes from the stream and stores local references to all attributes it wants to access.
The consumer calls
incrementToken()
until it returns false consuming the attributes after each call.The consumer calls
end()
so that any end-of-stream operations can be performed.The consumer calls
close()
to release any resource when finished using theTokenStream
.
所以代码必须在incrementToken()
之前调用一次reset()
:
IKAnalyzer ss =
new
IKAnalyzer();
StringReader reader =
new
StringReader(str);
try
{
TokenStream tokenStream = ss.tokenStream(
""
, reader);
tokenStream.reset();
while
(tokenStream.incrementToken())
{
CharTermAttribute termAttribute = tokenStream.getAttribute(CharTermAttribute.
class
);
System.out.println(termAttribute.toString());
}
}
catch
(IOException e)
{
e.printStackTrace();
}
- Lucene 4.6.1 java.lang.IllegalStateException: TokenStream contract violation
- IKAnalyzer2012FF + Lucene4.9 TokenStream contract violation: reset()/close() call missing
- Glassfish启动异常: java.lang.IllegalStateException:Class invariant violation
- 配置Paoding分词时出现的错误:java.lang.AbstractMethodError: org.apache.lucene.analysis.TokenStream.incrementToken()
- 配置Paoding分词时出现的错误:java.lang.AbstractMethodError: org.apache.lucene.analysis.TokenStream.incrementTo
- lucene TokenStream类学习
- java.lang.IllegalStateException翻译
- java.lang.IllegalStateException 异常
- java.lang.IllegalStateException
- java.lang.IllegalStateException 解决办法
- java.lang.IllegalStateException
- java.lang.IllegalStateException ,IllegalComponentStateException
- struts2 java.lang.IllegalStateException
- java.lang.IllegalStateException
- java.lang.IllegalStateException
- java.lang.IllegalStateException
- java.lang.IllegalStateException: EMF2DOMAdapterImpl_ERROR_0
- java.lang.IllegalStateException
- struts2 datetimepicker标签的使用
- [Hibernate系列—] 2. 创建SessionFactory 与 Session
- 推理题 2014 TCO Round 2B 500 SumAndProductPuzzle
- 设计模式之迭代器模式
- 自己对集合知识几点总结
- Lucene 4.6.1 java.lang.IllegalStateException: TokenStream contract violation
- Python正则之预编译表达式re.compile()
- 【点击模型学习笔记】A survey on click modeling in web search_Lianghao Li_ppt
- C语言 运算符 优先级 和 口诀
- Tomcat端口号设置
- Zen Coding:css,html缩写替换大观---让你的html,css飞起来
- Effect of Switchovers, Failovers, and Control File Creation on Backups
- 一、排序_练习_1023_2
- 个人网站搬迁到CSDN