Type relArgsType = newCas2.getTypeSystem().getType(
"org.apache.uima.testTypeSystem.BinaryRelationArgs");
Feature domainFeat = relArgsType.getFeatureByBaseName("domainValue");
Feature rangeFeat = relArgsType.getFeatureByBaseName("rangeValue");
AnnotationFS ownerAnnot = newCas2.createAnnotation(ownerType, 0, 70);
FeatureStructure relArgs = newCas2.createFS(relArgsType);
relArgs.setFeatureValue(domainFeat, person);
relArgs.setFeatureValue(rangeFeat, org);
ownerAnnot.setFeatureValue(argsFeat, relArgs);
ownerAnnot.setStringValue(componentIdFeat, "XCasDeserializerTest");
newCas2.addFsToIndexes(ownerAnnot);
int orgBegin = org.getBegin();
int orgEnd = org.getEnd();
//add Sofas
CAS newView1 = newCas1.createView("newSofa1");
final String sofaText1 = "This is a new Sofa, created in CAS 1.";
newView1.setDocumentText(sofaText1);
final String annotText = "Sofa";
int annotStart1 = sofaText1.indexOf(annotText);
AnnotationFS annot1 = newView1.createAnnotation(orgType, annotStart1, annotStart1 + annotText.length());
newView1.addFsToIndexes(annot1);
CAS newView2 = newCas2.createView("newSofa2");
final String sofaText2 = "This is another new Sofa, created in CAS 2.";
newView2.setDocumentText(sofaText2);
int annotStart2 = sofaText2.indexOf(annotText);
AnnotationFS annot2 = newView2.createAnnotation(orgType, annotStart2, annotStart2 + annotText.length());
newView2.addFsToIndexes(annot2);
// Add an FS with an array of existing annotations in another view
int nToks = 3;
ArrayFS array = newView2.createArrayFS(nToks);
Type thingType = newCas2.getTypeSystem().getType("org.apache.uima.testTypeSystem.Thing");
FSIterator thingIter = newCas2.getAnnotationIndex(thingType).iterator();
for (int i = 0; i < nToks; ++i)
array.set(i, (FeatureStructure)thingIter.next());
Type annotArrayTestType = newView2.getTypeSystem().getType("org.apache.uima.testTypeSystem.AnnotationArrayTest");
Feature annotArrayFeat = annotArrayTestType.getFeatureByBaseName("arrayOfAnnotations");
AnnotationFS fsArrayTestAnno = newView2.createAnnotation(annotArrayTestType, 13, 27);
fsArrayTestAnno.setFeatureValue(annotArrayFeat,array);
newView2.addFsToIndexes(fsArrayTestAnno);
// re-serialize each new CAS back to XMI, keeping consistent ids
String newSerCas1 = serialize(newCas1, deserSharedData1, marker1);
String newSerCas2 = serialize(newCas2, deserSharedData2, marker2);
// merge the two XMI CASes back into the original CAS
// the shared data will be reset and recreated if not using deltaCas
if (useDeltas) {
deserialize(newSerCas1, cas, serSharedData, false, maxOutgoingXmiId);
} else {
deserialize(newSerCas1, cas, serSharedData, false, -1);
}
assertEquals(numAnnotations + 2, cas.getAnnotationIndex().size());
deserialize(newSerCas2, cas, serSharedData, false, maxOutgoingXmiId);
assertEquals(numAnnotations + 5, cas.getAnnotationIndex().size());
assertEquals(docText, cas.getDocumentText());
// Serialize/deserialize again in case merge created duplicate ids
String newSerCasMerged = serialize(cas, serSharedData);
deserialize(newSerCasMerged, cas, serSharedData, false, -1);
//check covered text of annotations
FSIterator iter = cas.getAnnotationIndex().iterator();
while (iter.hasNext()) {
AnnotationFS annot = (AnnotationFS)iter.next();
assertEquals(cas.getDocumentText().substring(
annot.getBegin(), annot.getEnd()), annot.getCoveredText());
}
//check Owner annotation we created to test link across merge boundary
iter = cas.getAnnotationIndex(ownerType).iterator();
while (iter.hasNext()) {
AnnotationFS
annot = (AnnotationFS)iter.next();
String componentId = annot.getStringValue(componentIdFeat);
if ("XCasDeserializerTest".equals(componentId)) {
FeatureStructure targetRelArgs = annot.getFeatureValue(argsFeat);
AnnotationFS targetDomain = (AnnotationFS)targetRelArgs.getFeatureValue(domainFeat);
assertEquals(60, targetDomain.getBegin());
assertEquals(70, targetDomain.getEnd());
AnnotationFS targetRange = (AnnotationFS)targetRelArgs.getFeatureValue(rangeFeat);
assertEquals(orgBegin, targetRange.getBegin());
assertEquals(orgEnd, targetRange.getEnd());
}
}
//check Sofas