import java.io.IOException; import java.io.StringReader; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.TermAttribute; import org.apache.lucene.analysis.tokenattributes.TypeAttribute; import jeasy.analysis.MMAnalyzer; public class JE { public static void main(String[] args) throws IOException { MMAnalyzer analyzer = new MMAnalyzer(); TokenStream ts = analyzer.tokenStream("", new StringReader("Hightman开发的一套基于词频词典的机械中文分词引擎,它能将一整段的汉字基本正确的切分成词。采用的是采集的词频词典,并辅以一定的专有名称,人名,地名,数字年代等规则识别来达到基本分词,经小范围测试大概准确率在 90% ~ 95% 之间,已能基本满足一些小型搜索引擎、关键字提取等场合运用。45Kb左右的文本切词时间是0.026秒,大概是1.5MB文本/秒,支持PHP4和PHP 5。")); TermAttribute termAtt = (TermAttribute) ts .getAttribute(TermAttribute.class); TypeAttribute typeAtt = (TypeAttribute) ts .getAttribute(TypeAttribute.class); while (ts.incrementToken()) { System.out.print(termAtt.term()); System.out.print(" "); System.out.println(typeAtt.type()); } } }
je 分词及 Lucene2.9 TokenStream新的遍历方法
本文展示了一个使用Java实现的Lucene分词器示例,该分词器基于词频词典进行中文分词,能够将连续的汉字文本正确切分为独立词汇。测试显示其分词准确率约为90%-95%,适用于小型搜索引擎和关键字提取等场景。

被折叠的 条评论
为什么被折叠?



