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


Java FSIterator.moveToFirst方法代码示例

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


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

示例1: checkForTheSameBoundaries

import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
public static void checkForTheSameBoundaries(CAS cas, Class<? extends AnnotationFS> typeClass) {
    Type type = CasUtil.getType(cas, typeClass);
    FSIterator<AnnotationFS> iter = cas.getAnnotationIndex(type).iterator();
    iter.moveToFirst();
    if (!iter.isValid()) {
        return;
    }
    AnnotationOffsetComparator<AnnotationFS> cmp =
            AnnotationOffsetComparator.instance(AnnotationFS.class);
    AnnotationFS lastAnno = iter.get();
    iter.moveToNext();
    while (iter.isValid()) {
        AnnotationFS anno = iter.get();
        if (cmp.compare(anno, lastAnno) == 0) {
            throw new IllegalStateException(String.format(
                    "Annotations %s and %s have the same boundaries",
                    lastAnno, anno));
        }
        iter.moveToNext();
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:22,代码来源:AnnotationOffsetComparator.java

示例2: normalizeSpaceBetween

import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
private String normalizeSpaceBetween(FSIterator<TokenBase> tbIter, final Token x, final Token y) {
    // X must be before Y
    Preconditions.checkArgument(x == null || y == null || x.getCAS().getAnnotationIndex().compare(x, y) < 0);
    if (x == null) {
        tbIter.moveToFirst();
    } else {
        tbIter.moveTo(x);
    }
    while (// if Y is null then iterate till the end
            (y == null && tbIter.isValid())
                    // else - iterate till the Y
                    || (y != null && !tbIter.get().equals(y))) {
        if (tbIter.get() instanceof BREAK) {
            return "\n";
        }
        tbIter.moveToNext();
    }
    return " ";
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:20,代码来源:NormalizedTextWriter.java

示例3: testNonAmbiguousIterator

import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
 * @param annotationIndex
 */
private void testNonAmbiguousIterator(
		AnnotationIndex<Annotation> annotationIndex) {
	FSIterator<Annotation> annotationIndexIterator;
	Annotation annotation;
	System.out.println("Debug: ---------------------------------------------------------------");
	System.out.println("Debug: non-ambiguous iteration over an annotation index");
	annotationIndexIterator = annotationIndex.iterator(false);
	annotationIndexIterator.moveToFirst();
	annotation = annotationIndexIterator.get();
	System.out.println("first annotation coveredText>"+annotation.getCoveredText()+"< type>"+annotation.getClass().getName()+"< ");
	annotationIndexIterator.moveToNext();
	while(annotationIndexIterator.isValid()) {
		annotation = annotationIndexIterator.get();
		System.out.println("moveToNext annotation coveredText>"+annotation.getCoveredText()+"< type>"+annotation.getClass().getName()+"<");
		annotationIndexIterator.moveToNext();
	}
}
 
开发者ID:nicolashernandez,项目名称:dev-star,代码行数:21,代码来源:TestLocatedAnnotationAE.java

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

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

示例6: testAnnotationTreeNavigation

import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
	 * @param annotationIndex
	 */
	private void testAnnotationTreeNavigation(
			AnnotationIndex<Annotation> annotationIndex) {
		FSIterator<Annotation> annotationIndexIterator;
		Annotation annotation;
		/*
		 * Debug: 
first annotation type>org.apache.uima.jcas.tcas.DocumentAnnotation< coveredText>Jean pousse la voiture.
<
Parent type>org.apache.uima.jcas.tcas.DocumentAnnotation< coveredText>Jean pousse la voiture.
<
--Child type>common.types.text.Sentence< coveredText>Jean pousse la voiture.<
--Parent type>common.types.text.Sentence< coveredText>Jean pousse la voiture.<
----Child type>common.types.text.Chunk< coveredText>Jean<
----Parent type>common.types.text.Chunk< coveredText>Jean<
------Child type>common.types.text.LexicalUnit< coveredText>Jean<
------Parent type>common.types.text.LexicalUnit< coveredText>Jean<
--------Child type>org.apache.uima.examples.SourceDocumentInformation< coveredText><
--------Parent type>org.apache.uima.examples.SourceDocumentInformation< coveredText><
----Child type>common.types.text.Chunk< coveredText>pousse<
----Parent type>common.types.text.Chunk< coveredText>pousse<
------Child type>common.types.text.LexicalUnit< coveredText>pousse<
------Parent type>common.types.text.LexicalUnit< coveredText>pousse<
----Child type>common.types.text.Chunk< coveredText>la voiture<
----Parent type>common.types.text.Chunk< coveredText>la voiture<
------Child type>common.types.text.LexicalUnit< coveredText>la<
------Parent type>common.types.text.LexicalUnit< coveredText>la<
------Child type>common.types.text.LexicalUnit< coveredText>voiture<
------Parent type>common.types.text.LexicalUnit< coveredText>voiture<
----Child type>common.types.text.LexicalUnit< coveredText>.<
----Parent type>common.types.text.LexicalUnit< coveredText>.<
Debug: ------------------------------------------------------------------
		 */
		System.out.println("Debug: ---------------------------------------------------------------");
		System.out.println("Debug: tree navigation");

		annotationIndexIterator = annotationIndex.iterator();
		annotationIndexIterator.moveToFirst();
		annotation = annotationIndexIterator.get();
		System.out.println("first annotation type>"+annotation.getClass().getName()+"< coveredText>"+annotation.getCoveredText()+"<");

		AnnotationTree<Annotation>	annotationTree = annotationIndex.tree(annotation);
		exploreAnnotationTreeNode(annotationTree.getRoot(),0);
	}
 
开发者ID:nicolashernandez,项目名称:dev-star,代码行数:47,代码来源:TestLocatedAnnotationAE.java

示例7: testTypeSubsumptionConstrainedIterator

import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
 * @param inputViewJCas
 * @param annotationIndexIterator
 */
private void testTypeSubsumptionConstrainedIterator(JCas inputViewJCas,
		FSIterator<Annotation> annotationIndexIterator) {
	Annotation annotation;
	// -- constrained iterator chunk which words occurs at the same offsets 
	System.out.println("Debug: ---------------------------------------------------------------");
	System.out.println("Debug: constrained iterator chunk which words occurs at the same offsets (do not work since none is the surtype of the other) ; works with tcas.annotation");
	// 
	// Start by getting the constraint factory from the CAS.
	ConstraintFactory cf = inputViewJCas.getConstraintFactory();

	// To specify a path to an item to test, you start by
	// creating an empty path.
	//FeaturePath path = cas.createFeaturePath();

	// Add POS feature to path, creating one-element path.
	//path.addFeature(posFeat);

	// You can extend the chain arbitrarily by adding additional
	// features.

	// Create a new type constraint.  

	// Type constraints will check that structures
	// they match against have a type at least as specific
	// as the type specified in the constraint.
	FSTypeConstraint chunkConstraint = cf.createTypeConstraint();

	// Set the type (by default it is TOP).
	// This succeeds if the type being tested by this constraint
	// is nounType or a subtype of nounType.
	chunkConstraint.add(inputViewJCas.getTypeSystem().getType("common.types.text.Chunk"));


	// Embed the noun constraint under the pos path.
	// This means, associate the test with the path, so it tests the
	// proper value.

	// The result is a test which will
	// match a feature structure that has a posFeat defined
	// which has a value which is an instance of a nounType or
	// one of its subtypes.
	//FSMatchConstraint embeddedNoun = cf.embedConstraint(path, chunkConstraint);

	// Create a type constraint for token (or a subtype of it)
	FSTypeConstraint uimaTCasAnnotationConstraint = cf.createTypeConstraint();

	// Set the type.
	uimaTCasAnnotationConstraint.add(inputViewJCas.getTypeSystem().getType("uima.tcas.Annotation"));

	// Create the final constraint by conjoining the two constraints.
	FSMatchConstraint chunkAndLexicalUnitCons = cf.and(chunkConstraint, uimaTCasAnnotationConstraint);

	// Create a filtered iterator from some annotation iterator.
	FSIterator uimaTCasAnnotationUnitIterator = inputViewJCas.createFilteredIterator(annotationIndexIterator, chunkAndLexicalUnitCons);

	uimaTCasAnnotationUnitIterator.moveToFirst();

	annotation = (Annotation) uimaTCasAnnotationUnitIterator.get();
	System.out.println("first chunkAndLexicalUnitIterator annotation type>"+annotation.getClass().getName()+"< coveredText>"+annotation.getCoveredText()+"<");
	uimaTCasAnnotationUnitIterator.moveToNext();

	while(uimaTCasAnnotationUnitIterator.isValid()) {
		annotation =  (Annotation) uimaTCasAnnotationUnitIterator.get();

		System.out.println("moveToNext chunkAndLexicalUnitIterator annotation type>"+annotation.getClass().getName()+"< coveredText>"+annotation.getCoveredText()+"<");
		uimaTCasAnnotationUnitIterator.moveToNext();
	}
}
 
开发者ID:nicolashernandez,项目名称:dev-star,代码行数:73,代码来源:TestLocatedAnnotationAE.java

示例8: testSelectSpecificTypesConstrainedIterator

import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
 * @param inputViewJCas
 * @param annotationIndexIterator
 */
private void testSelectSpecificTypesConstrainedIterator(JCas inputViewJCas,
		FSIterator<Annotation> annotationIndexIterator) {
	Annotation annotation;
	// -- constrained iterator chunk which words occurs at the same offsets 
	System.out.println("Debug: ---------------------------------------------------------------");
	System.out.println("Debug: constrained iterator over two types (noun and verb) without inheritance relations");

	// Start by getting the constraint factory from the CAS.
	ConstraintFactory cf = inputViewJCas.getConstraintFactory();

	// Create a new type constraint.  

	// Type constraints will check that structures
	// they match against have a type at least as specific
	// as the type specified in the constraint.
	FSTypeConstraint nounConstraint = cf.createTypeConstraint();

	// Set the type (by default it is TOP).
	// This succeeds if the type being tested by this constraint
	// is nounType or a subtype of nounType.
	nounConstraint.add(inputViewJCas.getTypeSystem().getType("common.types.text.Noun"));


	FSTypeConstraint verbConstraint = cf.createTypeConstraint();

	// Set the type (by default it is TOP).
	// This succeeds if the type being tested by this constraint
	// is nounType or a subtype of nounType.
	verbConstraint.add(inputViewJCas.getTypeSystem().getType("common.types.text.Verb"));



	// Create the final constraint by conjoining the two constraints.
	FSMatchConstraint nounOrVerbConstraint = cf.or(verbConstraint, nounConstraint);

	// Create a filtered iterator from some annotation iterator.
	FSIterator uimaTCasAnnotationUnitIterator = inputViewJCas.createFilteredIterator(annotationIndexIterator, nounOrVerbConstraint);

	uimaTCasAnnotationUnitIterator.moveToFirst();

	annotation = (Annotation) uimaTCasAnnotationUnitIterator.get();
	System.out.println("first nounOrVerbConstraint annotation type>"+annotation.getClass().getName()+"< coveredText>"+annotation.getCoveredText()+"<");
	uimaTCasAnnotationUnitIterator.moveToNext();

	while(uimaTCasAnnotationUnitIterator.isValid()) {
		annotation =  (Annotation) uimaTCasAnnotationUnitIterator.get();

		System.out.println("moveToNext nounOrVerbConstraint annotation type>"+annotation.getClass().getName()+"< coveredText>"+annotation.getCoveredText()+"<");
		uimaTCasAnnotationUnitIterator.moveToNext();
	}
}
 
开发者ID:nicolashernandez,项目名称:dev-star,代码行数:56,代码来源:TestLocatedAnnotationAE.java


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