当前位置: 首页>>代码示例>>Java>>正文


Java Token.endOffset方法代码示例

本文整理汇总了Java中org.apache.lucene.analysis.Token.endOffset方法的典型用法代码示例。如果您正苦于以下问题:Java Token.endOffset方法的具体用法?Java Token.endOffset怎么用?Java Token.endOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.analysis.Token的用法示例。


在下文中一共展示了Token.endOffset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isOffsetCorrect

import org.apache.lucene.analysis.Token; //导入方法依赖的package包/类
private boolean isOffsetCorrect(String s, Collection<Token> tokens) {
  for (Token token : tokens) {
    int start = token.startOffset();
    int end = token.endOffset();
    if (!s.substring(start, end).equals(token.toString()))  return false;
  }
  return true;
}
 
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:SpellingQueryConverterTest.java

示例2: getCollation

import org.apache.lucene.analysis.Token; //导入方法依赖的package包/类
private String getCollation(String origQuery,
                            List<SpellCheckCorrection> corrections) {
  StringBuilder collation = new StringBuilder(origQuery);
  int offset = 0;
  String corr = "";
  for(int i=0 ; i<corrections.size() ; i++) {
    SpellCheckCorrection correction = corrections.get(i);   
    Token tok = correction.getOriginal();
    // we are replacing the query in order, but injected terms might cause
    // illegal offsets due to previous replacements.
    if (tok.getPositionIncrement() == 0)
      continue;
    corr = correction.getCorrection();
    boolean addParenthesis = false;
    Character requiredOrProhibited = null;
    int indexOfSpace = corr.indexOf(' ');
    StringBuilder corrSb = new StringBuilder(corr);
    int bump = 1;
    
    //If the correction contains whitespace (because it involved breaking a word in 2+ words),
    //then be sure all of the new words have the same optional/required/prohibited status in the query.
    while(indexOfSpace>-1 && indexOfSpace<corr.length()-1) {
      addParenthesis = true;
      char previousChar = tok.startOffset()>0 ? origQuery.charAt(tok.startOffset()-1) : ' ';
      if(previousChar=='-' || previousChar=='+') {
        corrSb.insert(indexOfSpace + bump, previousChar);
        if(requiredOrProhibited==null) {
          requiredOrProhibited = previousChar;
        }
        bump++;
      } else if ((tok.getFlags() & QueryConverter.TERM_IN_BOOLEAN_QUERY_FLAG) == QueryConverter.TERM_IN_BOOLEAN_QUERY_FLAG) {
        corrSb.insert(indexOfSpace + bump, "AND ");
        bump += 4;
      }
      indexOfSpace = correction.getCorrection().indexOf(' ', indexOfSpace + bump);
    }
    
    int oneForReqOrProhib = 0;
    if(addParenthesis) { 
      if(requiredOrProhibited!=null) {
        corrSb.insert(0, requiredOrProhibited);
        oneForReqOrProhib++;
      }
      corrSb.insert(0, '(');
      corrSb.append(')');
    }
    corr = corrSb.toString();  
    int startIndex = tok.startOffset() + offset - oneForReqOrProhib;
    int endIndex = tok.endOffset() + offset;
    collation.replace(startIndex, endIndex, corr);
    offset += corr.length() - oneForReqOrProhib - (tok.endOffset() - tok.startOffset());      
  }
  return collation.toString();
}
 
开发者ID:europeana,项目名称:search,代码行数:55,代码来源:SpellCheckCollator.java

示例3: newToken

import org.apache.lucene.analysis.Token; //导入方法依赖的package包/类
private Token newToken(Token existing, String newText){
    return new Token(newText, existing.startOffset(), existing.endOffset());
}
 
开发者ID:DiceTechJobs,项目名称:SolrPlugins,代码行数:4,代码来源:DiceMultipleCaseSuggester.java


注:本文中的org.apache.lucene.analysis.Token.endOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。