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


Java FSIterator.moveToPrevious方法代码示例

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


在下文中一共展示了FSIterator.moveToPrevious方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: findWindowStartCenteringOnSelection

import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
 * Gets the address of the first sentence visible on screen in such a way that the specified
 * focus offset is centered on screen.
 *
 * @param aJcas
 *            the CAS object
 * @param aSentence
 *            the old sentence
 * @param aFocusOffset
 *            the actual offset of the sentence.
 * @param aProject
 *            the project.
 * @param aDocument
 *            the document.
 * @param aWindowSize
 *            the window size.
 * @return the ID of the first sentence.
 */
public static Sentence findWindowStartCenteringOnSelection(JCas aJcas, Sentence aSentence,
        int aFocusOffset, Project aProject, SourceDocument aDocument, int aWindowSize)
{
    if (aWindowSize == 1) {
        return aSentence;
    }

    // Seek the sentence that contains the current focus
    Sentence s = getSentence(aJcas, aFocusOffset);
    
    // If the focus is outside any sentence, then we just return the reference sentence.
    // This should actually never happen, but in case it does, we log a warning and try to
    // behave.
    if (s == null) {
        LOG.warn("Focus [{}] is outside any unit, using first unit.", aFocusOffset);
        return aSentence;
    }

    // Center sentence
    FSIterator<Sentence> si = seekByFs(aJcas, Sentence.class, s);
    if (aWindowSize == 2 && s.getBegin() > aSentence.getBegin()) {
        return s;
    }
    int count = 0;
    while (si.isValid() && count < (aWindowSize / 2)) {
        si.moveToPrevious();
        if (si.isValid()) {
            s = si.get();
        }

        count++;
    }

    return s;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:54,代码来源:WebAnnoCasUtil.java

示例3: sentenceTokenize

import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
public List<Sentence> sentenceTokenize(JCas jcas) {
		List<Sentence> outList = new LinkedList<Sentence>();
		FSIterator tokIt = jcas.getAnnotationIndex(Token.type).iterator();
		
		Sentence s = new Sentence(jcas);
		Boolean sentenceStarted = false;
		Token tOld = null;
		Token t = null;
		while(tokIt.hasNext()) {
			if (!(t == null)){
				tOld = t;
			}
			t = (Token) tokIt.next();
			
			// set sentence beginning
			if(sentenceStarted == false) {
				sentenceStarted = true;
				
				s.setBegin(t.getBegin());
			}
			
			/* detect sentence ends
			 * second character class taken from: http://en.wikipedia.org/wiki/Quotation_mark#Curved_quotes_and_Unicode
			 */
			if(!tokIt.hasNext() ||
					(t.getCoveredText().matches("[.:!\\?]+") && 
							(!((tOld != null && tOld.getCoveredText().matches("[\\d]+")) ||
							((jcas.getDocumentText().substring(t.getEnd()).length() > 2) && (jcas.getDocumentText().substring(t.getEnd(),t.getEnd()+3)).matches(" [A-Z][.-]")))))){
//							((!(tOld.getCoveredText().matches("[\\d]+")))) && (!((jcas.getDocumentText().substring(t.getEnd())).matches("^[\\s]*"))))) {
//					(t.getCoveredText().matches("[.:!\\?]+") && (!(tOld.getCoveredText().matches("[\\d]+"))))) { // das funktioniert ok
				sentenceStarted = false;
				s.setEnd(t.getEnd());

				// check for whether the punctuation mark is followed by a closing quotation mark
				if(tokIt.hasNext()) {
					Token tNext = (Token) tokIt.next();
					
					if(tNext.getCoveredText().matches("[»’'\"‛”‟›〞』」﹄"'」﹂]+")) {
						s.setEnd(tNext.getEnd());
					} else {
						tokIt.moveToPrevious();
					}
				}
				
				s.addToIndexes();
				
				outList.add(s);
				
				s = new Sentence(jcas);
			}
		}
		
		return outList;
	}
 
开发者ID:HeidelTime,项目名称:heideltime,代码行数:55,代码来源:AllLanguagesTokenizer.java

示例4: 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

示例5: 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.moveToPrevious方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。