AnnotationFS anAnnot4 = cas1.createAnnotation(cas1.getAnnotationType(), 15, 30);
cas1.getIndexRepository().addFS(anAnnot4);
FSIndex tIndex = cas1.getAnnotationIndex();
assertTrue(tIndex.size() == 5); //doc annot plus 4 annots
FeatureStructure entityFS = cas1.createFS(entityType);
cas1.getIndexRepository().addFS(entityFS);
StringArrayFS strArrayFS = cas1.createStringArrayFS(5);
strArrayFS.set(0, "class1");
entityFS.setFeatureValue(classesFeat, strArrayFS);
//create listFS and set the link feature
FeatureStructure emptyNode = cas1.createFS(emptyFsListType);
FeatureStructure secondNode = cas1.createFS(nonEmptyFsListType);
secondNode.setFeatureValue(headFeat, anAnnot2);
secondNode.setFeatureValue(tailFeat, emptyNode);
FeatureStructure firstNode = cas1.createFS(nonEmptyFsListType);
firstNode.setFeatureValue(headFeat, anAnnot1);
firstNode.setFeatureValue(tailFeat, secondNode);
entityFS.setFeatureValue(linksFeat, firstNode);
// create a view w/o setting document text
CAS view1 = cas1.createView("View1");
// create another view
CAS preexistingView = cas1.createView("preexistingView");
String preexistingViewText = "John Smith blah blah blah";
preexistingView.setDocumentText(preexistingViewText);
AnnotationFS person1Annot = createPersonAnnot(preexistingView, 0, 10);
person1Annot.setStringValue(componentIdFeat, "deltacas1");
AnnotationFS person2Annot = createPersonAnnot(preexistingView, 0, 5);
AnnotationFS orgAnnot = preexistingView.createAnnotation(orgType, 16, 24);
preexistingView.addFsToIndexes(orgAnnot);
AnnotationFS ownerAnnot = preexistingView.createAnnotation(ownerType, 0, 24);
preexistingView.addFsToIndexes(ownerAnnot);
FeatureStructure relArgs = cas1.createFS(relArgsType);
relArgs.setFeatureValue(domainFeat, person1Annot);
ownerAnnot.setFeatureValue(argsFeat, relArgs);
//serialize complete
XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
String xml = serialize(cas1, sharedData);
int maxOutgoingXmiId = sharedData.getMaxXmiId();
//System.out.println("CAS1 " + xml);
//System.out.println("MaxOutgoingXmiId " + maxOutgoingXmiId);
//deserialize into cas2
XmiSerializationSharedData sharedData2 = new XmiSerializationSharedData();
this.deserialize(xml, cas2, sharedData2, true, -1);
CasComparer.assertEquals(cas1, cas2);
//=======================================================================
//create Marker, add/modify fs and serialize in delta xmi format.
Marker marker = cas2.createMarker();
FSIndex cas2tIndex = cas2.getAnnotationIndex();
CAS cas2preexistingView = cas2.getView("preexistingView");
FSIndex cas2personIndex = cas2preexistingView.getAnnotationIndex(personType);
FSIndex cas2orgIndex = cas2preexistingView.getAnnotationIndex(orgType);
FSIndex cas2ownerIndex = cas2preexistingView.getAnnotationIndex(ownerType);
// create an annotation and add to index
AnnotationFS cas2anAnnot5 = cas2.createAnnotation(cas2.getAnnotationType(), 6, 8);
cas2.getIndexRepository().addFS(cas2anAnnot5);
assertTrue(cas2tIndex.size() == 6); // prev annots and this new one
// set document text of View1
CAS cas2view1 = cas2.getView("View1");
cas2view1.setDocumentText("This is the View1 document.");
//create an annotation in View1
AnnotationFS cas2view1Annot = cas2view1.createAnnotation(cas2.getAnnotationType(), 1, 5);
cas2view1.getIndexRepository().addFS(cas2view1Annot);
FSIndex cas2view1Index = cas2view1.getAnnotationIndex();
assertTrue(cas2view1Index.size() == 2); //document annot and this annot
//modify an existing annotation
Iterator<FeatureStructure> tIndexIter = cas2tIndex.iterator();
AnnotationFS docAnnot = (AnnotationFS) tIndexIter.next(); //doc annot
AnnotationFS modAnnot1 = (AnnotationFS) tIndexIter.next();
AnnotationFS delAnnot = (AnnotationFS) tIndexIter.next();
//modify language feature
Feature languageF = cas2.getDocumentAnnotation().getType().getFeatureByBaseName(CAS.FEATURE_BASE_NAME_LANGUAGE);
docAnnot.setStringValue(languageF, "en");
//index update - reindex
cas2.getIndexRepository().removeFS(modAnnot1);
Feature endF = cas2.getAnnotationType().getFeatureByBaseName(CAS.FEATURE_BASE_NAME_END);
modAnnot1.setIntValue(endF, 4);
cas2.getIndexRepository().addFS(modAnnot1);
//index update - remove annotation from index
cas2.getIndexRepository().removeFS(delAnnot);
//modify FS - string feature and FS feature.
Iterator<FeatureStructure> personIter = cas2personIndex.iterator();
AnnotationFS cas2person1 = (AnnotationFS) personIter.next();
AnnotationFS cas2person2 = (AnnotationFS) personIter.next();
cas2person1.setFloatValue(confidenceFeat, (float) 99.99);
cas2person1.setStringValue(mentionTypeFeat, "FULLNAME");
cas2person2.setStringValue(componentIdFeat, "delataCas2");
cas2person2.setStringValue(mentionTypeFeat, "FIRSTNAME");
Iterator<FeatureStructure> orgIter = cas2orgIndex.iterator();
AnnotationFS cas2orgAnnot = (AnnotationFS) orgIter.next();
cas2orgAnnot.setStringValue(mentionTypeFeat, "ORGNAME");
//modify FS feature
Iterator<FeatureStructure> ownerIter = cas2ownerIndex.iterator();
AnnotationFS cas2ownerAnnot = (AnnotationFS) ownerIter.next();
FeatureStructure cas2relArgs = cas2ownerAnnot.getFeatureValue(argsFeat);
cas2relArgs.setFeatureValue(rangeFeat, cas2orgAnnot);
//Test modification of a nonshared multivalued feature.
//This should serialize the encompassing FS.
Iterator<FeatureStructure> iter = cas2.getIndexRepository().getIndex("testEntityIndex").iterator();
FeatureStructure cas2EntityFS = (FeatureStructure) iter.next();
StringArrayFS cas2strarrayFS = (StringArrayFS) cas2EntityFS.getFeatureValue(classesFeat);
cas2strarrayFS.set(1, "class2");
cas2strarrayFS.set(2, "class3");
cas2strarrayFS.set(3, "class4");
cas2strarrayFS.set(4, "class5");
//add to FSList
FeatureStructure cas2linksFS = cas2EntityFS.getFeatureValue(linksFeat);
FeatureStructure cas2secondNode = cas2linksFS.getFeatureValue(tailFeat);
FeatureStructure cas2emptyNode = cas2secondNode.getFeatureValue(tailFeat);
FeatureStructure cas2thirdNode = cas2.createFS(nonEmptyFsListType);
cas2thirdNode.setFeatureValue(headFeat, cas2anAnnot5);
cas2thirdNode.setFeatureValue(tailFeat, cas2emptyNode);
cas2secondNode.setFeatureValue(tailFeat, cas2thirdNode);
// // Test that the new access method returns an array containing just the right marker
// removed per https://issues.apache.org/jira/browse/UIMA-2478
// List<Marker> mkrs = cas2.getMarkers();