国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ik-analysis for lucene 5.x

2019-11-09 20:44:53
字體:
來源:轉載
供稿:網友

package org.wltea.analyzer.lucene; import java.io.IOException; import org.apache.lucene.analysis.Tokenizer;import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;import org.apache.lucene.analysis.tokenattributes.TypeAttribute;import org.wltea.analyzer.core.IKSegmenter;import org.wltea.analyzer.core.Lexeme; public class IKTokenizer extends Tokenizer {     //IK分詞器實現    PRivate IKSegmenter _IKImplement;          //詞元文本屬性    private final CharTermAttribute termAtt;    //詞元位移屬性    private final OffsetAttribute offsetAtt;    //詞元分類屬性(該屬性分類參考org.wltea.analyzer.core.Lexeme中的分類常量)    private final TypeAttribute typeAtt;    //記錄最后一個詞元的結束位置    private int endPosition;                /**    public IKTokenizer(Reader in , boolean useSmart){        super(in);        offsetAtt = addAttribute(OffsetAttribute.class);        termAtt = addAttribute(CharTermAttribute.class);        typeAtt = addAttribute(TypeAttribute.class);        _IKImplement = new IKSegmenter(input , useSmart);    }**/          /**     * Lucene 5.x Tokenizer適配器類構造函數     * 實現最新的Tokenizer接口     * @param useSmart     */    public IKTokenizer(boolean useSmart){        super();        offsetAtt = addAttribute(OffsetAttribute.class);        termAtt = addAttribute(CharTermAttribute.class);        typeAtt = addAttribute(TypeAttribute.class);        _IKImplement = new IKSegmenter(input , useSmart);    }      /* (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;    }          @Override    public void reset() throws IOException {        super.reset();        _IKImplement.reset(input);    }             @Override    public final void end() {        // set final offset        int finalOffset = correctOffset(this.endPosition);        offsetAtt.setOffset(finalOffset, finalOffset);    } }

package org.wltea.analyzer.lucene; import java.io.IOException; import org.apache.lucene.analysis.Tokenizer;import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;import org.apache.lucene.analysis.tokenattributes.TypeAttribute;import org.wltea.analyzer.core.IKSegmenter;import org.wltea.analyzer.core.Lexeme; public class IKTokenizer extends Tokenizer {     //IK分詞器實現    private IKSegmenter _IKImplement;          //詞元文本屬性    private final CharTermAttribute termAtt;    //詞元位移屬性    private final OffsetAttribute offsetAtt;    //詞元分類屬性(該屬性分類參考org.wltea.analyzer.core.Lexeme中的分類常量)    private final TypeAttribute typeAtt;    //記錄最后一個詞元的結束位置    private int endPosition;                /**    public IKTokenizer(Reader in , boolean useSmart){        super(in);        offsetAtt = addAttribute(OffsetAttribute.class);        termAtt = addAttribute(CharTermAttribute.class);        typeAtt = addAttribute(TypeAttribute.class);        _IKImplement = new IKSegmenter(input , useSmart);    }**/          /**     * Lucene 5.x Tokenizer適配器類構造函數     * 實現最新的Tokenizer接口     * @param useSmart     */    public IKTokenizer(boolean useSmart){        super();        offsetAtt = addAttribute(OffsetAttribute.class);        termAtt = addAttribute(CharTermAttribute.class);        typeAtt = addAttribute(TypeAttribute.class);        _IKImplement = new IKSegmenter(input , useSmart);    }      /* (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;    }          @Override    public void reset() throws IOException {        super.reset();        _IKImplement.reset(input);    }             @Override    public final void end() {        // set final offset        int finalOffset = correctOffset(this.endPosition);        offsetAtt.setOffset(finalOffset, finalOffset);    } }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 犍为县| 汽车| 沈丘县| 故城县| 黄龙县| 通江县| 南平市| 昌江| 资溪县| 台前县| 安岳县| 恩平市| 达州市| 北流市| 东明县| 泉州市| 乌兰察布市| 阳江市| 吉林市| 呼图壁县| 芦山县| 漠河县| 乌兰县| 阿勒泰市| 齐河县| 墨脱县| 特克斯县| 都昌县| 巫溪县| 丰原市| 普兰店市| 遂宁市| 夹江县| 汨罗市| 岑巩县| 西充县| 夏津县| 刚察县| 广宁县| 连城县| 甘肃省|