當前位置: 首頁>>代碼示例>>Java>>正文


Java PositionIncrementAttribute.setPositionIncrement方法代碼示例

本文整理匯總了Java中org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute.setPositionIncrement方法的典型用法代碼示例。如果您正苦於以下問題:Java PositionIncrementAttribute.setPositionIncrement方法的具體用法?Java PositionIncrementAttribute.setPositionIncrement怎麽用?Java PositionIncrementAttribute.setPositionIncrement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute的用法示例。


在下文中一共展示了PositionIncrementAttribute.setPositionIncrement方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: emit

import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; //導入方法依賴的package包/類
private void emit( char[] token ) {
System.out.println( "emit: " + new String( token ) );
if (replaceWhitespaceWith != null) {
	token = replaceWhiteSpace( token );
}
CharTermAttribute termAttr = getTermAttribute( );
termAttr.setEmpty( );
termAttr.append( new StringBuilder( ).append( token ) );

OffsetAttribute offAttr = getOffsetAttribute( );
if (offAttr != null && offAttr.endOffset() >= token.length){ 
  int start = offAttr.endOffset() - token.length;
  offAttr.setOffset( start, offAttr.endOffset());
}

PositionIncrementAttribute pia = getPositionIncrementAttribute( );
if (pia != null) {
	pia.setPositionIncrement( ++positionIncr );
}

lastEmitted = token;
 }
 
開發者ID:lucidworks,項目名稱:auto-phrase-tokenfilter,代碼行數:23,代碼來源:AutoPhrasingTokenFilter.java

示例2: emit

import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; //導入方法依賴的package包/類
private void emit(char[] tokenChars) {
    char[] token = tokenChars;
    if (replaceWhitespaceWith != null) {
        token = replaceWhiteSpace(token);
    }
    CharTermAttribute termAttr = getTermAttribute();
    if (termAttr != null) {
        termAttr.setEmpty();
        termAttr.append(new StringBuilder().append(token));
    }
    OffsetAttribute offAttr = getOffsetAttribute();
    if (offAttr != null && offAttr.endOffset() >= token.length) {
        int start = offAttr.endOffset() - token.length;
        offAttr.setOffset(start, offAttr.endOffset());
    }
    PositionIncrementAttribute pia = getPositionIncrementAttribute();
    if (pia != null) {
        pia.setPositionIncrement(++positionIncr);
    }
    lastEmitted = token;
}
 
開發者ID:jprante,項目名稱:elasticsearch-plugin-bundle,代碼行數:22,代碼來源:AutoPhrasingTokenFilter.java

示例3: createState

import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; //導入方法依賴的package包/類
private static AttributeSource.State createState(AttributeSource a, Tok state, int tokenEnd) {
  a.clearAttributes();
  CharTermAttribute termAtt = a.addAttribute(CharTermAttribute.class);
  char[] tokChars = state.token.toString().toCharArray();
  termAtt.copyBuffer(tokChars, 0, tokChars.length);
  int tokenStart = tokenEnd - state.token.length();
  for (Entry<String, String> e : state.attr.entrySet()) {
    String k = e.getKey();
    if (k.equals("i")) {
      // position increment
      int incr = Integer.parseInt(e.getValue());
      PositionIncrementAttribute posIncr = a.addAttribute(PositionIncrementAttribute.class);
      posIncr.setPositionIncrement(incr);
    } else if (k.equals("s")) {
      tokenStart = Integer.parseInt(e.getValue());
    } else if (k.equals("e")) {
      tokenEnd = Integer.parseInt(e.getValue());
    } else if (k.equals("y")) {
      TypeAttribute type = a.addAttribute(TypeAttribute.class);
      type.setType(e.getValue());
    } else if (k.equals("f")) {
      FlagsAttribute flags = a.addAttribute(FlagsAttribute.class);
      int f = Integer.parseInt(e.getValue(), 16);
      flags.setFlags(f);
    } else if (k.equals("p")) {
      PayloadAttribute p = a.addAttribute(PayloadAttribute.class);
      byte[] data = hexToBytes(e.getValue());
      if (data != null && data.length > 0) {
        p.setPayload(new BytesRef(data));
      }
    } else {
      // unknown attribute
    }
  }
  // handle offset attr
  OffsetAttribute offset = a.addAttribute(OffsetAttribute.class);
  offset.setOffset(tokenStart, tokenEnd);
  State resState = a.captureState();
  a.clearAttributes();
  return resState;
}
 
開發者ID:europeana,項目名稱:search,代碼行數:42,代碼來源:SimplePreAnalyzedParser.java

示例4: end

import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; //導入方法依賴的package包/類
/**
 * This method is called by the consumer after the last token has been
 * consumed, after {@link #incrementToken()} returned <code>false</code>
 * (using the new <code>TokenStream</code> API). Streams implementing the old API
 * should upgrade to use this feature.
 * <p/>
 * This method can be used to perform any end-of-stream operations, such as
 * setting the final offset of a stream. The final offset of a stream might
 * differ from the offset of the last token eg in case one or more whitespaces
 * followed after the last token, but a WhitespaceTokenizer was used.
 * <p>
 * Additionally any skipped positions (such as those removed by a stopfilter)
 * can be applied to the position increment, or any adjustment of other
 * attributes where the end-of-stream value may be important.
 * <p>
 * If you override this method, always call {@code super.end()}.
 * 
 * @throws IOException If an I/O error occurs
 */
public void end() throws IOException {
  clearAttributes(); // LUCENE-3849: don't consume dirty atts
  PositionIncrementAttribute posIncAtt = getAttribute(PositionIncrementAttribute.class);
  if (posIncAtt != null) {
    posIncAtt.setPositionIncrement(0);
  }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:TokenStream.java


注:本文中的org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute.setPositionIncrement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。