Author: pkluegl
Date: Fri Dec 21 14:35:35 2018
New Revision: 1849481

URL: http://svn.apache.org/viewvc?rev=1849481&view=rev
Log:
UIMA-5489: improved verbalization

Added:
    
uima/ruta/trunk/ruta-core-ext/src/test/java/org/apache/uima/ruta/string/bool/
    
uima/ruta/trunk/ruta-core-ext/src/test/java/org/apache/uima/ruta/string/bool/VerbalizerTest.java
Modified:
    
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/BooleanOperationsExtension.java
    
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/ContainsBooleanFunction.java
    
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EndsWithBooleanFunction.java
    
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EqualsBooleanFunction.java
    
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EqualsIgnoreCaseBooleanFunction.java
    
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/StartsWithBooleanFunction.java
    
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ActionVerbalizerTest.java

Modified: 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/BooleanOperationsExtension.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/BooleanOperationsExtension.java?rev=1849481&r1=1849480&r2=1849481&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/BooleanOperationsExtension.java
 (original)
+++ 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/BooleanOperationsExtension.java
 Fri Dec 21 14:35:35 2018
@@ -31,38 +31,39 @@ import org.apache.uima.ruta.verbalize.Ru
 
 public class BooleanOperationsExtension implements 
IRutaBooleanFunctionExtension {
 
-  private final String[] knownExtensions = new String[] { "contains", 
"endsWith",
-      "startsWith", "equals", "equalsIgnoreCase", "isEmpty" };
+  private final String[] knownExtensions = new String[] { "contains", 
"endsWith", "startsWith",
+      "equals", "equalsIgnoreCase", "isEmpty" };
 
   private final Class<?>[] extensions = new Class[] { 
ContainsBooleanFunction.class,
-      EndsWithBooleanFunction.class, StartsWithBooleanFunction.class,
-      EqualsBooleanFunction.class, EqualsIgnoreCaseBooleanFunction.class,
-      IsEmptyBooleanFunction.class };
+      EndsWithBooleanFunction.class, StartsWithBooleanFunction.class, 
EqualsBooleanFunction.class,
+      EqualsIgnoreCaseBooleanFunction.class, IsEmptyBooleanFunction.class };
 
-  
-  
+  @Override
   public String verbalize(RutaElement element, RutaVerbalizer verbalizer) {
     if (element instanceof ContainsBooleanFunction) {
       return verbalizeName(element) + "("
-              + verbalizer.verbalize(((ContainsBooleanFunction) 
element).getExpr()) + ")";
+              + verbalizer.verbalize(((ContainsBooleanFunction) 
element).getExpr()) + ","
+              + verbalizer.verbalize(((ContainsBooleanFunction) 
element).getContainsExpr()) + ")";
     } else if (element instanceof EndsWithBooleanFunction) {
       return verbalizeName(element) + "("
-              + verbalizer.verbalize(((EndsWithBooleanFunction) 
element).getExpr()) + ")";
-    }
-    //
-    else if (element instanceof StartsWithBooleanFunction) {
+              + verbalizer.verbalize(((EndsWithBooleanFunction) 
element).getExpr()) + ","
+              + verbalizer.verbalize(((EndsWithBooleanFunction) 
element).getEndExpr()) + ")";
+    } else if (element instanceof StartsWithBooleanFunction) {
       return verbalizeName(element) + "("
-              + verbalizer.verbalize(((StartsWithBooleanFunction) 
element).getExpr()) + ")";
+              + verbalizer.verbalize(((StartsWithBooleanFunction) 
element).getExpr()) + ","
+              + verbalizer.verbalize(((StartsWithBooleanFunction) 
element).getStartExpr()) + ")";
     } else if (element instanceof EqualsBooleanFunction) {
       return verbalizeName(element) + "("
-              + verbalizer.verbalize(((EqualsBooleanFunction) 
element).getExpr()) + ")";
+              + verbalizer.verbalize(((EqualsBooleanFunction) 
element).getExpr()) + ","
+              + verbalizer.verbalize(((EqualsBooleanFunction) 
element).getCompareExpr()) + ")";
     } else if (element instanceof EqualsIgnoreCaseBooleanFunction) {
       return verbalizeName(element) + "("
-              + verbalizer.verbalize(((EqualsIgnoreCaseBooleanFunction) 
element).getExpr()) + ")";
+              + verbalizer.verbalize(((EqualsIgnoreCaseBooleanFunction) 
element).getExpr()) + ","
+              + verbalizer.verbalize(((EqualsIgnoreCaseBooleanFunction) 
element).getCompareExpr())
+              + ")";
     } else if (element instanceof IsEmptyBooleanFunction) {
       return verbalizeName(element) + "("
-              + verbalizer.verbalize(((IsEmptyBooleanFunction) 
element).getExpr())
-              + ")";
+              + verbalizer.verbalize(((IsEmptyBooleanFunction) 
element).getExpr()) + ")";
     }
     //
     else {
@@ -70,46 +71,44 @@ public class BooleanOperationsExtension
     }
   }
 
-
+  @Override
   public String verbalizeName(RutaElement element) {
-    
-     if (element instanceof ContainsBooleanFunction) {
+
+    if (element instanceof ContainsBooleanFunction) {
       return knownExtensions[0];
     }
-     
-     else if (element instanceof EndsWithBooleanFunction) {
+
+    else if (element instanceof EndsWithBooleanFunction) {
       return knownExtensions[1];
     }
 
-    
     else if (element instanceof StartsWithBooleanFunction) {
       return knownExtensions[2];
     }
-    
+
     else if (element instanceof EqualsBooleanFunction) {
       return knownExtensions[3];
     }
-    
+
     else if (element instanceof EqualsIgnoreCaseBooleanFunction) {
       return knownExtensions[4];
     }
-    
+
     else if (element instanceof IsEmptyBooleanFunction) {
       return knownExtensions[5];
     }
-    
 
-    
-    
     else {
       return "UnknownStringFunction";
     }
   }
 
+  @Override
   public String[] getKnownExtensions() {
     return knownExtensions;
   }
 
+  @Override
   public Class<?>[] extensions() {
     return extensions;
   }
@@ -117,41 +116,44 @@ public class BooleanOperationsExtension
   @Override
   public BooleanFunctionExpression createBooleanFunction(String name, 
List<RutaExpression> args)
           throws RutaParseException {
-    if(args ==null ){
-      throw new RutaParseException("You have to specify at least 1 Argument to 
use these Functions !");
+    if (args == null) {
+      throw new RutaParseException(
+              "You have to specify at least 1 Argument to use these Functions 
!");
     }
-    
+
     if (name.equals(knownExtensions[5])) {
       return new IsEmptyBooleanFunction((IStringExpression) args.get(0));
     }
-    
-    if (args == null || args.size()<2) {
-      throw new RutaParseException("You have to specify at least 2 Arguments 
to use these Functions !");
+
+    if (args == null || args.size() < 2) {
+      throw new RutaParseException(
+              "You have to specify at least 2 Arguments to use these Functions 
!");
     }
 
     if (name.equals(knownExtensions[0])) {
-      return new ContainsBooleanFunction((IStringExpression) args.get(0), 
(IStringExpression) args.get(1));
+      return new ContainsBooleanFunction((IStringExpression) args.get(0),
+              (IStringExpression) args.get(1));
     }
 
     else if (name.equals(knownExtensions[1])) {
-      return new EndsWithBooleanFunction((IStringExpression) 
args.get(0),(IStringExpression) args.get(1));
+      return new EndsWithBooleanFunction((IStringExpression) args.get(0),
+              (IStringExpression) args.get(1));
     }
 
     else if (name.equals(knownExtensions[2])) {
-      return new StartsWithBooleanFunction((IStringExpression) 
args.get(0),(IStringExpression) args.get(1));
+      return new StartsWithBooleanFunction((IStringExpression) args.get(0),
+              (IStringExpression) args.get(1));
     }
-    
-     if (name.equals(knownExtensions[3])) {
-      return new EqualsBooleanFunction((IStringExpression) 
args.get(0),(IStringExpression) args.get(1));
-    }
-    else if (name.equals(knownExtensions[4])) {
-      return new EqualsIgnoreCaseBooleanFunction((IStringExpression) 
args.get(0),(IStringExpression) args.get(1));
+
+    if (name.equals(knownExtensions[3])) {
+      return new EqualsBooleanFunction((IStringExpression) args.get(0),
+              (IStringExpression) args.get(1));
+    } else if (name.equals(knownExtensions[4])) {
+      return new EqualsIgnoreCaseBooleanFunction((IStringExpression) 
args.get(0),
+              (IStringExpression) args.get(1));
     }
-     
-    
+
     return null;
   }
 
-
-
 }

Modified: 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/ContainsBooleanFunction.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/ContainsBooleanFunction.java?rev=1849481&r1=1849480&r2=1849481&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/ContainsBooleanFunction.java
 (original)
+++ 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/ContainsBooleanFunction.java
 Fri Dec 21 14:35:35 2018
@@ -17,7 +17,6 @@
  * under the License.
  */
 
-
 package org.apache.uima.ruta.string.bool;
 
 import org.apache.uima.ruta.RutaStream;
@@ -26,29 +25,34 @@ import org.apache.uima.ruta.expression.s
 import org.apache.uima.ruta.rule.MatchContext;
 
 public class ContainsBooleanFunction extends BooleanFunctionExpression {
-  
+
   private IStringExpression text;
+
   private IStringExpression contains;
-  
-  public ContainsBooleanFunction(IStringExpression text,
-          IStringExpression contains) {
+
+  public ContainsBooleanFunction(IStringExpression text, IStringExpression 
contains) {
     this.text = text;
-    this.contains =contains;
+    this.contains = contains;
   }
 
   public IStringExpression getExpr() {
     return text;
   }
 
+  public IStringExpression getContainsExpr() {
+    return contains;
+  }
+
   @Override
   public boolean getBooleanValue(MatchContext context, RutaStream stream) {
-    
-return text.getStringValue(context, 
stream).contains(contains.getStringValue(context, stream));
+
+    return text.getStringValue(context, 
stream).contains(contains.getStringValue(context, stream));
   }
 
   @Override
   public String getStringValue(MatchContext context, RutaStream stream) {
-    Boolean isContained = text.getStringValue(context, 
stream).contains(contains.getStringValue(context, stream)); 
+    Boolean isContained = text.getStringValue(context, stream)
+            .contains(contains.getStringValue(context, stream));
     return isContained.toString();
   }
 

Modified: 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EndsWithBooleanFunction.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EndsWithBooleanFunction.java?rev=1849481&r1=1849480&r2=1849481&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EndsWithBooleanFunction.java
 (original)
+++ 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EndsWithBooleanFunction.java
 Fri Dec 21 14:35:35 2018
@@ -17,7 +17,6 @@
  * under the License.
  */
 
-
 package org.apache.uima.ruta.string.bool;
 
 import org.apache.uima.ruta.RutaStream;
@@ -27,19 +26,23 @@ import org.apache.uima.ruta.rule.MatchCo
 
 public class EndsWithBooleanFunction extends BooleanFunctionExpression {
   private IStringExpression text;
+
   private IStringExpression end;
-  
-  public EndsWithBooleanFunction(IStringExpression text,
-          IStringExpression end) {
+
+  public EndsWithBooleanFunction(IStringExpression text, IStringExpression 
end) {
     this.text = text;
     this.end = end;
-    
+
   }
 
   public IStringExpression getExpr() {
     return text;
   }
 
+  public IStringExpression getEndExpr() {
+    return end;
+  }
+
   @Override
   public boolean getBooleanValue(MatchContext context, RutaStream stream) {
     return text.getStringValue(context, 
stream).endsWith(end.getStringValue(context, stream));
@@ -47,7 +50,8 @@ public class EndsWithBooleanFunction ext
 
   @Override
   public String getStringValue(MatchContext context, RutaStream stream) {
-    Boolean endsWith = text.getStringValue(context, 
stream).endsWith(end.getStringValue(context, stream)); 
+    Boolean endsWith = text.getStringValue(context, stream)
+            .endsWith(end.getStringValue(context, stream));
     return endsWith.toString();
   }
 }

Modified: 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EqualsBooleanFunction.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EqualsBooleanFunction.java?rev=1849481&r1=1849480&r2=1849481&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EqualsBooleanFunction.java
 (original)
+++ 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EqualsBooleanFunction.java
 Fri Dec 21 14:35:35 2018
@@ -17,7 +17,6 @@
  * under the License.
  */
 
-
 package org.apache.uima.ruta.string.bool;
 
 import org.apache.uima.ruta.RutaStream;
@@ -26,13 +25,12 @@ import org.apache.uima.ruta.expression.s
 import org.apache.uima.ruta.rule.MatchContext;
 
 public class EqualsBooleanFunction extends BooleanFunctionExpression {
-  
+
   private IStringExpression text;
+
   private IStringExpression compare;
-  
-  
-  public EqualsBooleanFunction(IStringExpression text,
-          IStringExpression compare) {
+
+  public EqualsBooleanFunction(IStringExpression text, IStringExpression 
compare) {
     this.text = text;
     this.compare = compare;
   }
@@ -41,6 +39,10 @@ public class EqualsBooleanFunction exten
     return text;
   }
 
+  public IStringExpression getCompareExpr() {
+    return compare;
+  }
+
   @Override
   public boolean getBooleanValue(MatchContext context, RutaStream stream) {
     return text.getStringValue(context, 
stream).equals(compare.getStringValue(context, stream));
@@ -48,7 +50,8 @@ public class EqualsBooleanFunction exten
 
   @Override
   public String getStringValue(MatchContext context, RutaStream stream) {
-    Boolean equals = text.getStringValue(context, 
stream).equals(compare.getStringValue(context, stream)); 
+    Boolean equals = text.getStringValue(context, stream)
+            .equals(compare.getStringValue(context, stream));
     return equals.toString();
   }
 }

Modified: 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EqualsIgnoreCaseBooleanFunction.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EqualsIgnoreCaseBooleanFunction.java?rev=1849481&r1=1849480&r2=1849481&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EqualsIgnoreCaseBooleanFunction.java
 (original)
+++ 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/EqualsIgnoreCaseBooleanFunction.java
 Fri Dec 21 14:35:35 2018
@@ -25,13 +25,12 @@ import org.apache.uima.ruta.expression.s
 import org.apache.uima.ruta.rule.MatchContext;
 
 public class EqualsIgnoreCaseBooleanFunction extends BooleanFunctionExpression 
{
-  
+
   private IStringExpression text;
+
   private IStringExpression compare;
-  
-  
-  public EqualsIgnoreCaseBooleanFunction(IStringExpression text,
-          IStringExpression compare) {
+
+  public EqualsIgnoreCaseBooleanFunction(IStringExpression text, 
IStringExpression compare) {
     this.text = text;
     this.compare = compare;
   }
@@ -40,14 +39,20 @@ public class EqualsIgnoreCaseBooleanFunc
     return text;
   }
 
+  public IStringExpression getCompareExpr() {
+    return compare;
+  }
+
   @Override
   public boolean getBooleanValue(MatchContext context, RutaStream stream) {
-    return text.getStringValue(context, 
stream).equalsIgnoreCase(compare.getStringValue(context, stream));
+    return text.getStringValue(context, stream)
+            .equalsIgnoreCase(compare.getStringValue(context, stream));
   }
 
   @Override
   public String getStringValue(MatchContext context, RutaStream stream) {
-    Boolean equals = text.getStringValue(context, 
stream).equalsIgnoreCase(compare.getStringValue(context, stream)); 
+    Boolean equals = text.getStringValue(context, stream)
+            .equalsIgnoreCase(compare.getStringValue(context, stream));
     return equals.toString();
   }
 }

Modified: 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/StartsWithBooleanFunction.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/StartsWithBooleanFunction.java?rev=1849481&r1=1849480&r2=1849481&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/StartsWithBooleanFunction.java
 (original)
+++ 
uima/ruta/trunk/ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/StartsWithBooleanFunction.java
 Fri Dec 21 14:35:35 2018
@@ -40,16 +40,19 @@ public class StartsWithBooleanFunction e
     return text;
   }
 
+  public IStringExpression getStartExpr() {
+    return start;
+  }
+
   @Override
   public boolean getBooleanValue(MatchContext context, RutaStream stream) {
-    return text.getStringValue(context, stream).startsWith(
-            start.getStringValue(context, stream));
+    return text.getStringValue(context, 
stream).startsWith(start.getStringValue(context, stream));
   }
 
   @Override
   public String getStringValue(MatchContext context, RutaStream stream) {
-    Boolean endsWith = text.getStringValue(context, stream).startsWith(
-            start.getStringValue(context, stream));
+    Boolean endsWith = text.getStringValue(context, stream)
+            .startsWith(start.getStringValue(context, stream));
     return endsWith.toString();
   }
 }

Added: 
uima/ruta/trunk/ruta-core-ext/src/test/java/org/apache/uima/ruta/string/bool/VerbalizerTest.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core-ext/src/test/java/org/apache/uima/ruta/string/bool/VerbalizerTest.java?rev=1849481&view=auto
==============================================================================
--- 
uima/ruta/trunk/ruta-core-ext/src/test/java/org/apache/uima/ruta/string/bool/VerbalizerTest.java
 (added)
+++ 
uima/ruta/trunk/ruta-core-ext/src/test/java/org/apache/uima/ruta/string/bool/VerbalizerTest.java
 Fri Dec 21 14:35:35 2018
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.string.bool;
+
+import org.apache.uima.ruta.expression.string.SimpleStringExpression;
+import org.apache.uima.ruta.verbalize.RutaVerbalizer;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class VerbalizerTest {
+
+  @Test
+  public void test() {
+    ContainsBooleanFunction f = new ContainsBooleanFunction(new 
SimpleStringExpression("abc"),
+            new SimpleStringExpression("def"));
+
+    BooleanOperationsExtension extension = new BooleanOperationsExtension();
+    String verbalize = extension.verbalize(f, new RutaVerbalizer());
+
+    Assert.assertEquals("contains(\"abc\",\"def\")", verbalize);
+  }
+}

Modified: 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ActionVerbalizerTest.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ActionVerbalizerTest.java?rev=1849481&r1=1849480&r2=1849481&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ActionVerbalizerTest.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ActionVerbalizerTest.java
 Fri Dec 21 14:35:35 2018
@@ -247,6 +247,10 @@ public class ActionVerbalizerTest {
     s = v.verbalize(a);
     assertEquals("MATCHEDTEXT(anyVar, 4, numVar)", s);
 
+    a = new MatchedTextAction(var, null);
+    s = v.verbalize(a);
+    assertEquals("MATCHEDTEXT(anyVar)", s);
+
     // MERGE
     a = new MergeAction(boolExpr1, var, listExprList);
     s = v.verbalize(a);


Reply via email to