org.apache.uima.cas.text.AnnotationIndex.subiterator()方法的使用及代码示例

x33g5p2x  于11个月前 转载在 其他  
字(13.9k)|赞(0)|评价(0)|浏览(19)

本文整理了Java中org.apache.uima.cas.text.AnnotationIndex.subiterator()方法的一些代码示例,展示了AnnotationIndex.subiterator()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotationIndex.subiterator()方法的具体详情如下:
包路径:org.apache.uima.cas.text.AnnotationIndex
类名称:AnnotationIndex
方法名:subiterator

AnnotationIndex.subiterator介绍

[英]Return a subiterator whose bounds are defined by the input annotation.

The annot is used for 3 purposes:

  • It is used to compute the position in the index where the iteration starts.
  • It is used to compute end point where the iterator stops when moving forward.
  • It is used to specify which annotations will be skipped while iterating.

The starting position is computed by first finding a position whose annotation compares equal with the annot (this might be one of several), and then advancing until reaching a position where the annotation there is not equal to the annot. If no item in the index is equal (meaning it has the same begin, the same end, and is the same type as the annot) then the iterator is positioned to the first annotation which is greater than the annot, or if there are no annotations greater than the annot, the iterator is marked invalid.

The iterator will stop (become invalid) when

  • it runs out of items in the index going forward or backwards, or
  • while moving forward, it reaches a point where the annotation at that position has a start is beyond the annot's end position, or
  • while moving backwards, it reaches a position in front of its original starting position.

While iterating, it operates like a strict iterator; annotations whose end positions are > the end position of annot are skipped.

This is equivalent to returning annotations b such that

  • annot < b, and
  • annot.getEnd() >= b.getBegin(), skipping b's whose end position is > annot.getEnd().

For annotations x, y, x < y here is to be interpreted as "x comes before y in the index", according to the rules defined in the description of AnnotationIndex.

This definition implies that annotations b that have the same span as annot may or may not be returned by the subiterator. This is determined by the type priorities; the subiterator will only return such an annotation b if the type of annot precedes the type of b in the type priorities definition. If you have not specified the priority, or if annot and b are of the same type, then the behavior is undefined.

For example, if you have an annotation S of type Sentence and an annotation P of type Paragraph that have the same span, and you have defined Paragraph before Sentence in your type priorities, then subiterator(P) will give you an iterator that will return S, but subiterator(S) will give you an iterator that will NOT return P. The intuition is that a Paragraph is conceptually larger than a Sentence, as defined by the type priorities.

Calling subiterator(a) is equivalent to calling subiterator(a, true, true).. See #subiterator(AnnotationFS,boolean,boolean).
[中]返回一个子迭代器,其边界由输入注释定义。
annot有三个用途:
*它用于计算迭代开始时索引中的位置。
*它用于计算迭代器前进时停止的终点。
*它用于指定迭代时将跳过哪些注释。
计算起始位置的方法是:首先查找注释与annot比较相等的位置(这可能是几个位置之一),然后前进,直到到达注释不等于annot的位置。如果索引中没有相等的项(意味着它与annot具有相同的开始、结束和相同的类型),则迭代器定位到大于annot的第一个注释,或者如果没有大于annot的注释,则迭代器被标记为无效。
迭代器将在以下情况下停止(变得无效)
*向前或向后运行时,索引中的项目已用完,或
*向前移动时,它到达一个点,该位置的注释的起点超出annot's结束位置,或
*当向后移动时,它到达其原始起始位置之前的位置。
迭代时,它的运行方式类似于strict迭代器;跳过结束位置大于annot结束位置的批注。
这相当于返回注释b,以便
*annot < b,以及
*annot.getEnd() >= b.getBegin(),跳过结束位置为>annot的b's。getEnd()。
根据AnnotationIndex描述中定义的规则,对于注释x,y,x < y这里被解释为“索引中x在y之前”。
此定义意味着子迭代器可能返回或不返回与annot具有相同跨度的注释b。这取决于类型优先级;如果类型优先级定义中annot的类型先于b的类型,子迭代器将仅返回此类注释b。如果未指定优先级,或者annotb属于同一类型,则该行为未定义。
例如,如果您有类型为Sentence的注释S和类型为Paragraph的注释P具有相同的跨度,并且您在类型优先级中的Sentence之前定义了Paragraph,那么subiterator(P)将为您提供一个返回S的迭代器,但subiterator(S)将为您提供一个不会返回[$30$]的迭代器。直觉是段落在概念上比句子大,这是由类型优先级定义的。
调用subiterator(a)等同于调用subiterator(a, true, true).。请参见#子迭代器(注释、布尔、布尔)。

代码示例

代码示例来源:origin: org.apache.ctakes/ctakes-assertion

protected void buildSentenceToTokenNumberMap() {
 sentenceToTokenNumberMap = new HashMap<Sentence, List<BaseToken>>();
 for (Sentence s : beginTreeMap.values()) {
  FSIterator<Annotation> tokensInSentenceIterator = jcas
    .getAnnotationIndex(BaseToken.type).subiterator(s);
  List<BaseToken> btList = new ArrayList<BaseToken>();
  BaseToken bt = null;
  while ((bt = this.getNextNonEOLToken(tokensInSentenceIterator)) != null) {
   btList.add(bt);
  }
  sentenceToTokenNumberMap.put(s, btList);
 }
}

代码示例来源:origin: apache/ctakes

protected void buildSentenceToTokenNumberMap() {
 sentenceToTokenNumberMap = new HashMap<Sentence, List<BaseToken>>();
 for (Sentence s : beginTreeMap.values()) {
  FSIterator<Annotation> tokensInSentenceIterator = jcas
    .getAnnotationIndex(BaseToken.type).subiterator(s);
  List<BaseToken> btList = new ArrayList<BaseToken>();
  BaseToken bt = null;
  while ((bt = this.getNextNonEOLToken(tokensInSentenceIterator)) != null) {
   btList.add(bt);
  }
  sentenceToTokenNumberMap.put(s, btList);
 }
}

代码示例来源:origin: apache/ctakes

/**
   * Gets a list of annotations within the specified window annotation.
   * 
//     * @param annotItr
   * @param jCas
   * @param window
   * @return
   * @throws Exception
   */
  private List<Annotation> constrainToWindow(JCas jCas, int type, Annotation window) {

    List<Annotation> list = new ArrayList<Annotation>();

    FSIterator subiterator = jCas.getAnnotationIndex(type).subiterator(window);

    while (subiterator.hasNext()) {
      Annotation annot = (Annotation) subiterator.next();
      list.add(annot);
    }
    return list;
  }

代码示例来源:origin: org.apache.ctakes/ctakes-ne-contexts

/**
   * Gets a list of annotations within the specified window annotation.
   * 
//     * @param annotItr
   * @param jCas
   * @param window
   * @return
   * @throws Exception
   */
  private List<Annotation> constrainToWindow(JCas jCas, int type, Annotation window) {

    List<Annotation> list = new ArrayList<Annotation>();

    FSIterator subiterator = jCas.getAnnotationIndex(type).subiterator(window);

    while (subiterator.hasNext()) {
      Annotation annot = (Annotation) subiterator.next();
      list.add(annot);
    }
    return list;
  }

代码示例来源:origin: apache/uima-uimaj

public static FeatureStructure[] getDebugLogicalStructure_SubAnnotations(AnnotationFS fs) {
 // uses sub iterators - may cause apparant skipping of initial annotations due to type
 // priorities.
 return getIndexContents(fs.getCAS().getAnnotationIndex().subiterator(fs)); // built-in
 // annotation
 // index
}

代码示例来源:origin: apache/ctakes

protected List<Annotation> getMiddleScopeContextAnnotations(JCas jCas, Annotation focus)
    throws AnalysisEngineProcessException {
  List<Annotation> scopeContextAnnotations = new ArrayList<Annotation>();
  FSIterator subiterator = jCas.getAnnotationIndex(contextType).subiterator(focus);
  while (subiterator.hasNext()) {
    scopeContextAnnotations.add((Annotation) subiterator.next());
  }
  if (scopeContextAnnotations.size() == 0 && JCasUtil.getType(focus.getClass()) == contextType)
    scopeContextAnnotations.add(focus);
  else if (scopeContextAnnotations.size() == 0) {
    TypeSystem typeSystem = jCas.getTypeSystem();
    Type superType = jCas.getType(focusType).casType;
    Type subType = focus.getType();
    if (typeSystem.subsumes(superType, subType))
      scopeContextAnnotations.add(focus);
  }
  return scopeContextAnnotations;
}

代码示例来源:origin: org.apache.ctakes/ctakes-ne-contexts

protected List<Annotation> getMiddleScopeContextAnnotations(JCas jCas, Annotation focus)
    throws AnalysisEngineProcessException {
  List<Annotation> scopeContextAnnotations = new ArrayList<Annotation>();
  FSIterator subiterator = jCas.getAnnotationIndex(contextType).subiterator(focus);
  while (subiterator.hasNext()) {
    scopeContextAnnotations.add((Annotation) subiterator.next());
  }
  if (scopeContextAnnotations.size() == 0 && JCasUtil.getType(focus.getClass()) == contextType)
    scopeContextAnnotations.add(focus);
  else if (scopeContextAnnotations.size() == 0) {
    TypeSystem typeSystem = jCas.getTypeSystem();
    Type superType = jCas.getType(focusType).casType;
    Type subType = focus.getType();
    if (typeSystem.subsumes(superType, subType))
      scopeContextAnnotations.add(focus);
  }
  return scopeContextAnnotations;
}

代码示例来源:origin: org.apache.uima/ruta-core

public List<RutaBasic> getBasicsInWindow(AnnotationFS windowAnnotation) {
 List<RutaBasic> result = new ArrayList<RutaBasic>();
 if (windowAnnotation instanceof RutaBasic) {
  result.add((RutaBasic) windowAnnotation);
  return result;
 }
 FSMatchConstraint defaultConstraint = filter.getDefaultConstraint();
 FSIterator<AnnotationFS> iterator = cas.createFilteredIterator(
     cas.getAnnotationIndex(basicType).subiterator(windowAnnotation), defaultConstraint);
 while (iterator.isValid()) {
  result.add((RutaBasic) iterator.get());
  iterator.moveToNext();
 }
 return result;
}

代码示例来源:origin: org.apache.uima/textmarker-core

public List<TextMarkerBasic> getBasicsInWindow(AnnotationFS windowAnnotation) {
 List<TextMarkerBasic> result = new ArrayList<TextMarkerBasic>();
 if (windowAnnotation instanceof TextMarkerBasic) {
  result.add((TextMarkerBasic) windowAnnotation);
  return result;
 }
 FSMatchConstraint defaultConstraint = filter.getDefaultConstraint();
 FSIterator<AnnotationFS> iterator = cas.createFilteredIterator(cas
     .getAnnotationIndex(basicType).subiterator(windowAnnotation), defaultConstraint);
 while (iterator.isValid()) {
  result.add((TextMarkerBasic) iterator.get());
  iterator.moveToNext();
 }
 return result;
}

代码示例来源:origin: nlpie/biomedicus

private void divideAnnotation(AnnotationFS annotation) {
 Objects.requireNonNull(typeToCreate);
 Objects.requireNonNull(dividers);
 FSIterator<AnnotationFS> subiterator = dividers.subiterator(annotation);
 int begin = annotation.getBegin();
 while (subiterator.hasNext()) {
  int end = subiterator.next().getBegin();
  cas.addFsToIndexes(cas.createAnnotation(typeToCreate, begin, end));
  begin = end;
 }
}

代码示例来源:origin: org.apache.uima/ruta-core

private void updateIterators(CAS cas, Type basicType, FilterManager filter,
    AnnotationFS additionalWindow) {
 if (additionalWindow != null) {
  this.basicIt = cas.getAnnotationIndex(basicType).subiterator(additionalWindow);
 } else {
  this.basicIt = cas.getAnnotationIndex(basicType).iterator();
 }
 currentIt = filter.createFilteredIterator(cas, basicType);
}

代码示例来源:origin: apache/ctakes

/**
 * For correct behavior, requires types to be listed in TypePriorities so that the subiterator works as expected
 */
public static FSIterator getAnnotationsIteratorInSpan(JCas jcas, int type, int beginSpan, int endSpan)
{
  Annotation ann = new Annotation(jcas, beginSpan, endSpan);
  ann.addToIndexes();
  AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type);
  FSIterator<?> itr = annIdx.subiterator(ann);
  ann.removeFromIndexes();
  return itr;
}

代码示例来源:origin: org.apache.uima/textmarker-core

private void updateIterators(CAS cas, Type basicType, FilterManager filter,
    AnnotationFS additionalWindow) {
 if (additionalWindow != null) {
  this.basicIt = cas.getAnnotationIndex(basicType).subiterator(additionalWindow);
 } else {
  this.basicIt = cas.getAnnotationIndex(basicType).iterator();
 }
 currentIt = filter.createFilteredIterator(cas, basicType);
}

代码示例来源:origin: org.apache.ctakes/ctakes-core

/**
 * For correct behavior, requires types to be listed in TypePriorities so that the subiterator works as expected
 */
public static FSIterator getAnnotationsIteratorInSpan(JCas jcas, int type, int beginSpan, int endSpan)
{
  Annotation ann = new Annotation(jcas, beginSpan, endSpan);
  ann.addToIndexes();
  AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type);
  FSIterator<?> itr = annIdx.subiterator(ann);
  ann.removeFromIndexes();
  return itr;
}

代码示例来源:origin: org.apache.uima/uimafit-core

/**
 * Convenience method to get a sub-iterator for the specified type.
 * 
 * @param <T>
 *          the iteration type.
 * @param container
 *          the containing annotation.
 * @param type
 *          the type.
 * @param ambiguous
 *          If set to <code>false</code>, resulting iterator will be unambiguous.
 * @param strict
 *          Controls if annotations that overlap to the right are considered in or out.
 * @return A sub-iterator.
 * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
 */
@SuppressWarnings("unchecked")
public static <T extends AnnotationFS> Iterator<T> iterator(AnnotationFS container,
    Class<T> type, boolean ambiguous, boolean strict) {
 CAS cas = container.getCAS();
 return ((AnnotationIndex<T>) cas.getAnnotationIndex(CasUtil.getType(cas, type))).subiterator(
     container, ambiguous, strict);
}

代码示例来源:origin: org.apache.uima/ruta-core

public FSIterator<AnnotationFS> createFilteredIterator(CAS cas, Type basicType) {
 if (windowAnnotation != null) {
  FSIterator<AnnotationFS> windowIt = cas.getAnnotationIndex(basicType)
      .subiterator(windowAnnotation);
  FSIterator<AnnotationFS> iterator = cas.createFilteredIterator(windowIt,
      createCurrentConstraint(false));
  return iterator;
 } else {
  FSIterator<AnnotationFS> iterator = cas.createFilteredIterator(
      cas.getAnnotationIndex(basicType).iterator(), createCurrentConstraint(false));
  return iterator;
 }
}

代码示例来源:origin: org.apache.uima/textmarker-core

public FSIterator<AnnotationFS> createFilteredIterator(CAS cas, Type basicType) {
 if (windowAnnotation != null) {
  FSIterator<AnnotationFS> windowIt = cas.getAnnotationIndex(basicType).subiterator(
      windowAnnotation);
  FSIterator<AnnotationFS> iterator = cas.createFilteredIterator(windowIt,
      createCurrentConstraint(false));
  return iterator;
 } else {
  FSIterator<AnnotationFS> iterator = cas.createFilteredIterator(
      cas.getAnnotationIndex(basicType).iterator(), createCurrentConstraint(false));
  return iterator;
 }
}

代码示例来源:origin: org.apache.ctakes/ctakes-ytex-uima

private void negateAnnotations(JCas aJCas, AnnotationIndex sentenceIdx,
    AnnotationIndex targetIdx, TargetAnnoFilter filter) {
  FSIterator sentenceIter = sentenceIdx.iterator();
  while (sentenceIter.hasNext()) {
    Sentence s = (Sentence) sentenceIter.next();
    FSIterator neIter = targetIdx.subiterator(s);
    while (neIter.hasNext()) {
      Annotation ne = (Annotation) neIter.next();
      if (filter == null || filter.filter(ne))
        checkNegation(aJCas, s, ne);
      // checkNegation2(aJCas, s, ne);
    }
  }
}

代码示例来源:origin: apache/ctakes

private void negateAnnotations(JCas aJCas, AnnotationIndex sentenceIdx,
    AnnotationIndex targetIdx, TargetAnnoFilter filter) {
  FSIterator sentenceIter = sentenceIdx.iterator();
  while (sentenceIter.hasNext()) {
    Sentence s = (Sentence) sentenceIter.next();
    FSIterator neIter = targetIdx.subiterator(s);
    while (neIter.hasNext()) {
      Annotation ne = (Annotation) neIter.next();
      if (filter == null || filter.filter(ne))
        checkNegation(aJCas, s, ne);
      // checkNegation2(aJCas, s, ne);
    }
  }
}

代码示例来源:origin: de.julielab/jcore-opennlp-parser-ae

private void addHeadAnnotation(Constituent cons, Span headSpan) throws CASRuntimeException, CASException {
  FSIterator tokens = cons.getCAS().getJCas().getAnnotationIndex(Token.type).subiterator(cons);
  int headStart = offsetMap.getMapping(headSpan.getStart());
  int headEnd = offsetMap.getMapping(headSpan.getEnd());
  while (tokens.hasNext()) {
    Token token = (Token) tokens.next();
    if (token.getBegin() == headStart && token.getEnd() == headEnd) {
      cons.setHead(token);
      tokens.moveToLast();
      tokens.next();
    }
  }
}

相关文章

最新文章

更多