You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ea...@apache.org on 2010/12/06 19:12:43 UTC
svn commit: r1042751 - in /uima/uimaj/trunk/uimaj-core/src:
main/java/org/apache/uima/cas/impl/XmiCasDeserializer.java
test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java
Author: eae
Date: Mon Dec 6 18:12:42 2010
New Revision: 1042751
URL: http://svn.apache.org/viewvc?rev=1042751&view=rev
Log:
UIMA-1965
Modified:
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasDeserializer.java
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasDeserializer.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasDeserializer.java?rev=1042751&r1=1042750&r2=1042751&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasDeserializer.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasDeserializer.java Mon Dec 6 18:12:42 2010
@@ -527,9 +527,11 @@ public class XmiCasDeserializer {
if (membersString != null) {
// a view with no Sofa will be added to the 1st, _InitialView, index
int sofaNum = 1;
+ boolean newview = false;
if (sofa != null) {
// translate sofa's xmi:id into its sofanum
int sofaXmiId = Integer.parseInt(sofa);
+ newview = isNewFS(sofaXmiId);
int sofaAddr;
try {
sofaAddr = getFsAddrForXmiId(sofaXmiId);
@@ -545,12 +547,18 @@ public class XmiCasDeserializer {
String[] members = parseArray(membersString);
for (int i = 0; i < members.length; i++) {
int id = Integer.parseInt(members[i]);
- //if merging, don't try to index anything below the merge point
- if (!isNewFS(id)) {
- if (this.allowPreexistingFS == AllowPreexistingFS.disallow) { //flag this
- this.disallowedViewMemberEncountered = true;
- }
- continue;
+ // special handling for merge operations ...
+ if (!newview && !isNewFS(id)) {
+ // a pre-existing FS is indexed in a pre-existing view
+ if (this.allowPreexistingFS == AllowPreexistingFS.ignore) {
+ // merging with full CAS: ignore anything below the high water mark
+ continue;
+ }
+ if (this.allowPreexistingFS == AllowPreexistingFS.disallow) {
+ // merging with delta CAS: flag it
+ this.disallowedViewMemberEncountered = true;
+ continue;
+ }
}
// have to map each ID to its "real" address (TODO: optimize?)
//TODO: currently broken, can't use XmiSerializationSharedData for
Modified: uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java?rev=1042751&r1=1042750&r2=1042751&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java Mon Dec 6 18:12:42 2010
@@ -273,6 +273,105 @@ public class XmiCasDeserializerTest exte
}
}
+ public void testDeltaCasIndexExistingFsInView() throws Exception {
+ CAS cas1 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
+ indexes);
+ CAS cas2 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
+ indexes);
+ cas1.setDocumentText("This is a test document in the initial view");
+ Type referentType = cas1.getTypeSystem().getType("org.apache.uima.testTypeSystem.Referent");
+ FeatureStructure fs1 = cas1.createFS(referentType);
+ cas1.getIndexRepository().addFS(fs1);
+
+ //serialize complete
+ XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
+ String xml = serialize(cas1, sharedData);
+ System.out.println(xml);
+ int maxOutgoingXmiId = sharedData.getMaxXmiId();
+
+ //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();
+
+ //create View
+ CAS view = cas2.createView("NewView");
+ //add FS to index
+ Type referentType2 = cas2.getTypeSystem().getType("org.apache.uima.testTypeSystem.Referent");
+ Iterator<FeatureStructure> fsIter = cas2.getIndexRepository().getAllIndexedFS(referentType2);
+ while (fsIter.hasNext()) {
+ FeatureStructure fs = fsIter.next();
+ view.getIndexRepository().addFS(fs);
+ }
+ AnnotationFS cas2newAnnot = view.createAnnotation(cas2.getAnnotationType(), 6, 8);
+ view.getIndexRepository().addFS(cas2newAnnot);
+
+ // serialize cas2 in delta format
+ String deltaxml1 = serialize(cas2, sharedData2, marker);
+ System.out.println(deltaxml1);
+
+ //deserialize delta xmi into cas1
+ this.deserialize(deltaxml1, cas1, sharedData, true, maxOutgoingXmiId, AllowPreexistingFS.allow);
+
+ //check that new View contains the FS
+ CAS deserView = cas1.getView("NewView");
+ Iterator<FeatureStructure> deserFsIter = deserView.getIndexRepository().getAllIndexedFS(referentType);
+ assertTrue(deserFsIter.hasNext());
+ }
+
+
+ public void testDeltaCasIndexExistingFsInNewView() throws Exception {
+ CAS cas1 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
+ indexes);
+ CAS cas2 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
+ indexes);
+ cas1.setDocumentText("This is a test document in the initial view");
+ Type referentType = cas1.getTypeSystem().getType("org.apache.uima.testTypeSystem.Referent");
+ FeatureStructure fs1 = cas1.createFS(referentType);
+ cas1.getIndexRepository().addFS(fs1);
+
+ //serialize complete
+ XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
+ String xml = serialize(cas1, sharedData);
+ System.out.println(xml);
+ int maxOutgoingXmiId = sharedData.getMaxXmiId();
+
+ //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();
+
+ //create View
+ CAS view = cas2.createView("NewView");
+ //add FS to index
+ Type referentType2 = cas2.getTypeSystem().getType("org.apache.uima.testTypeSystem.Referent");
+ Iterator<FeatureStructure> fsIter = cas2.getIndexRepository().getAllIndexedFS(referentType2);
+ while (fsIter.hasNext()) {
+ FeatureStructure fs = fsIter.next();
+ view.getIndexRepository().addFS(fs);
+ }
+ AnnotationFS cas2newAnnot = view.createAnnotation(cas2.getAnnotationType(), 6, 8);
+ view.getIndexRepository().addFS(cas2newAnnot);
+
+ // serialize cas2 in delta format
+ String deltaxml1 = serialize(cas2, sharedData2, marker);
+ System.out.println(deltaxml1);
+
+ //deserialize delta xmi into cas1
+ this.deserialize(deltaxml1, cas1, sharedData, true, maxOutgoingXmiId, AllowPreexistingFS.allow);
+
+ //check that new View contains the FS
+ CAS deserView = cas1.getView("NewView");
+ Iterator<FeatureStructure> deserFsIter = deserView.getIndexRepository().getAllIndexedFS(referentType);
+ assertTrue(deserFsIter.hasNext());
+ }
+
public void testMultipleSofas() throws Exception {
try {
@@ -1695,7 +1794,7 @@ public class XmiCasDeserializerTest exte
childCountStack.push(Integer.valueOf(count.intValue() - 1));
}
}
-
+
}
}