You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2016/08/25 14:39:40 UTC

svn commit: r1757695 - in /uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima: cas/impl/CASImpl.java util/CasIOUtils.java

Author: schor
Date: Thu Aug 25 14:39:40 2016
New Revision: 1757695

URL: http://svn.apache.org/viewvc?rev=1757695&view=rev
Log:
[UIMA-4685] allow null for typeSystem arg in load(..., typeSystem). fix logic and javadocs to order form 6 decoding type system sources: embedded first (always right, if available), type system passed in (either via load(..., typeSystem) or constructor for form6), and last choice the type system obtained from the 2nd input source of load.

Modified:
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java

Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java?rev=1757695&r1=1757694&r2=1757695&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java Thu Aug 25 14:39:40 2016
@@ -1474,13 +1474,48 @@ public class CASImpl extends AbstractCas
           tsRead.commit();  // no generators set up
         }
           
-        TypeSystemImpl ts_for_decoding = (ts != null)
-                                           ? ts 
-                                           : (f6 == null) 
-                                               ? tsRead
-                                               : (f6.getTgtTs() == null)
-                                                   ? tsRead
-                                                   : f6.getTgtTs(); 
+        
+        TypeSystemImpl ts_for_decoding =
+            (tsRead != null && embeddedCasMgrSerializer != null) 
+              ? tsRead                      // first choice: embedded - it's always correct
+              : (ts != null)                // 2nd choice is passed in ts arg, either ts or f6.getTgtTs() 
+                  ? ts
+                  : (f6 != null && f6.getTgtTs() != null)
+                      ? f6.getTgtTs()       // this is the ts passed in via BinaryCasSerDes6 constructor
+                      : tsRead;             // last choice: the ts read from 2nd input to load() in CasIOUtils
+            
+            
+//            (f6 != null)                    
+//              ? ((f6.getTgtTs() != null)    // first choice: embedded, because it's always correct 
+//                   ? f6.getTgtTs()
+//                   : (ts != null)           // 2nd choice: ts passed in
+//                       ? ts
+//                       : tsRead)            // 3rd choice: tsRead
+//              : (ts != null)            // no embedded
+//                  ? ts
+//                  : tsRead;
+                   
+//        if (f6 != null) {
+//          ts_for_decoding = f6.getTgtTs(); // use embedded one if available
+//          if (null == ts_for_decoding) {
+//            ts_for_decoding = ts;          // use argument ts
+//          }
+//          if (null == ts_for_decoding) {
+//            ts_for_decoding = tsRead;
+//          }
+//        } else {
+//          ts_for_decoding = (ts != null) 
+//                              ? ts
+//                              : tsRead;
+//        }
+          
+//        TypeSystemImpl ts_for_decoding = (ts != null)
+//                                           ? ts 
+//                                           : (f6 == null) 
+//                                               ? tsRead
+//                                               : (f6.getTgtTs() == null)
+//                                                   ? tsRead
+//                                                   : f6.getTgtTs(); 
                                                    
         try {
           BinaryCasSerDes6 bcsd = (f6 != null) 

Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java?rev=1757695&r1=1757694&r2=1757695&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java Thu Aug 25 14:39:40 2016
@@ -139,7 +139,7 @@ import org.xml.sax.SAXException;
  * <pre style="padding-left: 30px;">
  *   <code>load(aURL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , aCas)</code>
  *   <code>load(inputStream, aCas)</code>
- *   <code>load(inputStream, aCas, typeSystem)</code> // for Compressed Form 6 only
+ *   <code>load(inputStream, aCas, typeSystem)</code> // typeSystem used for decoding Compressed Form 6
  *   <code>load(inputStream, tsiInputStream, aCas)</code></pre>
  * <pre style="padding-left: 30px;">
  *   <code>load(aURL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , tsiURL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , aCAS, casLoadMode)&nbsp;&nbsp; - the second URL is for loading a separately-stored TSI</code>
@@ -313,8 +313,24 @@ public class CasIOUtils {
   }
   
   /**
-   * This is used for loading Form 6 compressed CASes where the type system to use to deserialize is provided as an argument.
-   *  
+   * This load variant can be used for loading Form 6 compressed CASes where the 
+   * type system to use to deserialize is provided as an argument.  It can also load other formats,
+   * where its behavior is identical to load(casInputStream, aCas).
+   *
+   * Loads a CAS from an Input Stream. The format is determined from the content.
+   * For SerialFormats of ending in _TSI SERIALIZED_TSI or COMPRESSED_FILTERED_TSI, 
+   * the type system and index definitions are read from the cas input source;
+   * the value of typeSystem is ignored.
+   * 
+   * For COMPRESSED_FILTERED_xxx formats, if the typeSystem is not null, 
+   * the typeSystem is used for decoding.
+   * 
+   * If embedded TSI information is available, the CAS's type system and indexes definition are replaced,
+   * except for SerialFormats COMPRESSED_FILTERED, COMPRESSED_FILTERED_TS, and COMPRESSED_FILTERED_TSI.
+   * 
+   *   To replace the CAS's type system and indexes definition for these, use a load form which 
+   *   has the CasLoadMode argument, and set this to REINIT.
+   *     
    * @param casInputStream
    *          The input stream containing the CAS, appropriately buffered.
    * @param aCAS
@@ -324,9 +340,6 @@ public class CasIOUtils {
    * @throws IOException Problem loading from given InputStream   
    */
   public static SerialFormat load(InputStream casInputStream, CAS aCAS, TypeSystem typeSystem) throws IOException {
-    if (null == typeSystem) {
-      throw new IllegalArgumentException("typeSystem argument cannot be null");
-    }
     return load(casInputStream, null, aCAS, CasLoadMode.DEFAULT, (TypeSystemImpl) typeSystem);
   }