Author: pkluegl
Date: Fri Dec 28 15:29:06 2018
New Revision: 1849866

URL: http://svn.apache.org/viewvc?rev=1849866&view=rev
Log:
UIMA-5481: null is now the initial default for strings in ruta

Modified:
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ExecAction.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanStringExpression.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/ComposedStringExpression.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java
    
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition2Test.java
    
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.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=1849866&r1=1849865&r2=1849866&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
 Fri Dec 28 15:29:06 2018
@@ -756,7 +756,7 @@ public class RutaEnvironment {
     } else if (Float.class.equals(type)) {
       return 0f;
     } else if (String.class.equals(type)) {
-      return "";
+      return null;
     } else if (Boolean.class.equals(type)) {
       return false;
     } else if (Type.class.equals(type)) {

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ExecAction.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ExecAction.java?rev=1849866&r1=1849865&r2=1849866&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ExecAction.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ExecAction.java
 Fri Dec 28 15:29:06 2018
@@ -75,7 +75,7 @@ public class ExecAction extends CallActi
     CAS cas = stream.getCas();
     if (view != null) {
       String viewName = view.getStringValue(context, stream);
-      if (!viewName.equals(CAS.NAME_DEFAULT_SOFA)) {
+      if (viewName != null && !viewName.equals(CAS.NAME_DEFAULT_SOFA)) {
         cas = cas.getView(viewName);
         AnalysisEngineMetaData metaData = 
targetEngine.getAnalysisEngineMetaData();
         try {

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java?rev=1849866&r1=1849865&r2=1849866&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java
 Fri Dec 28 15:29:06 2018
@@ -61,6 +61,11 @@ public class RegExpCondition extends Ter
     Matcher matcher = null;
     boolean ignore = ignoreCase == null ? false : 
ignoreCase.getBooleanValue(context, stream);
     String stringValue = pattern.getStringValue(context, stream);
+
+    if (stringValue == null) {
+      return new EvaluatedCondition(this, false);
+    }
+
     if (variable == null) {
       String coveredText = annotation.getCoveredText();
       Pattern regularExpPattern = null;

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanStringExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanStringExpression.java?rev=1849866&r1=1849865&r2=1849866&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanStringExpression.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanStringExpression.java
 Fri Dec 28 15:29:06 2018
@@ -47,8 +47,14 @@ public class BooleanStringExpression ext
 
   private boolean eval(String t1, String op, String t2) {
     if ("==".equals(op)) {
+      if (t1 == null) {
+        return t2 == null;
+      }
       return t1.equals(t2);
     } else if ("!=".equals(op)) {
+      if (t1 == null) {
+        return t2 != null;
+      }
       return !t1.equals(t2);
     }
     return false;

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/ComposedStringExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/ComposedStringExpression.java?rev=1849866&r1=1849865&r2=1849866&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/ComposedStringExpression.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/ComposedStringExpression.java
 Fri Dec 28 15:29:06 2018
@@ -26,15 +26,22 @@ import org.apache.uima.ruta.rule.MatchCo
 
 public class ComposedStringExpression extends LiteralStringExpression {
 
-  private final List<IStringExpression> epxressions;
+  private final List<IStringExpression> expressions;
 
   public ComposedStringExpression(List<IStringExpression> expressions) {
     super();
-    this.epxressions = expressions;
+    this.expressions = expressions;
   }
 
   @Override
   public String getStringValue(MatchContext context, RutaStream stream) {
+    if (expressions == null) {
+      return null;
+    }
+    if (expressions.size() == 1) {
+      IStringExpression stringExpression = expressions.get(0);
+      return stringExpression.getStringValue(context, stream);
+    }
     StringBuilder result = new StringBuilder();
     for (IStringExpression each : getExpressions()) {
       result.append(each.getStringValue(context, stream));
@@ -43,7 +50,7 @@ public class ComposedStringExpression ex
   }
 
   public List<IStringExpression> getExpressions() {
-    return epxressions;
+    return expressions;
   }
 
 }

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java?rev=1849866&r1=1849865&r2=1849866&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java
 Fri Dec 28 15:29:06 2018
@@ -44,9 +44,11 @@ public class RemoveFunction extends Stri
     String value = parent.getEnvironment().getVariableValue(var, String.class, 
stream);
     for (IStringExpression each : list) {
       String string = each.getStringValue(context, stream);
-      String[] split = value.split(string);
-      for (String r : split) {
-        result.append(r);
+      if (string != null) {
+        String[] split = value.split(string);
+        for (String r : split) {
+          result.append(r);
+        }
       }
     }
     return result.toString();

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java?rev=1849866&r1=1849865&r2=1849866&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java
 Fri Dec 28 15:29:06 2018
@@ -72,6 +72,12 @@ public class RegExpRule extends Abstract
     crowd.beginVisit(this, ruleApply);
     MatchContext context = new MatchContext(getParent());
     String regexpString = regexpExpr.getStringValue(context, stream);
+
+    if (regexpString == null) {
+      crowd.endVisit(this, ruleApply);
+      return ruleApply;
+    }
+
     AnnotationFS documentAnnotation = stream.getDocumentAnnotation();
     String document = documentAnnotation.getCoveredText();
     int delta = documentAnnotation.getBegin();

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java?rev=1849866&r1=1849865&r2=1849866&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java
 Fri Dec 28 15:29:06 2018
@@ -92,7 +92,7 @@ public class RutaLiteralMatcher implemen
     MatchContext context = new MatchContext(annotation, null, null, !before);
     context.setParent(parent);
     String stringValue = expression.getStringValue(context, stream);
-    if (stringValue.equals(basicNextTo.getCoveredText())) {
+    if (stringValue != null && 
stringValue.equals(basicNextTo.getCoveredText())) {
       result.add(basicNextTo);
     }
     return result;

Modified: 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition2Test.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition2Test.java?rev=1849866&r1=1849865&r2=1849866&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition2Test.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition2Test.java
 Fri Dec 28 15:29:06 2018
@@ -54,15 +54,17 @@ public class ImplicitCondition2Test {
     RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "Peter", "Kluegl", 
"Joern");
     RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "Peter", "Kluegl");
     RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "Peter");
-    RutaTestUtils.assertAnnotationsEquals(cas, 4, 5, "Kluegl", "Joern", 
"Kottmann", "Marshall", "Schor");
+    RutaTestUtils.assertAnnotationsEquals(cas, 4, 5, "Kluegl", "Joern", 
"Kottmann", "Marshall",
+            "Schor");
     RutaTestUtils.assertAnnotationsEquals(cas, 5, 3, "Kottmann", "Marshall", 
"Schor");
     RutaTestUtils.assertAnnotationsEquals(cas, 6, 2, "Marshall", "Schor");
 
     cas.release();
   }
-  
+
   @Test
-  public void testStringCompare() throws ResourceInitializationException, 
InvalidXMLException, IOException, AnalysisEngineProcessException, CASException {
+  public void testStringCompare() throws ResourceInitializationException, 
InvalidXMLException,
+          IOException, AnalysisEngineProcessException, CASException {
     String document = "a b. a b.";
     CAS cas = RutaTestUtils.getCAS(document);
     Assert.assertTrue(Ruta.matches(cas.getJCas(), "(w:W # 
W{W.ct==w.ct}){->T1};"));
@@ -70,21 +72,21 @@ public class ImplicitCondition2Test {
     RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "a b. a", "b. a b");
     RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "a b", "a b");
   }
-  
+
   @Test
-  public void testStringCompareNull() throws ResourceInitializationException, 
InvalidXMLException, IOException, AnalysisEngineProcessException, CASException {
+  public void testStringCompareNull() throws ResourceInitializationException, 
InvalidXMLException,
+          IOException, AnalysisEngineProcessException, CASException {
     String document = "a b. a b.";
     CAS cas = RutaTestUtils.getCAS(document);
-    
+
     String rules = "STRING s2;\n";
     rules += "Document{s2 == \"\" -> T10};\n";
     rules += "Document{s2 == null -> T11};\n";
     Assert.assertTrue(Ruta.matches(cas.getJCas(), rules));
-    
-    RutaTestUtils.assertAnnotationsEquals(cas, 10, 1, document);
-    RutaTestUtils.assertAnnotationsEquals(cas, 11, 0);
-    
+
+    RutaTestUtils.assertAnnotationsEquals(cas, 10, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 11, 1, document);
+
   }
-  
-  
+
 }

Modified: 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java?rev=1849866&r1=1849865&r2=1849866&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java
 Fri Dec 28 15:29:06 2018
@@ -52,25 +52,27 @@ public class ThreeStackedScriptsVariable
     RutaBuildOptions options = new RutaBuildOptions();
     RutaDescriptorInformation rdi = factory
             .parseDescriptorInformation(new File(path + "script1.ruta"), 
options);
-    Pair<AnalysisEngineDescription, TypeSystemDescription> descriptions = 
factory.createDescriptions(null, Paths.get(path).toFile().getAbsolutePath(), 
rdi, options, new String[] { path }, new String[] { path }, null);
+    Pair<AnalysisEngineDescription, TypeSystemDescription> descriptions = 
factory
+            .createDescriptions(null, 
Paths.get(path).toFile().getAbsolutePath(), rdi, options,
+                    new String[] { path }, new String[] { path }, null);
 
     AnalysisEngine ae = 
UIMAFramework.produceAnalysisEngine(descriptions.getKey());
     JCas jcas = JCasFactory.createJCas(descriptions.getValue());
-    
+
     jcas.setDocumentText(input1);
     ae.process(jcas);
     checkFeatureValue(jcas);
-    
+
     jcas.reset();
     jcas.setDocumentText(input2);
     ae.process(jcas);
     checkFeatureValue(jcas);
-    
+
     jcas.reset();
     jcas.setDocumentText(input3);
     ae.process(jcas);
     checkFeatureValue(jcas);
-    
+
   }
 
   private void checkFeatureValue(JCas jcas) {
@@ -79,7 +81,7 @@ public class ThreeStackedScriptsVariable
     Feature feature = type.getFeatureByBaseName("value");
     FeatureStructure fs = CasUtil.selectSingle(cas, type);
     String stringValue = fs.getStringValue(feature);
-    Assert.assertEquals("", stringValue);
+    Assert.assertNull(stringValue);
   }
 
 }


Reply via email to