Author: pkluegl
Date: Wed Dec 12 14:44:41 2018
New Revision: 1848768

URL: http://svn.apache.org/viewvc?rev=1848768&view=rev
Log:
UIMA-5888: fixed reset, added test

Modified:
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
    
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationVariableExpressionTest.java

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java?rev=1848768&r1=1848767&r2=1848768&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
 Wed Dec 12 14:44:41 2018
@@ -993,8 +993,9 @@ public class RutaEnvironment {
                Set<Entry<String, Object>> entrySet = variableValues.entrySet();
                for (Entry<String, Object> entry : entrySet) {
                        String key = entry.getKey();
+                       Class<?> variableType = variableTypes.get(key);
                        Object initialValue = getInitialValue(key, 
variableTypes.get(key));
-                       if (initialValue != null) {
+                       if ((!variableType.equals(RutaTable.class) && 
!variableType.equals(RutaWordList.class) ) || initialValue != null) {
                                // not for word lists
                                entry.setValue(initialValue);
                        }

Modified: 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationVariableExpressionTest.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationVariableExpressionTest.java?rev=1848768&r1=1848767&r2=1848768&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationVariableExpressionTest.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationVariableExpressionTest.java
 Wed Dec 12 14:44:41 2018
@@ -22,21 +22,31 @@ package org.apache.uima.ruta.expression.
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import java.io.IOException;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.FSIterator;
 import org.apache.uima.cas.Feature;
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.fit.factory.AnalysisEngineFactory;
 import org.apache.uima.jcas.cas.FSArray;
+import org.apache.uima.resource.ResourceConfigurationException;
+import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.ruta.engine.Ruta;
+import org.apache.uima.ruta.engine.RutaEngine;
 import org.apache.uima.ruta.engine.RutaTestUtils;
 import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature;
+import org.apache.uima.util.InvalidXMLException;
 import org.junit.Test;
 
 public class AnnotationVariableExpressionTest {
@@ -224,4 +234,44 @@ public class AnnotationVariableExpressio
     assertNotNull("Feature value is null!", array);
     assertEquals(2, array.size());
   }
+  
+  
+  @Test
+  public void testResetVariableBetweenCases() throws 
ResourceInitializationException, InvalidXMLException, IOException, 
AnalysisEngineProcessException, ResourceConfigurationException, 
URISyntaxException {
+    
+       String document = "Some text.";
+    String script = "ANNOTATIONLIST as;\n";
+    script += "ANNOTATION a;\n";
+    script += "WORDLIST wl = 
'org/apache/uima/ruta/WSDictionaryTestList.txt';\n";
+    script += "WORDTABLE wt = 'org/apache/uima/ruta/table2.csv';\n";
+    script += "a{-> T1};\n";
+    script += "as{-> T2};\n";
+    script += "Document{-> a = CW};\n";
+    script += "Document{-> as = W};\n";
+    script += "a{-> T3};\n";
+    script += "as{-> T4};";
+
+    AnalysisEngineDescription description = 
AnalysisEngineFactory.createEngineDescription(RutaEngine.class, 
RutaEngine.PARAM_RULES, script);
+    AnalysisEngine engine = AnalysisEngineFactory.createEngine(description);
+    
+    CAS cas =  RutaTestUtils.getCAS(document);
+    
+    cas.reset();
+    cas.setDocumentText(document);
+    engine.process(cas);
+    RutaTestUtils.assertAnnotationsEquals(cas, 1, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 2, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "Some");
+    RutaTestUtils.assertAnnotationsEquals(cas, 4, 2, "Some", "text");
+    
+    cas.reset();
+    cas.setDocumentText(document);
+    engine.process(cas);
+    RutaTestUtils.assertAnnotationsEquals(cas, 1, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 2, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "Some");
+    RutaTestUtils.assertAnnotationsEquals(cas, 4, 2, "Some", "text");
+
+  }
+  
 }


Reply via email to