lucene-core-3.0.2.jar和IKAnalyzer3.2.3Stable.jar组合使用出现错误。
aunox
2011-05-27
报错误:
使用jar列表: IKAnalyzer3.2.3Stable.jar lucene-core-3.0.2.jar java代码如下: -------------------------------------------------------------------- import java.io.IOException; import java.io.StringReader; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.TermAttribute; import org.apache.lucene.analysis.tokenattributes.TypeAttribute; import org.wltea.analyzer.lucene.IKAnalyzer; public class TestIKAnalyzer { public static void main(String[] args) throws IOException { Analyzer analyzer = new IKAnalyzer(); TokenStream tokenStream = analyzer.tokenStream("", new StringReader( "永和服装饰品有限公司")); // 2.x写法 3.0之后不支持了 // Token token = new Token(); // // while (tokenStream.next(token) != null) { // System.out.println(token.term()); // } // 3.x的写法 TermAttribute termAtt = tokenStream.getAttribute(TermAttribute.class); TypeAttribute typeAtt = tokenStream.getAttribute(TypeAttribute.class); while (tokenStream.incrementToken()) { System.out.print(termAtt.term()); System.out.print(' '); System.out.println(typeAtt.type()); } } } -------------------------------------------------------------------- 控制台错误提示: -------------------------------------------------------------------- Exception in thread "main" java.lang.IllegalArgumentException: This AttributeSource does not have the attribute 'org.apache.lucene.analysis.tokenattributes.TypeAttribute'. at org.apache.lucene.util.AttributeSource.getAttribute(AttributeSource.java:277) at TestIKAnalyzer.main(TestIKAnalyzer.java:27) -------------------------------------------------------------------- 若其中使用jar包lucene-core-3.0.2.jar替换成lucene-core-2.9.1.jar,则程序运行正常。 哪位遇到过类似情况?是否有解决方案,请各位指教! |
|
JavaYog
2011-06-21
IKAnalyzer支持的lucene版本问题
|