lucene 4.6以上和4.6一下分词需要注意的

    xiaoxiao2025-09-12  52

    /** * 得到分词list *  * @param text * @param analyzer * @return */ public static List<String> getIkFc(String text, Analyzer analyzer) { StringReader reader = new StringReader(text); List<String> list = new ArrayList<String>(); TokenStream ts; try { ts = analyzer.tokenStream("", reader); CharTermAttribute term = ts.getAttribute(CharTermAttribute.class); ts.reset();//lucene 4.6以上要加这个,4.6以前不需要,本人测试的是4.2 .0不需要,4.10.4需要 while (ts.incrementToken()) { list.add(term.toString()); } } catch (IOException e) { e.printStackTrace(); } System.out.println(list); reader.close(); return list; } 相关资源:中文分词lucene
    最新回复(0)