CAS cas3 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
indexes);
Type personType = cas1.getTypeSystem().getType(
"org.apache.uima.testTypeSystem.Person");
Feature componentIdFeat = personType.getFeatureByBaseName("componentId");
Feature confidenceFeat = personType.getFeatureByBaseName("confidence");
Type orgType = cas1.getTypeSystem().getType(
"org.apache.uima.testTypeSystem.Organization");
Type ownerType = cas1.getTypeSystem().getType(
"org.apache.uima.testTypeSystem.Owner");
Type entityAnnotType = cas1.getTypeSystem().getType(
"org.apache.uima.testTypeSystem.EntityAnnotation");
Feature mentionTypeFeat = entityAnnotType.getFeatureByBaseName("mentionType");
Feature argsFeat = ownerType.getFeatureByBaseName("relationArgs");
Type relArgsType = cas1.getTypeSystem().getType(
"org.apache.uima.testTypeSystem.BinaryRelationArgs");
Feature domainFeat = relArgsType.getFeatureByBaseName("domainValue");
Feature rangeFeat = relArgsType.getFeatureByBaseName("rangeValue");
Type entityType = cas1.getTypeSystem().getType("org.apache.uima.testTypeSystem.Entity");
Feature classesFeat = entityType.getFeatureByBaseName("classes");
Feature linksFeat = entityType.getFeatureByBaseName("links");
Feature canonicalFormFeat = entityType.getFeatureByBaseName("canonicalForm");
Type nonEmptyFsListType = cas1.getTypeSystem().getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST);
Type emptyFsListType = cas1.getTypeSystem().getType(CAS.TYPE_NAME_EMPTY_FS_LIST);
Feature headFeat = nonEmptyFsListType.getFeatureByBaseName("head");
Feature tailFeat = nonEmptyFsListType.getFeatureByBaseName("tail");
//cas1
//initial set of feature structures
// set document text for the initial view and create Annotations
cas1.setDocumentText("This is a test document in the initial view");
AnnotationFS anAnnot1 = cas1.createAnnotation(cas1.getAnnotationType(), 0, 4);
cas1.getIndexRepository().addFS(anAnnot1);
AnnotationFS anAnnot2 = cas1.createAnnotation(cas1.getAnnotationType(), 5, 6);
cas1.getIndexRepository().addFS(anAnnot2);
AnnotationFS anAnnot3 = cas1.createAnnotation(cas1.getAnnotationType(), 8, 13);
cas1.getIndexRepository().addFS(anAnnot3);
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);