Author: pkluegl
Date: Mon Aug 24 15:01:28 2015
New Revision: 1697426

URL: http://svn.apache.org/r1697426
Log:
UIMA-4568
- added some debug logging for now (will be removed again)

Modified:
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
    
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/StackedScriptsTest.java

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java?rev=1697426&r1=1697425&r2=1697426&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
 Mon Aug 24 15:01:28 2015
@@ -70,6 +70,7 @@ import org.apache.uima.ruta.extensions.R
 import org.apache.uima.ruta.parser.RutaLexer;
 import org.apache.uima.ruta.parser.RutaParser;
 import org.apache.uima.ruta.seed.RutaAnnotationSeeder;
+import org.apache.uima.ruta.type.RutaBasic;
 import org.apache.uima.ruta.verbalize.RutaVerbalizer;
 import org.apache.uima.ruta.visitor.CreatedByVisitor;
 import org.apache.uima.ruta.visitor.DebugInfoCollectorVisitor;
@@ -91,16 +92,15 @@ public class RutaEngine extends JCasAnno
 
   public static final String FRAME_TYPE = 
"org.apache.uima.ruta.type.RutaFrame";
 
-  
   /**
-   * A String parameter representing the rule that should be applied by the 
analysis engine.
-   * If set, it replaces the content of file specified by the {@code 
mainScript} parameter.
+   * A String parameter representing the rule that should be applied by the 
analysis engine. If set,
+   * it replaces the content of file specified by the {@code mainScript} 
parameter.
    */
   public static final String PARAM_RULES = "rules";
 
   @ConfigurationParameter(name = PARAM_RULES, mandatory = false)
   private String rules;
-  
+
   /**
    * Load script in Java notation, with "{@code .}" as package separator and 
no extension. File
    * needs to be located in the path specified below with ending {@code .ruta}.
@@ -253,7 +253,7 @@ public class RutaEngine extends JCasAnno
    */
   public static final String PARAM_REMOVE_BASICS = "removeBasics";
 
-  @ConfigurationParameter(name = PARAM_REMOVE_BASICS, mandatory = false, 
defaultValue = "true")
+  @ConfigurationParameter(name = PARAM_REMOVE_BASICS, mandatory = false, 
defaultValue = "false")
   private Boolean removeBasics;
 
   /**
@@ -269,8 +269,8 @@ public class RutaEngine extends JCasAnno
 
   /**
    * This parameter specifies whether the memory consumption should be 
reduced. This parameter
-   * should be set to true for very large CAS documents (e.g., > 500k 
tokens), but it also reduces
-   * the performance. The default value is set to false.
+   * should be set to true for very large CAS documents (e.g., > 500k 
tokens), but it also
+   * reduces the performance. The default value is set to false.
    */
   public static final String PARAM_LOW_MEMORY_PROFILE = "lowMemoryProfile";
 
@@ -386,7 +386,8 @@ public class RutaEngine extends JCasAnno
    * string array specifies the variable of the n-th entry of the string array 
of the parameter
    * varValues. If the variables is defined in the root of a script, then the 
name of the variable
    * suffices. If the variable is defined in a BLOCK or imported script, then 
the the name must
-   * contain the namespaces of the blocks as a prefix, e.g., 
InnerBlock.varName or OtherScript.SomeBlock.varName
+   * contain the namespaces of the blocks as a prefix, e.g., 
InnerBlock.varName or
+   * OtherScript.SomeBlock.varName
    */
   public static final String PARAM_VAR_NAMES = "varNames";
 
@@ -486,7 +487,7 @@ public class RutaEngine extends JCasAnno
       varValues = (String[]) 
aContext.getConfigParameterValue(PARAM_VAR_VALUES);
       dictRemoveWS = (Boolean) 
aContext.getConfigParameterValue(PARAM_DICT_REMOVE_WS);
       dictRemoveWS = dictRemoveWS == null ? false : dictRemoveWS;
-      
+
       this.context = aContext;
 
       factory = new RutaExternalFactory();
@@ -524,7 +525,12 @@ public class RutaEngine extends JCasAnno
 
   @Override
   public void process(JCas jcas) throws AnalysisEngineProcessException {
+    
     CAS cas = jcas.getCas();
+    
+    // TODO: added logging method calls temporarily for UIMA-4568
+    logInfoForFirstBasic("begin of process", cas);
+    
     if (reloadScript || (!initialized && 
!cas.getViewName().equals(CAS.NAME_DEFAULT_SOFA))) {
       initializeScript(cas.getViewName());
     } else {
@@ -684,9 +690,38 @@ public class RutaEngine extends JCasAnno
             simpleGreedyForComposed, crowd);
 
     stream.initalizeBasics();
+    // TODO: added logging method calls temporarily for UIMA-4568
+    logInfoForFirstBasic("after initBasics", cas);
     return stream;
   }
 
+  private void logInfoForFirstBasic(String context, CAS cas) {
+    AnnotationIndex<AnnotationFS> index = 
cas.getAnnotationIndex(cas.getTypeSystem().getType(
+            BASIC_TYPE));
+    if (index.size() == 0) {
+      getLogger().info(context + " : "+ rules + " - no RutaBasic yet");
+    } else {
+      AnnotationFS next = index.iterator().next();
+      if (next instanceof RutaBasic) {
+        RutaBasic basic = (RutaBasic) next;
+        getLogger().info(context + " - first RutaBasic: "+ 
basic.getBegin()+"|"+basic.getEnd() + " addr:" + basic.getAddress());
+        Collection<?>[] beginMap = basic.getBeginMap();
+        int counter = 0;
+        for (Collection<?> collection : beginMap) {
+          if (collection != null) {
+            for (Object object : collection) {
+              if (object != null) {
+                counter++;
+              }
+            }
+          }
+        }
+
+        getLogger().info(context + " : "+ rules + " - size of beginMap: " + 
counter);
+      }
+    }
+  }
+
   private List<Type> seedAnnotations(CAS cas) throws 
AnalysisEngineProcessException {
     List<Type> result = new ArrayList<Type>();
     if (seeders != null) {
@@ -716,7 +751,7 @@ public class RutaEngine extends JCasAnno
 
   private void initializeScript(String viewName) throws 
AnalysisEngineProcessException {
     if (mainScript == null) {
-      if(rules != null) {
+      if (rules != null) {
         try {
           script = loadScriptByString(rules);
         } catch (RecognitionException e) {
@@ -849,7 +884,7 @@ public class RutaEngine extends JCasAnno
   }
 
   private void initializeVariableValues() {
-    if(varNames == null || varValues == null) {
+    if (varNames == null || varValues == null) {
       return;
     }
     if (varNames.length != varValues.length) {
@@ -860,7 +895,7 @@ public class RutaEngine extends JCasAnno
     for (int i = 0; i < varNames.length; i++) {
       String longName = varNames[i];
       String value = varValues[i];
-      
+
       int lastIndexOf = longName.lastIndexOf('.');
       String shortName = longName;
       String blockName = null;
@@ -869,10 +904,10 @@ public class RutaEngine extends JCasAnno
         shortName = longName.substring(lastIndexOf + 1, longName.length());
       }
       RutaBlock block = script.getBlock(blockName);
-      if(block == null) {
+      if (block == null) {
         return;
       }
-      
+
       RutaEnvironment environment = block.getEnvironment();
       if (!environment.ownsVariable(shortName)) {
         return;
@@ -1043,7 +1078,7 @@ public class RutaEngine extends JCasAnno
     RutaModule script = parser.file_input("Anonymous");
     return script;
   }
-  
+
   private RutaModule loadScript(String scriptLocation) throws IOException, 
RecognitionException {
     File scriptFile = new File(scriptLocation);
     CharStream st = new ANTLRFileStream(scriptLocation, scriptEncoding);

Modified: 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/StackedScriptsTest.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/StackedScriptsTest.java?rev=1697426&r1=1697425&r2=1697426&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/StackedScriptsTest.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/StackedScriptsTest.java
 Mon Aug 24 15:01:28 2015
@@ -31,6 +31,9 @@ import org.junit.Test;
 
 public class StackedScriptsTest {
 
+  private static final String DOC_TEXT = "This is a simple test.";
+  private static final int LINES = 1;
+
   @Test
   public void test() throws ResourceInitializationException, 
InvalidXMLException, IOException, AnalysisEngineProcessException {
     String rules1 = "CW{->T1};";
@@ -41,7 +44,12 @@ public class StackedScriptsTest {
     AnalysisEngine rutaAE2 = createEngine(RutaEngine.class, 
RutaEngine.PARAM_RULES, rules2);
     AnalysisEngine rutaAE3 = createEngine(RutaEngine.class, 
RutaEngine.PARAM_RULES, rules3);
 
-    CAS cas = RutaTestUtils.getCAS("This is a simple test.");
+    StringBuilder sb = new StringBuilder();
+    for (int i = 0; i < LINES; i++) {
+      sb.append(DOC_TEXT);
+      sb.append("\n");
+    }
+    CAS cas = RutaTestUtils.getCAS(sb.toString());
 
     rutaAE1.process(cas);
     rutaAE2.process(cas);
@@ -52,7 +60,7 @@ public class StackedScriptsTest {
     RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "a");
     RutaTestUtils.assertAnnotationsEquals(cas, 4, 3, "This", "is", "a");
     
-    
   }
+  
 
 }


Reply via email to