本文整理汇总了Java中org.apache.uima.cas.FSIterator.get方法的典型用法代码示例。如果您正苦于以下问题:Java FSIterator.get方法的具体用法?Java FSIterator.get怎么用?Java FSIterator.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.uima.cas.FSIterator
的用法示例。
在下文中一共展示了FSIterator.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例2: 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;
}
}
示例3: 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;
}
}
}
示例4: 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 " ";
}
示例5: getLastSentenceInDisplayWindow
import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
* Get the last sentence CAS address in the current display window
*
* @param aJcas
* the JCas.
* @param aFirstSentenceAddress
* the CAS address of the first sentence in the display window
* @param aWindowSize
* the window size
* @return The address of the last sentence address in the current display window.
*/
public static Sentence getLastSentenceInDisplayWindow(JCas aJcas, int aFirstSentenceAddress,
int aWindowSize)
{
int count = 0;
FSIterator<Sentence> si = seekByAddress(aJcas, Sentence.class, aFirstSentenceAddress);
Sentence s = si.get();
while (count < aWindowSize - 1) {
si.moveToNext();
if (si.isValid()) {
s = si.get();
}
else {
break;
}
count++;
}
return s;
}
示例6: testChunkUnambiguousStrictSubiterator
import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
private void testChunkUnambiguousStrictSubiterator(JCas testJcas,
AnnotationIndex<Annotation> annotationIndex) {
System.out.println("Debug: ---------------------------------------------------------------");
System.out.println("Debug: unambiguous and strict subiterating all the chunk annotations");
AnnotationIndex<Annotation> chunkAnnotationIndex = (AnnotationIndex<Annotation>) testJcas.getAnnotationIndex(Chunk.type);
for (Annotation aChunk : chunkAnnotationIndex) {
FSIterator<Annotation> chunkSubIterator = annotationIndex.subiterator(aChunk,false,true);
System.out.println("annotation to subiterate type>"+aChunk.getClass().getName()+"< coveredText>"+aChunk.getCoveredText()+"<");
while(chunkSubIterator.isValid()) {
Annotation subAnnotation = chunkSubIterator.get();
System.out.println("moveToNext subAnnotation type>"+subAnnotation.getClass().getName()+"< coveredText>"+subAnnotation.getCoveredText()+"<");
chunkSubIterator.moveToNext();
}
}
}
示例7: 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();
}
}
示例8: 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();
}
}
示例9: copyFeatureStructuresOfType
import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
public static void copyFeatureStructuresOfType(String typeName, CAS sourceView,
CAS destinationView) {
FeatureStructureCopyingQueue featureStructureCopyingQueue = new FeatureStructureCopyingQueue(
sourceView,
destinationView);
FSIterator<FeatureStructure> iterator = sourceView.getIndexRepository()
.getAllIndexedFS(sourceView.getTypeSystem().getType(typeName));
while (iterator.hasNext()) {
FeatureStructure featureStructure = iterator.get();
featureStructureCopyingQueue.enqueue(featureStructure);
}
featureStructureCopyingQueue.run();
}
示例10: process
import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
String txt = jCas.getDocumentText();
if (txt == null || txt.isEmpty()) {
return;
}
int txtLength = txt.length();
AnnotationIndex<Annotation> tokenIndex = jCas
.getAnnotationIndex(TokenBase.typeIndexID);
FSIterator<Annotation> tokenIter = tokenIndex.iterator();
if (!tokenIter.isValid()) {
makeNTSpan(jCas, 0, txtLength);
} else {
int lastTokenEnd = 0;
while (tokenIter.isValid()) {
Annotation token = tokenIter.get();
if (token.getBegin() > lastTokenEnd) {
makeNTSpan(jCas, lastTokenEnd, token.getBegin());
}
lastTokenEnd = token.getEnd();
//
tokenIter.moveToNext();
}
// check the span after the last token
if (txtLength > lastTokenEnd) {
makeNTSpan(jCas, lastTokenEnd, txtLength);
}
}
}
示例11: 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);
}
示例12: 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;
}
示例13: printAnnotations
import org.apache.uima.cas.FSIterator; //导入方法依赖的package包/类
/**
* (A code that is borrowed from UIMA-library example)
* Prints all Annotations to a PrintStream.
*
* @param aCAS
* the CAS containing the FeatureStructures to print
* @param aOut
* the PrintStream to which output will be written
*/
public static void printAnnotations(CAS aCAS, PrintStream aOut) {
// get iterator over annotations
FSIterator<AnnotationFS> iter = aCAS.getAnnotationIndex().iterator();
// iterate
while (iter.isValid()) {
FeatureStructure fs = iter.get();
printFS(fs, aCAS, 0, aOut);
iter.moveToNext();
}
}
示例14: 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;
}
示例15: 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);
}