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

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

ik-analysis for lucene 5.x

2019-11-10 18:32:18
字體:
來源:轉載
供稿:網友

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);    } }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 马山县| 顺平县| 专栏| 博乐市| 奇台县| 都安| 普兰店市| 镇康县| 固原市| 通渭县| 平远县| 西青区| 新邵县| 镇平县| 犍为县| 宁南县| 民县| 项城市| 洞口县| 西华县| 抚松县| 大埔区| 漳平市| 中江县| 金堂县| 和龙市| 泰来县| 罗山县| 榆社县| 伊宁市| 饶阳县| 富锦市| 宿迁市| 胶州市| 舞阳县| 唐河县| 阿城市| 丽水市| 桓台县| 长葛市| 嘉祥县|