本文整理汇总了Java中org.apache.uima.cas.FSIterator.moveTo方法的典型用法代码示例。如果您正苦于以下问题:Java FSIterator.moveTo方法的具体用法?Java FSIterator.moveTo怎么用?Java FSIterator.moveTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.uima.cas.FSIterator
的用法示例。
在下文中一共展示了FSIterator.moveTo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNext
import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
* Return next element if exists.
*
* @param iter iterator
* @param anchor an anchor
* @return next element if exists or null otherwise
*/
private static Token getNext(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()) {
Token result = iter.get();
if (result.equals(anchor)) {
iter.moveToNext();
if (iter.isValid()) {
return iter.get();
} else {
return null;
}
} else {
return result;
}
} else {
return null;
}
}
示例2: 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;
}
}
}
示例3: 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 " ";
}
示例4: testNonAmbiguousIteratorOverAnIndexOfAGivenType
import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
* @param inputViewJCas
* @param firstChunk
*/
private void testNonAmbiguousIteratorOverAnIndexOfAGivenType(JCas inputViewJCas,
Annotation firstChunk) {
AnnotationIndex<Annotation> annotationIndex;
FSIterator<Annotation> annotationIndexIterator;
Annotation annotation;
System.out.println("Debug: ---------------------------------------------------------------");
System.out.println("Debug: moveTo+ non-ambiguous iteration over an annotation index (of Chunk.type)");
annotationIndex = (AnnotationIndex<Annotation>) inputViewJCas.getAnnotationIndex(Chunk.type);
annotationIndexIterator = annotationIndex.iterator(false);
annotationIndexIterator.moveTo(firstChunk);
annotation = annotationIndexIterator.get();
System.out.println("moveTo annotation (first chunk firstly met) 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();
}
}
示例5: areAdjoining
import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
public static boolean areAdjoining(Token t1, Token t2) {
JCas jCas = getJCas(t1);
FSIterator<Annotation> tokenIter = jCas.getAnnotationIndex(Token.typeIndexID).iterator();
tokenIter.moveTo(t1);
assert (t1.equals(tokenIter.get()));
tokenIter.moveToNext();
return tokenIter.isValid() && tokenIter.get().equals(t2);
}
示例6: createCCPTextAnnotationNoDups
import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
public static CCPTextAnnotation createCCPTextAnnotationNoDups(String mentionType, int[] span, JCas jcas) {
CCPTextAnnotation ccpTA = new CCPTextAnnotation(jcas);
int startIndex = span[0];
int endIndex = span[1];
ccpTA.setBegin(startIndex);
ccpTA.setEnd(endIndex);
/* create span */
FSArray ccpSpans = new FSArray(jcas, 1);
CCPSpan ccpSpan = new CCPSpan(jcas);
ccpSpan.setSpanStart(startIndex);
ccpSpan.setSpanEnd(endIndex);
ccpSpans.set(0, ccpSpan);
ccpTA.setSpans(ccpSpans);
/* set annotator and annotation set */
CCPAnnotator ccpAnnotator = new CCPAnnotator(jcas);
ccpAnnotator.setAffiliation("N/A");
ccpAnnotator.setFirstName("Default Annotator");
ccpAnnotator.setAnnotatorID(-1);
ccpAnnotator.setLastName("Default Annotator");
CCPAnnotationSet ccpAnnotationSet = new CCPAnnotationSet(jcas);
ccpAnnotationSet.setAnnotationSetID(-1);
ccpAnnotationSet.setAnnotationSetName("Default Set");
ccpAnnotationSet.setAnnotationSetDescription("");
ccpTA.setAnnotator(ccpAnnotator);
FSArray asets = new FSArray(jcas, 1);
asets.set(0, ccpAnnotationSet);
ccpTA.setAnnotationSets(asets);
ccpTA.setDocumentSectionID(-1);
CCPClassMention ccpCM = new CCPClassMention(jcas);
ccpCM.setMentionName(mentionType);
ccpTA.setClassMention(ccpCM);
ccpCM.setCcpTextAnnotation(ccpTA);
boolean deep = true;
boolean anonymize = true;
WrappedCCPTextAnnotation wrappedCcpTa = new WrappedCCPTextAnnotation(ccpTA);
// String ccpTA_string = toString(ccpTA, deep, anonymize);
FSIterator completeIt = jcas.getAnnotationIndex().iterator();
completeIt.moveTo(ccpTA);
if (completeIt.isValid()) {
if (completeIt.get() instanceof CCPTextAnnotation) {
CCPTextAnnotation ccpTA_comp = (CCPTextAnnotation) completeIt.get();
WrappedCCPTextAnnotation wrappedCcpTa_comp = new WrappedCCPTextAnnotation(ccpTA_comp);
// String stringRep = toString(ccpTA_comp, deep, anonymize);
if (wrappedCcpTa.equals(wrappedCcpTa_comp)) {
return null;
} else {
ccpTA.addToIndexes();
return ccpTA;
}
}
} else {
ccpTA.addToIndexes();
return ccpTA;
}
return null;
}
示例7: 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);
}
示例8: 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;
}
示例9: testNonAmbiguousSubiterator
import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
* @param annotationIndex
* @param firstSentence
*/
private void testNonAmbiguousSubiterator(
AnnotationIndex<Annotation> annotationIndex,
Annotation firstSentence) {
FSIterator<Annotation> annotationIndexIterator;
Annotation annotation;
System.out.println("Debug: ---------------------------------------------------------------");
System.out.println("Debug: non-ambiguous subiterator over an annotation index");
/**
* Debug: non-ambiguous subiterator over an annotation index
move to first sentence annotation coveredText>Jean pousse la voiture.< type>common.types.text.Sentence<
moveToNext ambiguous annotationIndexSubiterator coveredText>Jean< type>common.types.text.Chunk<
moveToNext ambiguous annotationIndexSubiterator coveredText>Jean< type>common.types.text.LexicalUnit<
moveToNext ambiguous annotationIndexSubiterator coveredText>< type>org.apache.uima.examples.SourceDocumentInformation<
moveToNext ambiguous annotationIndexSubiterator coveredText>pousse< type>common.types.text.Chunk<
moveToNext ambiguous annotationIndexSubiterator coveredText>pousse< type>common.types.text.LexicalUnit<
moveToNext ambiguous annotationIndexSubiterator coveredText>la voiture< type>common.types.text.Chunk<
moveToNext ambiguous annotationIndexSubiterator coveredText>la< type>common.types.text.LexicalUnit<
moveToNext ambiguous annotationIndexSubiterator coveredText>voiture< type>common.types.text.LexicalUnit<
moveToNext ambiguous annotationIndexSubiterator coveredText>.< type>common.types.text.LexicalUnit<
move to first sentence annotation coveredText>Jean pousse la voiture.< type>common.types.text.Sentence<
moveToNext non ambiguous annotationIndexSubiterator coveredText>Jean< type>common.types.text.Chunk<
moveToNext non ambiguous annotationIndexSubiterator coveredText>pousse< type>common.types.text.Chunk<
moveToNext non ambiguous annotationIndexSubiterator coveredText>la voiture< type>common.types.text.Chunk<
moveToNext non ambiguous annotationIndexSubiterator coveredText>.< type>common.types.text.LexicalUnit<
*/
annotationIndexIterator = annotationIndex.iterator();
annotationIndexIterator.moveTo(firstSentence);
annotation = annotationIndexIterator.get();
System.out.println("move to first sentence annotation coveredText>"+annotation.getCoveredText()+"< type>"+annotation.getClass().getName()+"< ");
FSIterator<Annotation> annotationIndexSubiterator = annotationIndex.subiterator(annotation);
while(annotationIndexSubiterator.isValid()) {
annotation = annotationIndexSubiterator.get();
System.out.println("moveToNext ambiguous annotationIndexSubiterator coveredText>"+annotation.getCoveredText()+"< type>"+annotation.getClass().getName()+"<");
annotationIndexSubiterator.moveToNext();
}
annotationIndexIterator.moveTo(firstSentence);
annotation = annotationIndexIterator.get();
System.out.println("move to first sentence annotation coveredText>"+annotation.getCoveredText()+"< type>"+annotation.getClass().getName()+"< ");
annotationIndexSubiterator = annotationIndex.subiterator(annotation,false,true);
while(annotationIndexSubiterator.isValid()) {
annotation = annotationIndexSubiterator.get();
System.out.println("moveToNext non ambiguous annotationIndexSubiterator coveredText>"+annotation.getCoveredText()+"< type>"+annotation.getClass().getName()+"<");
annotationIndexSubiterator.moveToNext();
}
}