IKAnalyzer分词器自定义扩展字典设置不起作用
时间: 2014-03-29来源:开源中国
前景提要
HDC调试需求开发(15万预算),能者速来!>>> public class TestIKAnalyzer2 { public static void main(String[] args) throws IOException { String text = "2012年欧洲杯四强赛"; Analyzer analyzer = new IKAnalyzer(true); TokenStream tokenStream = analyzer.tokenStream("content", new StringReader(text)); CharTermAttribute term= tokenStream.addAttribute(CharTermAttribute.class); tokenStream.reset(); while(tokenStream.incrementToken()){ System.out.print(term.toString() + "/"); } tokenStream.end(); tokenStream.close(); } }


IKAnalyzer配置如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>IK Analyzer 扩展配置</comment> <!-- 用户可以在这里配置自己的扩展字典 --> <entry key="ext_dict">ext.dic</entry> <!-- 用户可以在这里配置自己的扩展停用词字典 --> <entry key="ext_stopwords">chinese_stopword.dic;english_stopword.dic</entry> </properties>



ext.dic是自定义扩展词库,我在里面添加了一项: 欧洲杯四强赛希望IKAnalyzer能把它当作一个词,不要把它拆分,可是运行结果却是: 加载扩展词典:/ext.dic 加载扩展停止词典:chinese_stopword.dic 加载扩展停止词典:english_stopword.dic 2012年/欧洲杯/四强赛/
我希望是:2012年/欧洲杯四强赛/ Lucene我用的是最新版4.7, IKAnalyzer也是最新版

科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行