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 2017/09/30 19:05:20 UTC

svn commit: r1810229 - in /uima/uv3/uimaj-v3/trunk: uima-docbook-v3-users-guide/src/docbook/ uimaj-core/src/main/java/org/apache/uima/cas/impl/ uimaj-core/src/test/java/org/apache/uima/cas/test/

Author: schor
Date: Sat Sep 30 19:05:19 2017
New Revision: 1810229

URL: http://svn.apache.org/viewvc?rev=1810229&view=rev
Log:
[UIMA-5595] fix pretty print for fs

Modified:
    uima/uv3/uimaj-v3/trunk/uima-docbook-v3-users-guide/src/docbook/uv3.migration.aids.xml
    uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImplC.java
    uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/SubiteratorTest.java

Modified: uima/uv3/uimaj-v3/trunk/uima-docbook-v3-users-guide/src/docbook/uv3.migration.aids.xml
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uima-docbook-v3-users-guide/src/docbook/uv3.migration.aids.xml?rev=1810229&r1=1810228&r2=1810229&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uima-docbook-v3-users-guide/src/docbook/uv3.migration.aids.xml (original)
+++ uima/uv3/uimaj-v3/trunk/uima-docbook-v3-users-guide/src/docbook/uv3.migration.aids.xml Sat Sep 30 19:05:19 2017
@@ -41,7 +41,7 @@ under the License.
     <title>Properties Table</title>
       
     <para>This table describes the various JVM defined properties; specify these on the Java command line
-    using -Dxxxxxx, where the xxxxxx is one of
+    using <code>-Dxxxxxx</code>, where the <code>xxxxxx</code> is one of
     the properties starting with <code>uima.</code> from the table below.</para>  
     <informaltable frame="all" rowsep="1" colsep="1">
      <tgroup cols="2">
@@ -58,9 +58,21 @@ under the License.
 
          <!-- ******************************************************************************* -->
          <row>
+           <entry><para>Use UIMA V2 format for toString() for Feature Structures</para></entry>
+           
+           <entry><para><code>uima.uima.v2_pretty_print_format</code></para>
+           
+                  <para>The native v3 format for pretty printing feature structures
+                    includes an id number with each FS, and some other minor improvements.
+                    If you have code which depends on the exact format that v2 UIMA produced
+                    for the toString() operation on Feature Structures, then include this
+                    flag to revert to that format.</para></entry>
+         </row>
+         <!-- ******************************************************************************* -->
+         <row>
            <entry><para>Disable Type System consolidation</para></entry>
            
-           <entry><para>uima.disable_typesystem_consolidation</para>
+           <entry><para><code>uima.disable_typesystem_consolidation</code></para>
            
                   <para>Default: equal Type Systems are consolidated.</para>
                   <para>When type systems are committed, the resulting Type System (Java object) 
@@ -74,7 +86,7 @@ under the License.
          <row>
            <entry><para>Enable finding all Feature Structures by their int ID</para></entry>
            
-           <entry><para>uima.enable_id_to_feature_structure_map_for_all_fss</para>
+           <entry><para><code>uima.enable_id_to_feature_structure_map_for_all_fss</code></para>
            
                   <para>Default: normally created Feature Structures are not kept in a map.</para>
                   <para>In version 3, normally, Feature Structures are not added to the 
@@ -91,7 +103,7 @@ under the License.
          <row>
            <entry><para>Disabling runtime feature validation</para></entry>
            
-           <entry><para>uima.uima.disable_runtime_feature_validation</para>
+           <entry><para><code>uima.uima.disable_runtime_feature_validation</code></para>
            
                   <para>Once code is running correctly, you may remove this check for performance
                     reasons by setting this property.</para></entry>
@@ -100,7 +112,7 @@ under the License.
          <row>
            <entry><para>Disabling runtime feature <emphasis>value</emphasis> validation</para></entry>
            
-           <entry><para>uima.disable_runtime_feature_value_validation</para>
+           <entry><para><code>uima.disable_runtime_feature_value_validation</code></para>
            
                   <para>Default: features being set into FS features which are FSs are checked for proper type subsumption.</para>
                   <para>Once code is running correctly, you may remove this check for performance

Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImplC.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImplC.java?rev=1810229&r1=1810228&r2=1810229&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImplC.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImplC.java Sat Sep 30 19:05:19 2017
@@ -28,6 +28,7 @@ import java.util.function.IntFunction;
 
 import org.apache.uima.UIMARuntimeException;
 import org.apache.uima.UIMA_IllegalStateException;
+import org.apache.uima.UimaSerializableFSs;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASRuntimeException;
 import org.apache.uima.cas.CommonArrayFS;
@@ -47,6 +48,7 @@ import org.apache.uima.jcas.cas.FloatArr
 import org.apache.uima.jcas.cas.IntegerArray;
 import org.apache.uima.jcas.cas.LongArray;
 import org.apache.uima.jcas.cas.ShortArray;
+import org.apache.uima.jcas.cas.Sofa;
 import org.apache.uima.jcas.cas.StringArray;
 import org.apache.uima.jcas.cas.TOP;
 import org.apache.uima.jcas.impl.JCasImpl;
@@ -80,6 +82,10 @@ public class FeatureStructureImplC imple
   public static final String DISABLE_RUNTIME_FEATURE_VALUE_VALIDATION = "uima.disable_runtime_feature_value_validation";
   public static final boolean IS_ENABLE_RUNTIME_FEATURE_VALUE_VALIDATION  = !Misc.getNoValueSystemProperty(DISABLE_RUNTIME_FEATURE_VALUE_VALIDATION);
  
+  public static final String V2_PRETTY_PRINT = "uima.v2_pretty_print_format";
+  public static final boolean IS_V2_PRETTY_PRINT = // debug true || 
+                                                   Misc.getNoValueSystemProperty(V2_PRETTY_PRINT);
+  
   private  static final boolean traceFSs = CASImpl.traceFSs;
     
   // next is for experiment (Not implemented) of allocating multiple int arrays for different fss
@@ -979,6 +985,14 @@ public class FeatureStructureImplC imple
     getPrintRefs(printRefs, this);
   }
 
+  /**
+   * This is called, once, at the top level thing being printed.
+   * It recursively descends any references, and updates the
+   * PrintReferences with info needed to handle circular structures 
+   * 
+   * @param printRefs the PrintReferences to update
+   * @param fs the top level FS being pretty printed, to descend if needed
+   */
   private final void getPrintRefs(PrintReferences printRefs, FeatureStructureImplC fs) {
     if (null == fs) {
       return;
@@ -990,11 +1004,15 @@ public class FeatureStructureImplC imple
     
     final TypeImpl ti = fs._typeImpl;
     if (ti != null) { // null for REMOVED marker
+      
       if (ti.isArray() && (fs instanceof FSArray)) {
         for (TOP item : ((FSArray)fs)._getTheArray()) {
           getPrintRefs(printRefs, item);
         }
       } else {
+        if (fs instanceof UimaSerializableFSs) {
+          ((UimaSerializableFSs)fs)._save_fsRefs_to_cas_data();
+        }
         ti.getFeaturesAsStream()
           .filter(fi -> fi.getRangeImpl().isRefType)     // is ref type
           .map(fi -> fs.getFeatureValue(fi)) // get the feature value
@@ -1107,11 +1125,11 @@ public class FeatureStructureImplC imple
     
     try {
     indent += incr;
-    if (indent > 20) {
+    if (!IS_V2_PRETTY_PRINT && indent > 20) {
       buf.append(" ... past indent 20 ... ");
       return;
     }
-    getPrintRefs(printRefs, this);
+      
     final int printInfo = printRefs.printInfo(this);
     if (printInfo != PrintReferences.NO_LABEL) {
       String label = printRefs.getLabel(this);
@@ -1119,7 +1137,7 @@ public class FeatureStructureImplC imple
         buf.append(printRefs.getLabel(this));
       }
       if (printInfo == PrintReferences.JUST_LABEL) {
-        buf.append(' ');  // was newline
+        buf.append(IS_V2_PRETTY_PRINT ? ' ' : '\n');  
         return;
       }
       buf.append(' ');
@@ -1136,7 +1154,11 @@ public class FeatureStructureImplC imple
       } else {
         buf.append(getType().getName());
       }
-      buf.append(':').append(_id);
+      
+      if (!IS_V2_PRETTY_PRINT) {
+        buf.append(':').append(_id);
+      }
+      
       if (s != null) {
         buf.append(" \"" + s + "\"");
       }
@@ -1198,7 +1220,10 @@ public class FeatureStructureImplC imple
       
       return;
     }  // end of case
+    
     }  // end of switch
+
+    // if get here, non of the cases in the above switch fit
     
     if (this instanceof FSArray) {  // catches instance of FSArrays which are "typed" to hold specific element types
       FSArray a = (FSArray) this;
@@ -1213,8 +1238,9 @@ public class FeatureStructureImplC imple
       StringUtils.printSpaces(indent, buf);
       buf.append(fi.getShortName() + ": ");
       TypeImpl range = (TypeImpl) fi.getRange();
-      if (range.isPrimitive()) {
+      if (range.isPrimitive()) {  // Strings and string subtypes are primitive
         addStringOrPrimitive(buf, fi);
+        buf.append('\n'); 
         continue;
       }
       
@@ -1235,7 +1261,12 @@ public class FeatureStructureImplC imple
             buf.append(val._getTypeImpl().getShortName()).append(':').append(val._id);
           }
         } else {
-          ppval(val, indent, incr, buf, useShortNames, printRefs, false);          
+          // treat sofa refs special, since they're pervasive
+          if (val instanceof Sofa) {
+            buf.append(((Sofa)val).getSofaID());
+          } else {
+            ppval(val, indent, incr, buf, useShortNames, printRefs, false);
+          }
           buf.append('\n');
         }
         
@@ -1298,7 +1329,9 @@ public class FeatureStructureImplC imple
     if (arrayLen > 0) {
       StringUtils.printSpaces(indent, buf);
       buf.append("Array elements: [");
-      int numToPrint = Math.min(15, arrayLen);  // print 15 or fewer elements
+      int numToPrint = IS_V2_PRETTY_PRINT
+                          ? arrayLen
+                          : Math.min(15, arrayLen);  // print 15 or fewer elements
 
       for (int i = 0; i < numToPrint; i++) {
         if (i > 0) {
@@ -1308,7 +1341,11 @@ public class FeatureStructureImplC imple
         if (null == element) {
           buf.append("null");
         } else {
-          buf.append("\"" + Misc.elideString(element, 50) + "\"");  // was 15
+          buf.append('"');
+          buf.append(IS_V2_PRETTY_PRINT
+                       ? element
+                       : Misc.elideString(element, 50));
+          buf.append('"');
         }
       }
       

Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/SubiteratorTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/SubiteratorTest.java?rev=1810229&r1=1810228&r2=1810229&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/SubiteratorTest.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/SubiteratorTest.java Sat Sep 30 19:05:19 2017
@@ -117,6 +117,7 @@ public class SubiteratorTest extends Tes
     Annotation sentence = jcas.getAnnotationIndex(Sentence.class).iterator().next();
     FSIterator<Token> tokenIterator = tokenIndex.subiterator(sentence);
     Annotation token = tokenIndex.iterator().next();
+    // debug token.toString();
     tokenIterator.moveTo(token); //throws ClassCastException 
     
     // check unambiguous iterator creation