Author: pkluegl
Date: Fri Dec 28 23:33:50 2018
New Revision: 1849894

URL: http://svn.apache.org/viewvc?rev=1849894&view=rev
Log:
UIMA-5771: added new expressions for boolean comparison of annotations, support 
in feature match expressions, added test

Added:
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationExpression.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationListExpression.java
Modified:
    
uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureMatchExpression.java
    
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpressionTest.java
    
uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
    
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/ExpressionFactory.java

Modified: 
uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g?rev=1849894&r1=1849893&r2=1849894&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
 Fri Dec 28 23:33:50 2018
@@ -2783,6 +2783,8 @@ composedBooleanExpression returns [IBool
        (e2 = booleanCompare)=> e2 = booleanCompare {expr = e2;}
        | (bne = booleanNumberExpression)=> bne = booleanNumberExpression{expr 
= bne;}
        | (bse = booleanStringExpression)=> bse = booleanStringExpression{expr 
= bse;}
+       | (bale = booleanAnnotationListExpression)=> bale = 
booleanAnnotationListExpression{expr = bale;}
+       | (bae = booleanAnnotationExpression)=> bae = 
booleanAnnotationExpression{expr = bae;}
        | (bte = booleanTypeExpression)=> bte = booleanTypeExpression{expr = 
bte;}
        | e1 = booleanFunction {expr = e1;}
        | LPAREN ep = booleanExpression RPAREN {expr = ep;}
@@ -2831,6 +2833,23 @@ booleanTypeExpression  returns  [IBoolea
        e2 = typeExpression
        {expr = expressionFactory.createBooleanTypeExpression(e1,op,e2);}
        ;
+
+booleanAnnotationExpression  returns  [IBooleanExpression expr = null]
+       :
+       e1 = annotationExpression
+       op = (EQUAL | NOTEQUAL)
+       e2 = annotationExpression
+       {expr = expressionFactory.createBooleanAnnotationExpression(e1,op,e2);}
+       ;
+
+booleanAnnotationListExpression  returns  [IBooleanExpression expr = null]
+       :
+       e1 = annotationListExpression
+       op = (EQUAL | NOTEQUAL)
+       e2 = annotationListExpression
+       {expr = 
expressionFactory.createBooleanAnnotationListExpression(e1,op,e2);}
+       ;
+       
 booleanStringExpression  returns  [IBooleanExpression expr = null]
        :
        e1 = stringExpression

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java?rev=1849894&r1=1849893&r2=1849894&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java
 Fri Dec 28 23:33:50 2018
@@ -38,6 +38,8 @@ import org.apache.uima.ruta.expression.a
 import org.apache.uima.ruta.expression.annotation.IAnnotationExpression;
 import org.apache.uima.ruta.expression.annotation.IAnnotationListExpression;
 import org.apache.uima.ruta.expression.bool.AbstractBooleanListExpression;
+import org.apache.uima.ruta.expression.bool.BooleanAnnotationExpression;
+import org.apache.uima.ruta.expression.bool.BooleanAnnotationListExpression;
 import org.apache.uima.ruta.expression.bool.BooleanFeatureExpression;
 import org.apache.uima.ruta.expression.bool.BooleanListFeatureExpression;
 import org.apache.uima.ruta.expression.bool.BooleanListVariableExpression;
@@ -248,6 +250,18 @@ public class ExpressionFactory {
     return new BooleanTypeExpression(e1, op.getText(), e2);
   }
 
+  public IBooleanExpression createBooleanAnnotationExpression(IRutaExpression 
e1, Token op,
+          IRutaExpression e2) {
+    return new BooleanAnnotationExpression((IAnnotationExpression) e1, 
op.getText(),
+            (IAnnotationExpression) e2);
+  }
+
+  public IBooleanExpression 
createBooleanAnnotationListExpression(IRutaExpression e1, Token op,
+          IRutaExpression e2) {
+    return new BooleanAnnotationListExpression((IAnnotationListExpression) e1, 
op.getText(),
+            (IAnnotationListExpression) e2);
+  }
+
   public AbstractBooleanListExpression 
createReferenceBooleanListExpression(Token var) {
     return new BooleanListVariableExpression(var.getText());
   }
@@ -304,12 +318,11 @@ public class ExpressionFactory {
   public MatchReference createMatchReference(Token refToken) {
     return createMatchReference(refToken, null, null);
   }
-  
+
   public MatchReference createMatchReference(String reference) {
     return createMatchReference(reference, null, null);
   }
-  
-  
+
   public MatchReference createMatchReference(Token matchToken, Token 
comparatorToken,
           IRutaExpression argument) {
     String match = matchToken.getText();
@@ -319,7 +332,7 @@ public class ExpressionFactory {
     }
     return createMatchReference(match, comparator, argument);
   }
-  
+
   public MatchReference createMatchReference(String matchString, String 
comparatorString,
           IRutaExpression argument) {
     if (typeUsage != null) {

Added: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationExpression.java?rev=1849894&view=auto
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationExpression.java
 (added)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationExpression.java
 Fri Dec 28 23:33:50 2018
@@ -0,0 +1,82 @@
+/*
+ * 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.expression.bool;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.expression.annotation.IAnnotationExpression;
+import org.apache.uima.ruta.rule.MatchContext;
+
+public class BooleanAnnotationExpression extends AbstractBooleanExpression {
+
+  private final IAnnotationExpression e1;
+
+  private final String op;
+
+  private final IAnnotationExpression e2;
+
+  public BooleanAnnotationExpression(IAnnotationExpression e1, String op,
+          IAnnotationExpression e2) {
+    super();
+    this.e1 = e1;
+    this.op = op;
+    this.e2 = e2;
+  }
+
+  @Override
+  public boolean getBooleanValue(MatchContext context, RutaStream stream) {
+    AnnotationFS first = getFristExpression().getAnnotation(context, stream);
+    AnnotationFS second = getSecondExpression().getAnnotation(context, stream);
+    return eval(first, getOperator(), second);
+  }
+
+  private boolean eval(AnnotationFS t1, String op, AnnotationFS 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;
+  }
+
+  public IAnnotationExpression getFristExpression() {
+    return e1;
+  }
+
+  public String getOperator() {
+    return op;
+  }
+
+  public IAnnotationExpression getSecondExpression() {
+    return e2;
+  }
+
+  @Override
+  public String getStringValue(MatchContext context, RutaStream stream) {
+    return e1.getStringValue(context, stream) + " " + op + " " + 
e2.getStringValue(context, stream);
+  }
+
+}

Added: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationListExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationListExpression.java?rev=1849894&view=auto
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationListExpression.java
 (added)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationListExpression.java
 Fri Dec 28 23:33:50 2018
@@ -0,0 +1,84 @@
+/*
+ * 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.expression.bool;
+
+import java.util.List;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.expression.annotation.IAnnotationListExpression;
+import org.apache.uima.ruta.rule.MatchContext;
+
+public class BooleanAnnotationListExpression extends AbstractBooleanExpression 
{
+
+  private final IAnnotationListExpression e1;
+
+  private final String op;
+
+  private final IAnnotationListExpression e2;
+
+  public BooleanAnnotationListExpression(IAnnotationListExpression e1, String 
op,
+          IAnnotationListExpression e2) {
+    super();
+    this.e1 = e1;
+    this.op = op;
+    this.e2 = e2;
+  }
+
+  @Override
+  public boolean getBooleanValue(MatchContext context, RutaStream stream) {
+    List<AnnotationFS> first = getFristExpression().getAnnotationList(context, 
stream);
+    List<AnnotationFS> second = 
getSecondExpression().getAnnotationList(context, stream);
+    return eval(first, getOperator(), second);
+  }
+
+  private boolean eval(List<AnnotationFS> t1, String op, List<AnnotationFS> 
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;
+  }
+
+  public IAnnotationListExpression getFristExpression() {
+    return e1;
+  }
+
+  public String getOperator() {
+    return op;
+  }
+
+  public IAnnotationListExpression getSecondExpression() {
+    return e2;
+  }
+
+  @Override
+  public String getStringValue(MatchContext context, RutaStream stream) {
+    return e1.getStringValue(context, stream) + " " + op + " " + 
e2.getStringValue(context, stream);
+  }
+
+}

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureMatchExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureMatchExpression.java?rev=1849894&r1=1849893&r2=1849894&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureMatchExpression.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureMatchExpression.java
 Fri Dec 28 23:33:50 2018
@@ -21,9 +21,11 @@ package org.apache.uima.ruta.expression.
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.uima.cas.ArrayFS;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.Feature;
 import org.apache.uima.cas.FeatureStructure;
@@ -34,6 +36,8 @@ import org.apache.uima.ruta.RutaStream;
 import org.apache.uima.ruta.expression.IRutaExpression;
 import org.apache.uima.ruta.expression.MatchReference;
 import org.apache.uima.ruta.expression.RutaExpression;
+import org.apache.uima.ruta.expression.annotation.IAnnotationExpression;
+import org.apache.uima.ruta.expression.annotation.IAnnotationListExpression;
 import org.apache.uima.ruta.expression.bool.IBooleanExpression;
 import org.apache.uima.ruta.expression.number.INumberExpression;
 import org.apache.uima.ruta.expression.string.IStringExpression;
@@ -128,13 +132,27 @@ public class FeatureMatchExpression exte
         String v2 = expr.getStringValue(context, stream);
         return compare(v1, v2);
       }
-    } else if (!feature.getRange().isPrimitive() && getArg() instanceof 
FeatureExpression) {
-      FeatureExpression fe = (FeatureExpression) getArg();
-      List<FeatureStructure> list = new ArrayList<>(1);
-      list.add(fs);
-      Collection<? extends FeatureStructure> featureAnnotations = 
fe.getFeatureStructures(list,
-              false, context, stream);
-      return compare(fs.getFeatureValue(feature), featureAnnotations);
+    } else {
+      FeatureStructure featureValue = fs.getFeatureValue(feature);
+      if (!feature.getRange().isPrimitive() && getArg() instanceof 
FeatureExpression) {
+        FeatureExpression fe = (FeatureExpression) getArg();
+        List<FeatureStructure> list = new ArrayList<>(1);
+        list.add(fs);
+        Collection<? extends FeatureStructure> featureAnnotations = 
fe.getFeatureStructures(list,
+                false, context, stream);
+        return compare(featureValue, featureAnnotations);
+      } else if (!feature.getRange().isPrimitive() && getArg() instanceof 
IAnnotationExpression) {
+        IAnnotationExpression ae = (IAnnotationExpression) getArg();
+        AnnotationFS compareAnnotation = ae.getAnnotation(context, stream);
+        return compare(featureValue, compareAnnotation);
+      } else if (!feature.getRange().isPrimitive()
+              && 
typeSystem.subsumes(typeSystem.getType(CAS.TYPE_NAME_FS_ARRAY), 
featureRangeType)
+              && getArg() instanceof IAnnotationListExpression) {
+        ArrayFS fsArray = (ArrayFS) featureValue;
+        IAnnotationListExpression ale = (IAnnotationListExpression) getArg();
+        List<AnnotationFS> annotationList = ale.getAnnotationList(context, 
stream);
+        return compare(Arrays.asList(fsArray.toArray()), annotationList);
+      }
     }
     return false;
   }

Modified: 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpressionTest.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpressionTest.java?rev=1849894&r1=1849893&r2=1849894&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpressionTest.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpressionTest.java
 Fri Dec 28 23:33:50 2018
@@ -261,4 +261,74 @@ public class AnnotationFeatureExpression
 
   }
 
+  @Test
+  public void testAnnotationComparison() throws Exception {
+    String document = "Some text for testing.";
+    String t40String = "for testing.";
+
+    String script = "ANNOTATION a;\n";
+    script += "ANNOTATIONLIST as;\n";
+    script += "ANNOTATION a2;\n";
+    script += "ANNOTATIONLIST as2;\n";
+    script += "Document{-> a = CW};\n";
+    script += "Document{-> as = SW};\n";
+    script += "(W W @PERIOD){-> T40};\n";
+    script += "T40{-> a2 = PERIOD};\n";
+    script += "T40{-> as2 = SW};\n";
+    script += "Document{-> CREATE(Struct1, \"a\" = CW, \"as\" = SW  )};\n";
+    script += "T40{-> CREATE(Struct2, \"a\" = PERIOD, \"as\" = SW )};\n";
+
+    script += "Document{Struct1.a == a -> T1};\n";
+    script += "Document{Struct1.as == as -> T2};\n";
+    script += "Document{Struct1.a != a -> T3};\n";
+    script += "Document{Struct1.as != as -> T4};\n";
+    script += "Struct1.a == a { -> T5};\n";
+    script += "Struct1.as == as { -> T6};\n";
+
+    script += "T40{Struct2.a == a2 -> T7};\n";
+    script += "T40{Struct2.as == as2 -> T8};\n";
+    script += "T40{Struct2.a != a2 -> T9};\n";
+    script += "T40{Struct2.as != as2 -> T10};\n";
+    script += "Struct2.a == a2 { -> T11};\n";
+    script += "Struct2.as == as2 { -> T12};\n";
+
+    script += "Document{a != a2 -> T13};\n";
+    script += "Document{as != as2 -> T14};\n";
+
+    Map<String, String> typeMap = new TreeMap<String, String>();
+    String typeName1 = "Struct1";
+    typeMap.put(typeName1, "uima.tcas.Annotation");
+    String typeName2 = "Struct2";
+    typeMap.put(typeName2, "uima.tcas.Annotation");
+
+    Map<String, List<TestFeature>> featureMap = new TreeMap<String, 
List<TestFeature>>();
+    List<TestFeature> list = new ArrayList<RutaTestUtils.TestFeature>();
+    featureMap.put(typeName1, list);
+    featureMap.put(typeName2, list);
+    String fn1 = "a";
+    list.add(new TestFeature(fn1, "", "uima.tcas.Annotation"));
+    String fn2 = "as";
+    list.add(new TestFeature(fn2, "", "uima.cas.FSArray"));
+
+    CAS cas = RutaTestUtils.getCAS(document, typeMap, featureMap);
+    Ruta.apply(cas, script);
+
+    RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, document);
+    RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, document);
+    RutaTestUtils.assertAnnotationsEquals(cas, 3, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 4, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 5, 1, document);
+    RutaTestUtils.assertAnnotationsEquals(cas, 6, 1, document);
+
+    RutaTestUtils.assertAnnotationsEquals(cas, 7, 1, t40String);
+    RutaTestUtils.assertAnnotationsEquals(cas, 8, 1, t40String);
+    RutaTestUtils.assertAnnotationsEquals(cas, 9, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 10, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 11, 1, t40String);
+    RutaTestUtils.assertAnnotationsEquals(cas, 12, 1, t40String);
+
+    RutaTestUtils.assertAnnotationsEquals(cas, 13, 1, document);
+    RutaTestUtils.assertAnnotationsEquals(cas, 14, 1, document);
+  }
+
 }

Modified: 
uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g?rev=1849894&r1=1849893&r2=1849894&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
 (original)
+++ 
uima/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
 Fri Dec 28 23:33:50 2018
@@ -2661,6 +2661,8 @@ composedBooleanExpression returns [Expre
        (e2 = booleanCompare)=> e2 = booleanCompare {expr = e2;}
        | (bne = booleanNumberExpression)=> bne = booleanNumberExpression{expr 
= bne;}
        | (bse = booleanStringExpression)=> bse = booleanStringExpression{expr 
= bse;}
+       | (booleanAnnotationListExpression)=> bale = 
booleanAnnotationListExpression {expr = bale;}
+       | (booleanAnnotationExpression)=> bae = booleanAnnotationExpression 
{expr = bae;}
        | (bte = booleanTypeExpression)=> bte = booleanTypeExpression{expr = 
bte;}
        | e1 = booleanFunction {expr = e1;}
        | LPAREN ep = booleanExpression RPAREN {expr = ep;}
@@ -2701,6 +2703,22 @@ literalBooleanExpression returns  [Boole
        | value = FALSE)
        {expr = ExpressionFactory.createSimpleBooleanExpression(value);}
        ;
+       
+booleanAnnotationExpression  returns  [Expression expr = null]
+       :
+       e1 = annotationExpression
+       op = (EQUAL | NOTEQUAL)
+       e2 = annotationExpression
+       {expr = ExpressionFactory.createBooleanAnnotationExpression(e1,op,e2);}
+       ;
+
+booleanAnnotationListExpression  returns  [Expression expr = null]
+       :
+       e1 = annotationListExpression
+       op = (EQUAL | NOTEQUAL)
+       e2 = annotationListExpression
+       {expr = 
ExpressionFactory.createBooleanAnnotationListExpression(e1,op,e2);}
+       ;
 
 //not checked
 booleanTypeExpression  returns  [Expression expr = null]

Modified: 
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/ExpressionFactory.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/ExpressionFactory.java?rev=1849894&r1=1849893&r2=1849894&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/ExpressionFactory.java
 (original)
+++ 
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/ExpressionFactory.java
 Fri Dec 28 23:33:50 2018
@@ -51,7 +51,8 @@ public class ExpressionFactory extends A
     return newVariableReference(ref, RutaTypeConstants.RUTA_TYPE_G);
   }
 
-  public static RutaQuantifierLiteralExpression 
createQuantifierLiteralExpression(Token q, Token q2) {
+  public static RutaQuantifierLiteralExpression 
createQuantifierLiteralExpression(Token q,
+          Token q2) {
     int bounds[] = getBounds(q);
     if (q2 != null) {
       bounds[1] = Math.max(bounds[1], getBounds(q2)[1]);
@@ -271,7 +272,8 @@ public class ExpressionFactory extends A
 
   // TODO
   public static Expression createBooleanFunction(Token op, Expression e1, 
Expression e2) {
-    return new RutaExpression(e1.sourceStart(), e2.sourceEnd(), null, 
RutaTypeConstants.RUTA_TYPE_B);
+    return new RutaExpression(e1.sourceStart(), e2.sourceEnd(), null,
+            RutaTypeConstants.RUTA_TYPE_B);
   }
 
   public static Expression createListVariableReference(Token id) {
@@ -281,17 +283,16 @@ public class ExpressionFactory extends A
   public static Expression createTableVariableReference(Token id) {
     return newVariableReference(id, RutaTypeConstants.RUTA_TYPE_WT);
   }
-  
+
   public static Expression createListVariableReference(Expression ref) {
     int bounds[] = getSurroundingBounds(ref);
     return new RutaVariableReference(bounds[0], bounds[1], "", 
RutaTypeConstants.RUTA_TYPE_WL);
   }
-  
+
   public static Expression createTableVariableReference(Expression ref) {
     int bounds[] = getSurroundingBounds(ref);
     return new RutaVariableReference(bounds[0], bounds[1], "", 
RutaTypeConstants.RUTA_TYPE_WT);
   }
-  
 
   public static Expression createRessourceReference(Token path) {
     int bounds[] = getBounds(path);
@@ -331,6 +332,48 @@ public class ExpressionFactory extends A
     return null;
   }
 
+  public static Expression createBooleanAnnotationExpression(Expression e1, 
Token op,
+          Expression e2) {
+    int lexerOpID = op.getType(); // Integer.valueOf(op.getText());
+    int operatorID = 0;
+    // convert lexer-opId to dltk-opId:
+    switch (lexerOpID) {
+      case RutaLexer.EQUAL:
+        operatorID = E_EQUAL;
+        break;
+      case RutaLexer.NOTEQUAL:
+        operatorID = E_NOT_EQUAL;
+        break;
+      default:
+        break;
+    }
+    if (e1 != null && e2 != null) {
+      return new RutaBooleanCompareExpression(e1.sourceStart(), 
e2.sourceEnd(), operatorID, e1, e2);
+    }
+    return null;
+  }
+
+  public static Expression createBooleanAnnotationListExpression(Expression 
e1, Token op,
+          Expression e2) {
+    int lexerOpID = op.getType(); // Integer.valueOf(op.getText());
+    int operatorID = 0;
+    // convert lexer-opId to dltk-opId:
+    switch (lexerOpID) {
+      case RutaLexer.EQUAL:
+        operatorID = E_EQUAL;
+        break;
+      case RutaLexer.NOTEQUAL:
+        operatorID = E_NOT_EQUAL;
+        break;
+      default:
+        break;
+    }
+    if (e1 != null && e2 != null) {
+      return new RutaBooleanCompareExpression(e1.sourceStart(), 
e2.sourceEnd(), operatorID, e1, e2);
+    }
+    return null;
+  }
+
   public static Expression createBooleanStringExpression(Expression e1, Token 
op, Expression e2) {
     int lexerOpID = op.getType(); // Integer.valueOf(op.getText());
     int operatorID = 0;
@@ -350,7 +393,7 @@ public class ExpressionFactory extends A
     }
     return null;
   }
-  
+
   public static Expression createListExpression(List<Expression> exprList, int 
type) {
     List<ASTNode> l = new ArrayList<>();
     int start = 0;
@@ -443,16 +486,13 @@ public class ExpressionFactory extends A
           Expression arg, List<RutaCondition> cs) {
     int bounds[] = getBounds(match);
     int end = bounds[1];
-    if(cs != null && !cs.isEmpty()) {
-      end = cs.get(cs.size()-1).sourceEnd();
-    } else if(arg != null) {
+    if (cs != null && !cs.isEmpty()) {
+      end = cs.get(cs.size() - 1).sourceEnd();
+    } else if (arg != null) {
       end = arg.sourceEnd();
     }
-    FeatureMatchExpression reference =  new FeatureMatchExpression(bounds[0], 
end, match, comp, arg);
-    return new ConditionedAnnotationTypeExpression(bounds[0], end , reference, 
arg, cs);
+    FeatureMatchExpression reference = new FeatureMatchExpression(bounds[0], 
end, match, comp, arg);
+    return new ConditionedAnnotationTypeExpression(bounds[0], end, reference, 
arg, cs);
   }
 
-  
-
- 
 }


Reply via email to