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/09/04 14:41:04 UTC

svn commit: r691994 - in /incubator/uima/uimaj/trunk/uimaj-core/src: main/java/org/apache/uima/cas/impl/ test/java/org/apache/uima/cas/impl/

Author: eae
Date: Thu Sep  4 05:41:02 2008
New Revision: 691994

URL: http://svn.apache.org/viewvc?rev=691994&view=rev
Log:
UIMA-1129 Commit Bhavani's UIMA-1129-2.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/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiSerializationSharedData.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=691994&r1=691993&r2=691994&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 Thu Sep  4 05:41:02 2008
@@ -1005,6 +1005,10 @@
           if (currVal != casArray) {
             casBeingFilled.setFeatureValue(addr, featCode, casArray);
           }
+          //add to nonshared fs to encompassing FS map
+          if (!ts.ll_getFeatureForCode(featCode).isMultipleReferencesAllowed()) {
+            addNonsharedFSToEncompassingFSMapping(casArray, addr);
+          }
           break;
         }
         /**
@@ -1015,32 +1019,44 @@
         }
         **/
         case XmiCasSerializer.TYPE_CLASS_INTLIST: {
-          int currVal = casBeingFilled.getFeatureValue(addr, featCode);
-          if (currVal == 0) {
-            int listFS = listUtils.createIntList(featVals);
+          int listFS = casBeingFilled.getFeatureValue(addr, featCode);
+          if (listFS == 0) {
+            listFS = listUtils.createIntList(featVals);
             casBeingFilled.setFeatureValue(addr, featCode, listFS);
           } else {
-        	listUtils.updateIntList(currVal, featVals);
+        	listUtils.updateIntList(listFS, featVals);
+          }
+          //add to nonshared fs to encompassing FS map
+          if (!ts.ll_getFeatureForCode(featCode).isMultipleReferencesAllowed()) {
+            addNonsharedFSToEncompassingFSMapping(listFS, addr);
           }
           break;
         }
         case XmiCasSerializer.TYPE_CLASS_FLOATLIST: {
-          int currVal = casBeingFilled.getFeatureValue(addr, featCode);
-          if (currVal == 0) {
-            int listFS = listUtils.createFloatList(featVals);
+          int listFS = casBeingFilled.getFeatureValue(addr, featCode);
+          if (listFS == 0) {
+            listFS = listUtils.createFloatList(featVals);
             casBeingFilled.setFeatureValue(addr, featCode, listFS);
           } else {
-        	listUtils.updateFloatList(currVal, featVals);
+        	listUtils.updateFloatList(listFS, featVals);
+          }
+          //add to nonshared fs to encompassing FS map
+          if (!ts.ll_getFeatureForCode(featCode).isMultipleReferencesAllowed()) {
+            addNonsharedFSToEncompassingFSMapping(listFS, addr);
           }
           break;
         }
         case XmiCasSerializer.TYPE_CLASS_STRINGLIST: {
-          int currVal = casBeingFilled.getFeatureValue(addr, featCode);
-          if (currVal == 0) {
-            int listFS = listUtils.createStringList(featVals);
+          int listFS = casBeingFilled.getFeatureValue(addr, featCode);
+          if (listFS == 0) {
+            listFS = listUtils.createStringList(featVals);
             casBeingFilled.setFeatureValue(addr, featCode, listFS);
           } else {
-        	listUtils.updateStringList(currVal, featVals);
+        	listUtils.updateStringList(listFS, featVals);
+          }
+          //add to nonshared fs to encompassing FS map
+          if (!ts.ll_getFeatureForCode(featCode).isMultipleReferencesAllowed()) {
+            addNonsharedFSToEncompassingFSMapping(listFS, addr);
           }
           break;
         }
@@ -1049,12 +1065,16 @@
           // 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).
-          int currVal = casBeingFilled.getFeatureValue(addr, featCode);
-          if (currVal == 0) {
-            int listFS = listUtils.createFsList(featVals, fsListNodesFromMultivaluedProperties);
+          int listFS = casBeingFilled.getFeatureValue(addr, featCode);
+          if (listFS == 0) {
+            listFS = listUtils.createFsList(featVals, fsListNodesFromMultivaluedProperties);
             casBeingFilled.setFeatureValue(addr, featCode, listFS);
           } else {
-        	listUtils.updateFsList(currVal, featVals, fsListNodesFromMultivaluedProperties);
+        	listUtils.updateFsList(listFS, featVals, fsListNodesFromMultivaluedProperties);
+          }
+          //add to nonshared fs to encompassing FS map
+          if (!ts.ll_getFeatureForCode(featCode).isMultipleReferencesAllowed()) {
+            addNonsharedFSToEncompassingFSMapping(listFS, addr);
           }
           break;
         }
@@ -1678,8 +1698,13 @@
     } 
     
     private boolean isNewFS(int id) {
-        return (id > this.mergePoint);
+      return (id > this.mergePoint);
     }  
+    
+    private void addNonsharedFSToEncompassingFSMapping(int nonsharedFS, int encompassingFS ) {
+      System.out.println("addNonsharedFSToEncompassingFSMapping" + nonsharedFS + " " + encompassingFS);
+      this.sharedData.addNonsharedRefToFSMapping(nonsharedFS, encompassingFS);
+    }
   }
   
   private TypeSystemImpl ts;

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java?rev=691994&r1=691993&r2=691994&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java Thu Sep  4 05:41:02 2008
@@ -218,6 +218,7 @@
 
       enqueueIncoming(); //make sure we enqueue every FS that was deserialized into this CAS
       enqueueIndexed();
+      enqueueNonsharedMultivaluedFS();
       enqueueFeaturesOfIndexed();
       iElementCount += indexedFSs.size();
       iElementCount += queue.size();
@@ -451,6 +452,30 @@
         }
       }
     }
+    
+    /** 
+     * When serializing Delta CAS,
+     * enqueue encompassing FS of nonshared multivalued FS that have been modified.
+     * 
+     */
+    private void enqueueNonsharedMultivaluedFS() {
+	  if (this.sharedData == null || !isDelta)
+	      return;
+	  int[] fsAddrs = this.sharedData.getNonsharedMulitValuedFSs();
+	  for (int i = 0; i < fsAddrs.length; i++) {
+	    if (!marker.isModified(fsAddrs[i])) {
+	  	  continue; 
+	    } else {
+	      System.out.println("enqueueNonshared " + fsAddrs[i] + " "  + this.sharedData.getEncompassingFS(fsAddrs[i]));
+	      int encompassingFS = this.sharedData.getEncompassingFS(fsAddrs[i]);
+	      if (isVisited(encompassingFS)) {
+	        continue;
+	      }
+	      visited.put(encompassingFS, encompassingFS);
+	      indexedFSs.add(encompassingFS);
+	    }	  
+	  }
+    }
 
     /**
      * Enqueue everything reachable from features of indexed FSs.

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiSerializationSharedData.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiSerializationSharedData.java?rev=691994&r1=691993&r2=691994&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiSerializationSharedData.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiSerializationSharedData.java Thu Sep  4 05:41:02 2008
@@ -45,7 +45,8 @@
  *       whenever it encounters an XMI element that doesn't correspond to a type in the type system, it will populate the
  *       <code>XmiSerializationSharedData</code> with information about these elements.  If you then pass the same 
  *       <code>XmiSerializationSharedData</code> object to the serializer when you attempt to serialize the same CAS, these
- *       out-of-typesystem FS will be reserialized without loss of information.  References between in-typesystem and out-of-typesystem
+ *       out-of-typesystem FS will be reserialized without loss of inform
+ *       ation.  References between in-typesystem and out-of-typesystem
  *       FS (in either direction) are maintained as well.</li>
  *   <li>After calling the XmiCasSerializer and passing an <code>XmiSerializationSharedData</code>, you can call the
  *       {@link #getMaxXmiId()} method to get the maximum xmi:id value in the serialized CAS.  This feature, along with the consistency of
@@ -99,6 +100,17 @@
    * The maximum XMI ID used in the serialization. Used to generate unique IDs if needed.
    */
   private int maxXmiId = 0;
+  
+  
+  /**
+   * Map from FS address of a non-shared multi-valued (Array/List) FS to the 
+   * FS address of the encompassing FS which has a feature whose value is this multi-valued FS.
+   * Used when deserializing a Delta CAS to find and serialize the encompassing FS when 
+   * the non-shared array/list FS is modified. 
+   * @param fsAddr
+   * @param xmiId
+   */
+   RedBlackTree nonsharedfeatureIdToFSId = new RedBlackTree();
 
   void addIdMapping(int fsAddr, int xmiId) {
     fsAddrToXmiIdMap.put(fsAddr, Integer.toString(xmiId));
@@ -153,6 +165,7 @@
   public void clearIdMap() {
     fsAddrToXmiIdMap.clear();
     xmiIdToFsAddrMap.clear();
+    nonsharedfeatureIdToFSId.clear();
     maxXmiId = 0;
   }
   
@@ -291,6 +304,35 @@
   }
   
   /**
+   * Add mapping between the address of FS that is the value of a non-shared multi-valued
+   * feature of a FeatureStructure. 
+   * 
+   * @param nonsharedFSAddr - fs address of non-shared multi-valued feature value
+   * @param fsAddr - fs address of encompassing featurestructure
+   */
+  public void addNonsharedRefToFSMapping(int nonsharedFSAddr, int fsAddr) {
+	this.nonsharedfeatureIdToFSId.put(nonsharedFSAddr, Integer.valueOf(fsAddr));
+  }
+  
+  /**
+   * 
+   * @return
+   */
+  public int[] getNonsharedMulitValuedFSs() {
+    return this.nonsharedfeatureIdToFSId.keySet();
+  }
+  
+  /**
+   * 
+   * @param nonsharedFS
+   * @return
+   */
+  public int getEncompassingFS(int nonsharedFS) {
+	Integer addr = (Integer) this.nonsharedfeatureIdToFSId.get(nonsharedFS);
+	return addr == null ? -1 : addr.intValue();
+  }
+  
+  /**
    * For debugging purposes only.
    */
   void checkForDups() {

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=691994&r1=691993&r2=691994&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 Thu Sep  4 05:41:02 2008
@@ -1183,14 +1183,13 @@
       FeatureStructure cas2EntityFS = (FeatureStructure) iter.next();
       //cas2EntityFS.setStringValue(canonicalFormFeat, "canonicalname");
       
-      //set values of stringarray fs
+      //Test modification of a nonshared multivalued feature.
+      //This should serialize the encompassing FS.
       StringArrayFS cas2strarrayFS = (StringArrayFS) cas2EntityFS.getFeatureValue(classesFeat);
       cas2strarrayFS.set(1, "class2");
       cas2strarrayFS.set(2, "class3");
       cas2strarrayFS.set(3, "class4");
       cas2strarrayFS.set(4, "class5");
-      cas2EntityFS.setFeatureValue(classesFeat, cas2strarrayFS); //?? need to touch the entity FS
-                                         						//to serialize non-shared array or list 
       
       //add to FSList 
       FeatureStructure cas2linksFS = cas2EntityFS.getFeatureValue(linksFeat);
@@ -1203,8 +1202,8 @@
       
       // serialize cas2 in delta format 
       String deltaxml1 = this.serialize(cas2, sharedData2, marker);
-      //System.out.println("delta cas");
-      //System.out.println(deltaxml1);
+      System.out.println("delta cas");
+      System.out.println(deltaxml1);
       
       //======================================================================
       //deserialize delta xmi into cas1