=======IKAnalyzer ============
/**
* 重载Analyzer接口,构造分词组件
*/
@Override
protected TokenStreamComponents createComponents(String fieldName, final Reader in) {
Tokenizer _IKTokenizer = new IKTokenizer(in , this.useSmart());
return new TokenStreamComponents(_IKTokenizer);
}
=======IKTokenizer==============
/* (non-Javadoc)
* @see org.apache.lucene.analysis.TokenStream#incrementToken()
*/
@Override
public boolean incrementToken() throws IOException {
//清除所有的词元属性
clearAttributes();
Lexeme nextLexeme = _IKImplement.next();
if(nextLexeme != null){
//将Lexeme转成Attributes
//设置词元文本
termAtt.append(nextLexeme.getLexemeText());
//设置词元长度
termAtt.setLength(nextLexeme.getLength());
//设置词元位移
offsetAtt.setOffset(nextLexeme.getBeginPosition(), nextLexeme.getEndPosition());
//记录分词的最后位置
endPosition = nextLexeme.getEndPosition();
//记录词元分类
typeAtt.setType(nextLexeme.getLexemeTypeString());
//返会true告知还有下个词元
return true;
}
//返会false告知词元输出完毕
return false;
}
=======IKSegmenter==============
/**
* 分词,获取下一个词元
* @return Lexeme 词元对象
* @throws IOException
*/
public synchronized Lexeme next()throws IOException{
Lexeme l = null;
while((l = context.getNextLexeme()) == null ){
/*
* 从reader中读取数据,填充buffer
* 如果reader是分次读入buffer的,那么buffer要 进行移位处理
* 移位处理上次读入的但未处理的数据
*/
int available = context.fillBuffer(this.input);
if(available <= 0){
//reader已经读完
context.reset();
return null;
}else{
//初始化指针
context.initCursor();
do{
//遍历子分词器
for(ISegmenter segmenter : segmenters){
segmenter.analyze(context);
}
//字符缓冲区接近读完,需要读入新的字符
if(context.needRefillBuffer()){
break;
}
//向前移动指针
}while(context.moveCursor());
//重置子分词器,为下轮循环进行初始化
for(ISegmenter segmenter : segmenters){
segmenter.reset();
}
}
//对分词进行歧义处理
this.arbitrator.process(context, this.cfg.useSmart());
//将分词结果输出到结果集,并处理未切分的单个CJK字符
context.outputToResult();
//记录本次分词的缓冲区位移
context.markBufferOffset();
}
return l;
}
=====================CJKSegmenter===================
中文分词
相关推荐
Lucene学习源码.rar
此博文是对近期做lucene索引的总结, (lucene,solr,netty,hadoop),如蒙加入,不胜感激,大家共同探讨,本人争取每日一博,希望大家关注呦
Apache旗下的Lucene是一款用JAVA语言开发的最早的搜索引擎系统,对学习搜索引擎的朋友们有很大的帮助!
lucene基础学习笔记&源码
Lucene项目的文档和源码,很好的java学习资料哦
Lucene.net源码+中文学习文档,打造自己网站内的强大搜索引擎。
这是我通过对Lucene3.3.0源码进行了简单解读,依据应用详细的做了很多Demo,大家可以一道学习。
lucene in action的源码,适合学习,适合初学者使用
NULL 博文链接:https://kylinsoong.iteye.com/blog/719415
方便大家学习和使用,也方便以后再使用。 Lucene.net是我从https://svn.apache.org/repos/asf/incubator/lucene.net/tags/Lucene.Net_2_9_2/ 上下载下来的,如果你想自己下载可以按照...
lucene官方网站上的lucene3.6源码,很不错的学习资料。
学习lucene的源码资料,myeclipse环境下开发的,值得借鉴
关于lucene的源码分析书,你一定会喜欢的!学习java搜索开发的必备
NULL 博文链接:https://iamyida.iteye.com/blog/2199848
NULL 博文链接:https://huanglz19871030.iteye.com/blog/1278428
Lucene项目源码,很不错的资源,欢迎大家来下载学习。
elasticsearch +lucene4.4开发,需要源码学习的朋友别错过
]java(结合lucene)版的公交搜索系统源码,能实现全部功能,用于学习和二次开发。
NULL 博文链接:https://fishhappy365.iteye.com/blog/456739
NULL 博文链接:https://iamyida.iteye.com/blog/2207080