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


Java FSIterator.moveToLast方法代码示例

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


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

示例1: getPrevious

import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
 * Return previous element if exists.
 *
 * @param iter   iterator
 * @param anchor an anchor
 * @return previous element if exists or null otherwise
 */
private static Token getPrevious(FSIterator<Token> iter, TokenBase anchor) {
    iter.moveTo(anchor);
    // now the current fs either greater (for tokens seq it means 'after') or equal to the anchor
    if (iter.isValid()) {
        // in any case we should move backward (true for disjoint token segmentation)
        iter.moveToPrevious();
        if (iter.isValid()) {
            return iter.get();
        } else {
            return null;
        }
    } else {
        // check for a case when anchor is after the last visible token
        iter.moveToLast();
        if (iter.isValid()) {
            return iter.get();
        } else {
            return null;
        }
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:29,代码来源:SentenceSplitter.java

示例2: process

import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
    Sentence sent = AnnotationFactory.createAnnotation(jCas, 0, jCas.getDocumentText().length(), Sentence.class);
    FSIterator<Token> tokenIter = jCas.getAnnotationIndex(Token.class).iterator();
    Token firstToken = null;
    Token lastToken = null;
    tokenIter.moveToFirst();
    if (tokenIter.isValid()) {
        firstToken = tokenIter.get();
        tokenIter.moveToLast();
        lastToken = tokenIter.get();
    }
    sent.setFirstToken(firstToken);
    sent.setLastToken(lastToken);
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:16,代码来源:SingleSentenceAnnotator.java

示例3: selectMatching

import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
 * REM: modified from CasUtils..
 * 
 * Get a list of annotations of the given annotation type constraint by a
 * start and end. It's good to provide an annotation that is close to the
 * region, to quickly move the iterator
 * 
 * @param cas
 *            a CAS.
 * @param type
 *            a UIMA type.
 * @param annotationCloseToTheRegion
 *            the covering annotation.
 * @return a return value.
 * @see Subiterator
 */
private static List<Annotation> selectMatching(CAS cas, final int begin,
        final int end, AnnotationFS annotationCloseToTheRegion) {

    final List<Annotation> list = new ArrayList<Annotation>();
    final FSIterator<AnnotationFS> it = cas.getAnnotationIndex().iterator();

    // Try to seek the insertion point.
    it.moveTo(annotationCloseToTheRegion);

    // If the insertion point is beyond the index, move back to the last.
    if (!it.isValid()) {
        it.moveToLast();
        if (!it.isValid()) {
            return list;
        }
    }

    // Ignore type priorities by seeking to the first that has the same
    // begin
    boolean moved = false;
    while (it.isValid() && (it.get()).getBegin() >= begin) {
        it.moveToPrevious();
        moved = true;
    }

    // If we moved, then we are now on one starting before the requested
    // begin, so we have to
    // move one ahead.
    if (moved) {
        it.moveToNext();
    }

    // If we managed to move outside the index, start at first.
    if (!it.isValid()) {
        it.moveToFirst();
    }

    // Skip annotations whose start is before the start parameter.
    while (it.isValid() && (it.get()).getBegin() < begin) {
        it.moveToNext();
    }

    while (it.isValid()) {
        AnnotationFS a = it.get();
        if (!(a instanceof Annotation))
            continue;

        // If the start of the current annotation is past the end parameter,
        // we're done.
        if (a.getBegin() > end) {
            break;
        }
        it.moveToNext();

        if (a.getBegin() == begin && a.getEnd() == end) {
            list.add((Annotation) a);
        }
    }
    return unmodifiableList(list);
}
 
开发者ID:BlueBrain,项目名称:bluima,代码行数:77,代码来源:AbbreviationsExpanderAnnotator.java

示例4: findCoverFS

import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
 * Finds the covering annotation of the specified coverFSType for the given annotation.
 * 
 * @param aCAS
 *          a CAS to search in
 * @param annot
 *          current annotation
 * @param coverFsType
 *          covering annotation type to search for
 * 
 * @return returns the covering annotation FS or null if the covering annotation was not found.
 * 
 */
private AnnotationFS findCoverFS(CAS aCAS, AnnotationFS annot, Type coverFsType) {

  // covering annotation
  AnnotationFS coverFs = null;

  // create a searchFS of the coverFsType with the annot boundaries to
  // search for it.
  FeatureStructure searchFs = aCAS.createAnnotation(coverFsType, annot.getBegin(), aCAS
      .getDocumentText().length());

  // get the coverFSType iterator from the CAS and move it "near" to the
  // position of the created searchFS.
  FSIterator<?> iterator = aCAS.getAnnotationIndex(coverFsType).iterator();
  iterator.moveTo(searchFs);

  // now the iterator can either point directly to the FS we are searching
  // or it points to the next higher FS in the list. So we either have
  // already found the correct one, of we maybe have to move the iterator to
  // the previous position.

  // check if the iterator at the current position is valid
  if (iterator.isValid()) {
    // iterator is valid, so we either have the correct annotation of we
    // have to move to the
    // previous one, lets check the current FS from the iterator
    // get current FS
    coverFs = (AnnotationFS) iterator.get();
    // check if the coverFS covers the current match type annotation
    if ((coverFs.getBegin() <= annot.getBegin()) && (coverFs.getEnd() >= annot.getEnd())) {
      // we found the covering annotation
      return coverFs;
    }
    // current coverFs does not cover the current match type annotation
    // lets try to move iterator to the previous annotation and check
    // again
    iterator.moveToPrevious();
    // check if the iterator is still valid after me move it to the
    // previous FS
    if (iterator.isValid()) {
      // get FS
      coverFs = (AnnotationFS) iterator.get();
      // check the found coverFS covers the current match type
      // annotation
      if ((coverFs.getBegin() <= annot.getBegin()) && (coverFs.getEnd() >= annot.getEnd())) {
        // we found the covering annotation
        return coverFs;
      }
    }
  }
  // iterator is invalid lets try to move the iterator to the last FS and
  // check the FS
  iterator.moveToLast();
  // check if the iterator is valid after we move it
  if (iterator.isValid()) {
    // get FS
    coverFs = (AnnotationFS) iterator.get();
    // check the found coverFS covers the current match type annotation
    if ((coverFs.getBegin() <= annot.getBegin()) && (coverFs.getEnd() >= annot.getEnd())) {
      // we found the covering annotation
      return coverFs;
    }
  }
  // no covering annotation found
  return null;
}
 
开发者ID:BlueBrain,项目名称:bluima,代码行数:79,代码来源:RegExAnnotator.java


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