String fTok = fst.nextToken();
int frBegin = frText.indexOf(fTok, frEnd);
frEnd = frBegin + fTok.length();
Annotation engAnnot = new Annotation(engJcas, engBegin, engEnd);
engAnnot.addToIndexes();
Annotation frAnnot = new Annotation(frJcas, frBegin, frEnd);
frAnnot.addToIndexes();
CrossAnnotation gerAnnot = new CrossAnnotation(gerJcas);
gerAnnot.setBegin(gerBegin);
gerAnnot.setEnd(gerEnd);
gerAnnot.setOtherAnnotation(engAnnot);
gerAnnot.addToIndexes();
}
// Test that the annotations are in separate index spaces, and that Sofas are indexed
JFSIndexRepository indexes = jcas.getJFSIndexRepository();
// FSIndex sofaIndex = indexes.getIndex(CAS.SOFA_INDEX_NAME);
indexes = engJcas.getJFSIndexRepository();
FSIndex engIndex = indexes.getAnnotationIndex(Annotation.type);
indexes = gerJcas.getJFSIndexRepository();
FSIndex gerIndex = indexes.getAnnotationIndex(Annotation.type);
indexes = frJcas.getJFSIndexRepository();
FSIndex frIndex = indexes.getAnnotationIndex(Annotation.type);
FSIterator sofaIter = jcas.getSofaIterator();
int numSofas = 0;
while (sofaIter.isValid()) {
numSofas++;
sofaIter.moveToNext();
}
// assertTrue(sofaIndex.size() == 3); // 3 sofas
assertTrue(numSofas == 3);
assertTrue(engIndex.size() == 5); // 4 annots plus documentAnnotation
assertTrue(gerIndex.size() == 5); // 4 annots plus documentAnnotation
assertTrue(frIndex.size() == 5); // 4 annots plus documentAnnotation
// Test that the annotations are of the correct types
FSIterator engIt = engIndex.iterator();
FSIterator gerIt = gerIndex.iterator();
FSIterator frIt = frIndex.iterator();
Annotation engAnnot = (Annotation) engIt.get();
Annotation gerAnnot = (Annotation) gerIt.get();
Annotation frAnnot = (Annotation) frIt.get();
assertTrue((CAS.TYPE_NAME_DOCUMENT_ANNOTATION).equals(engAnnot.getType().getName()));
assertTrue((CAS.TYPE_NAME_DOCUMENT_ANNOTATION).equals(gerAnnot.getType().getName()));
assertTrue((CAS.TYPE_NAME_DOCUMENT_ANNOTATION).equals(frAnnot.getType().getName()));
engIt.moveToNext();
gerIt.moveToNext();
frIt.moveToNext();
engAnnot = (Annotation) engIt.get();
CrossAnnotation gerCrossAnnot = (CrossAnnotation) gerIt.get();
frAnnot = (Annotation) frIt.get();
assertTrue((CAS.TYPE_NAME_ANNOTATION).equals(engAnnot.getType().getName()));
assertTrue(("this").equals(engAnnot.getCoveredText()));
assertTrue((CAS.TYPE_NAME_ANNOTATION).equals(frAnnot.getType().getName()));
assertTrue(("cette").equals(frAnnot.getCoveredText()));
assertTrue(("org.apache.uima.cas.test.CrossAnnotation").equals(gerCrossAnnot.getType()
.getName()));
assertTrue(("das").equals(gerCrossAnnot.getCoveredText()));
// Test that the other annotation feature of cross annotations works
Annotation crossAnnot = gerCrossAnnot.getOtherAnnotation();
assertTrue((CAS.TYPE_NAME_ANNOTATION).equals(crossAnnot.getType().getName()));
assertTrue(("this").equals(crossAnnot.getCoveredText()));
// Test that annotations accessed from a reference in the base CAS work correctly
FSArray anArray = new FSArray(jcas, 3);
anArray.set(0, engAnnot);
anArray.set(1, frAnnot);
anArray.set(2, gerCrossAnnot);
Annotation tstAnnot = (Annotation) anArray.get(0);
assertTrue(("this").equals(tstAnnot.getCoveredText()));
tstAnnot = (Annotation) anArray.get(1);
assertTrue(("cette").equals(tstAnnot.getCoveredText()));
tstAnnot = (Annotation) anArray.get(2);
assertTrue(("das").equals(tstAnnot.getCoveredText()));
} catch (Exception e) {
JUnitExtension.handleException(e);
}
}