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


Java WeightedPhraseInfo.getStartOffset方法代码示例

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


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

示例1: createFieldFragList

import org.apache.lucene.search.vectorhighlight.FieldPhraseList.WeightedPhraseInfo; //导入方法依赖的package包/类
protected FieldFragList createFieldFragList( FieldPhraseList fieldPhraseList, FieldFragList fieldFragList, int fragCharSize ){
  if( fragCharSize < minFragCharSize )
    throw new IllegalArgumentException( "fragCharSize(" + fragCharSize + ") is too small. It must be " + minFragCharSize + " or higher." );
  
  List<WeightedPhraseInfo> wpil = new ArrayList<>();
  IteratorQueue<WeightedPhraseInfo> queue = new IteratorQueue<>(fieldPhraseList.getPhraseList().iterator());
  WeightedPhraseInfo phraseInfo = null;
  int startOffset = 0;
  while((phraseInfo = queue.top()) != null){
    // if the phrase violates the border of previous fragment, discard it and try next phrase
    if( phraseInfo.getStartOffset() < startOffset )  {
      queue.removeTop();
      continue;
    }
    
    wpil.clear();
    final int currentPhraseStartOffset = phraseInfo.getStartOffset();
    int currentPhraseEndOffset = phraseInfo.getEndOffset();
    int spanStart = Math.max(currentPhraseStartOffset - margin, startOffset);
    int spanEnd = Math.max(currentPhraseEndOffset, spanStart + fragCharSize);
    if (acceptPhrase(queue.removeTop(),  currentPhraseEndOffset - currentPhraseStartOffset, fragCharSize)) {
      wpil.add(phraseInfo);
    }
    while((phraseInfo = queue.top()) != null) { // pull until we crossed the current spanEnd
      if (phraseInfo.getEndOffset() <= spanEnd) {
        currentPhraseEndOffset = phraseInfo.getEndOffset();
        if (acceptPhrase(queue.removeTop(),  currentPhraseEndOffset - currentPhraseStartOffset, fragCharSize)) {
          wpil.add(phraseInfo);
        }
      } else {
        break;
      }
    }
    if (wpil.isEmpty()) {
      continue;
    }
    
    final int matchLen = currentPhraseEndOffset - currentPhraseStartOffset;
    // now recalculate the start and end position to "center" the result
    final int newMargin = Math.max(0, (fragCharSize-matchLen)/2); // matchLen can be > fragCharSize prevent IAOOB here
    spanStart = currentPhraseStartOffset - newMargin;
    if (spanStart < startOffset) {
      spanStart = startOffset;
    }
    // whatever is bigger here we grow this out
    spanEnd = spanStart + Math.max(matchLen, fragCharSize);  
    startOffset = spanEnd;
    fieldFragList.add(spanStart, spanEnd, wpil);
  }
  return fieldFragList;
}
 
开发者ID:europeana,项目名称:search,代码行数:52,代码来源:BaseFragListBuilder.java

示例2: createFieldFragList

import org.apache.lucene.search.vectorhighlight.FieldPhraseList.WeightedPhraseInfo; //导入方法依赖的package包/类
protected FieldFragList createFieldFragList( FieldPhraseList fieldPhraseList, FieldFragList fieldFragList, int fragCharSize ){
  
  if( fragCharSize < minFragCharSize )
    throw new IllegalArgumentException( "fragCharSize(" + fragCharSize + ") is too small. It must be " + minFragCharSize + " or higher." );
  
  List<WeightedPhraseInfo> wpil = new ArrayList<WeightedPhraseInfo>();
  Iterator<WeightedPhraseInfo> ite = fieldPhraseList.getPhraseList().iterator();
  WeightedPhraseInfo phraseInfo = null;
  int startOffset = 0;
  boolean taken = false;
  while( true ){
    if( !taken ){
      if( !ite.hasNext() ) break;
      phraseInfo = ite.next();
    }
    taken = false;
    if( phraseInfo == null ) break;

    // if the phrase violates the border of previous fragment, discard it and try next phrase
    if( phraseInfo.getStartOffset() < startOffset ) continue;

    wpil.clear();
    wpil.add( phraseInfo );
    int firstOffset = phraseInfo.getStartOffset();
    int st = phraseInfo.getStartOffset() - margin < startOffset ?
        startOffset : phraseInfo.getStartOffset() - margin;
    int en = st + fragCharSize;
    if( phraseInfo.getEndOffset() > en )
      en = phraseInfo.getEndOffset();

    int lastEndOffset = phraseInfo.getEndOffset();
    while( true ){
      if( ite.hasNext() ){
        phraseInfo = ite.next();
        taken = true;
        if( phraseInfo == null ) break;
      }
      else
        break;
      if( phraseInfo.getEndOffset() <= en ){
        wpil.add( phraseInfo );
        lastEndOffset = phraseInfo.getEndOffset();
      }
      else
        break;
    }
    int matchLen = lastEndOffset - firstOffset;
    //now recalculate the start and end position to "center" the result
    int newMargin = (fragCharSize-matchLen)/2;
    st = firstOffset - newMargin;
    if(st<startOffset){
      st = startOffset;
    }
    en = st+fragCharSize;
    startOffset = en;
    fieldFragList.add( st, en, wpil );
  }
  return fieldFragList;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:60,代码来源:BaseFragListBuilder.java

示例3: createFieldFragList

import org.apache.lucene.search.vectorhighlight.FieldPhraseList.WeightedPhraseInfo; //导入方法依赖的package包/类
protected FieldFragList createFieldFragList( FieldPhraseList fieldPhraseList, FieldFragList fieldFragList, int fragCharSize ){
  if( fragCharSize < minFragCharSize )
    throw new IllegalArgumentException( "fragCharSize(" + fragCharSize + ") is too small. It must be " + minFragCharSize + " or higher." );
  
  List<WeightedPhraseInfo> wpil = new ArrayList<WeightedPhraseInfo>();
  IteratorQueue<WeightedPhraseInfo> queue = new IteratorQueue<WeightedPhraseInfo>(fieldPhraseList.getPhraseList().iterator());
  WeightedPhraseInfo phraseInfo = null;
  int startOffset = 0;
  while((phraseInfo = queue.top()) != null){
    // if the phrase violates the border of previous fragment, discard it and try next phrase
    if( phraseInfo.getStartOffset() < startOffset )  {
      queue.removeTop();
      continue;
    }
    
    wpil.clear();
    final int currentPhraseStartOffset = phraseInfo.getStartOffset();
    int currentPhraseEndOffset = phraseInfo.getEndOffset();
    int spanStart = Math.max(currentPhraseStartOffset - margin, startOffset);
    int spanEnd = Math.max(currentPhraseEndOffset, spanStart + fragCharSize);
    if (acceptPhrase(queue.removeTop(),  currentPhraseEndOffset - currentPhraseStartOffset, fragCharSize)) {
      wpil.add(phraseInfo);
    }
    while((phraseInfo = queue.top()) != null) { // pull until we crossed the current spanEnd
      if (phraseInfo.getEndOffset() <= spanEnd) {
        currentPhraseEndOffset = phraseInfo.getEndOffset();
        if (acceptPhrase(queue.removeTop(),  currentPhraseEndOffset - currentPhraseStartOffset, fragCharSize)) {
          wpil.add(phraseInfo);
        }
      } else {
        break;
      }
    }
    if (wpil.isEmpty()) {
      continue;
    }
    
    final int matchLen = currentPhraseEndOffset - currentPhraseStartOffset;
    // now recalculate the start and end position to "center" the result
    final int newMargin = Math.max(0, (fragCharSize-matchLen)/2); // matchLen can be > fragCharSize prevent IAOOB here
    spanStart = currentPhraseStartOffset - newMargin;
    if (spanStart < startOffset) {
      spanStart = startOffset;
    }
    // whatever is bigger here we grow this out
    spanEnd = spanStart + Math.max(matchLen, fragCharSize);  
    startOffset = spanEnd;
    fieldFragList.add(spanStart, spanEnd, wpil);
  }
  return fieldFragList;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:52,代码来源:BaseFragListBuilder.java


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