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 2008/12/23 03:05:57 UTC

svn commit: r728845 - in /incubator/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 22 18:05:56 2008
New Revision: 728845

URL: http://svn.apache.org/viewvc?rev=728845&view=rev
Log:
UIMA-1256 commit uima-1256.patch

Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasDeserializer.java
    incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasDeserializer.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasDeserializer.java?rev=728845&r1=728844&r2=728845&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasDeserializer.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasDeserializer.java Mon Dec 22 18:05:56 2008
@@ -1069,16 +1069,25 @@
           // adds each list node ID to the fsListNodesFromMultivaluedProperties list.
           // We need this so we can go back through later and reset the addresses of the
           // "head" features of these lists nodes (but not reset the tail features).
+          // It also adds a mapping between the nodes and the encompassing FS in order
+          // to properly serialize in delta xmi format.
           int listFS = casBeingFilled.getFeatureValue(addr, featCode);
+          IntVector fslistnodes = new IntVector();
           if (listFS == 0) {
-            listFS = listUtils.createFsList(featVals, fsListNodesFromMultivaluedProperties);
+            listFS = listUtils.createFsList(featVals, fslistnodes);
             casBeingFilled.setFeatureValue(addr, featCode, listFS);
           } else {
-        	listUtils.updateFsList(listFS, featVals, fsListNodesFromMultivaluedProperties);
+        	listUtils.updateFsList(listFS, featVals, fslistnodes);
+          } 
+          //add to multivaluedproperties fs list.
+          for (int i=0; i < fslistnodes.size();  i++) {
+        	  fsListNodesFromMultivaluedProperties.add(fslistnodes.get(i));
           }
-          //add to nonshared fs to encompassing FS map
+          //add to nonshared fs to encompassing FS map.
           if (!ts.ll_getFeatureForCode(featCode).isMultipleReferencesAllowed()) {
-            addNonsharedFSToEncompassingFSMapping(listFS, addr);
+        	for (int i=0; i < fslistnodes.size(); i++) {
+        	  addNonsharedFSToEncompassingFSMapping(fslistnodes.get(i), addr);
+        	}
           }
           break;
         }

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java?rev=728845&r1=728844&r2=728845&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java Mon Dec 22 18:05:56 2008
@@ -1156,6 +1156,127 @@
     }
   }
   
+  public void testDeltaCasListFS() throws Exception {
+	   try {
+	      CAS cas1 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
+	              indexes);
+	      CAS cas2 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
+	              indexes);
+	      CAS cas3 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
+	              indexes);
+	      
+	      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");
+	       
+	      //serialize complete  
+	      XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
+	      String xml = this.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();
+	      
+	      // 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
+	      // create an annotation and add to index
+	      AnnotationFS cas2anAnnot6 = cas2.createAnnotation(cas2.getAnnotationType(), 6, 8);
+	      cas2.getIndexRepository().addFS(cas2anAnnot6);
+	      assertTrue(cas2tIndex.size() == 7); // prev annots and twonew one
+	      
+	      //add to FSList 
+	      Iterator iter = cas2.getIndexRepository().getIndex("testEntityIndex").iterator();
+	      FeatureStructure cas2EntityFS = (FeatureStructure) iter.next();
+	      FeatureStructure cas2linksFS = cas2EntityFS.getFeatureValue(linksFeat);
+	      FeatureStructure cas2secondNode = cas2linksFS.getFeatureValue(tailFeat);
+	      FeatureStructure cas2emptyNode = cas2secondNode.getFeatureValue(tailFeat);
+	      FeatureStructure cas2thirdNode = cas2.createFS(nonEmptyFsListType);
+	      FeatureStructure cas2fourthNode = cas2.createFS(nonEmptyFsListType);
+	      
+	      cas2secondNode.setFeatureValue(tailFeat, cas2thirdNode);
+	      cas2thirdNode.setFeatureValue(headFeat, cas2anAnnot5);
+	      cas2thirdNode.setFeatureValue(tailFeat, cas2fourthNode);
+	      cas2fourthNode.setFeatureValue(headFeat, cas2anAnnot6);
+	      cas2fourthNode.setFeatureValue(tailFeat, cas2emptyNode);
+	      
+	      // serialize cas2 in delta format 
+	      String deltaxml1 = this.serialize(cas2, sharedData2, marker);
+	      //System.out.println("delta cas");
+	      //System.out.println(deltaxml1);
+	      
+	      //======================================================================
+	      //deserialize delta xmi into cas1
+	      this.deserialize(deltaxml1, cas1, sharedData, true, maxOutgoingXmiId, AllowPreexistingFS.allow);
+	      CasComparer.assertEquals(cas2linksFS, entityFS.getFeatureValue(linksFeat));
+	      //======================================================================
+	      //serialize complete cas and deserialize into cas3 and compare with cas1.
+	      String fullxml = this.serialize(cas2, sharedData2);
+	      XmiSerializationSharedData sharedData3 = new XmiSerializationSharedData();
+	      this.deserialize(fullxml, cas3, sharedData3, true,-1);
+	      CasComparer.assertEquals(cas1, cas3); 
+	      
+	      //System.out.println("CAS1 " + serialize(cas1, new XmiSerializationSharedData()));
+	      //System.out.println("CAS2 " + serialize(cas2, new XmiSerializationSharedData()));
+	      
+	    } catch (Exception e) {
+	      JUnitExtension.handleException(e);
+	    }
+	  }
+  
+  
+  
   public void testOutOfTypeSystemData() throws Exception {
     // deserialize a simple XMI into a CAS with no TypeSystem    
     CAS cas = CasCreationUtils.createCas(new TypeSystemDescription_impl(),