Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/NearCondition.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/NearCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/NearCondition.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/NearCondition.java
 Wed Jan 16 11:45:02 2019
@@ -21,6 +21,7 @@ package org.apache.uima.ruta.condition;
 
 import org.apache.uima.cas.FSIterator;
 import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.ruta.RutaStream;
 import org.apache.uima.ruta.expression.bool.IBooleanExpression;
@@ -55,12 +56,20 @@ public class NearCondition extends TypeS
   @Override
   public EvaluatedCondition eval(MatchContext context, RutaStream stream, 
InferenceCrowd crowd) {
     AnnotationFS annotation = context.getAnnotation();
+
+    Type t = type.getType(context, stream);
+
+    if (annotation == null || t == null) {
+      return new EvaluatedCondition(this, false);
+    }
+
     int maxValue = max.getIntegerValue(context, stream);
     int minValue = min.getIntegerValue(context, stream);
     boolean forwardValue = forward.getBooleanValue(context, stream);
 
-    FSIterator<AnnotationFS> it = filtered.getBooleanValue(context, stream) ? 
stream.getCurrentIt() : stream
-            .getUnfilteredBasicIterator();
+    FSIterator<AnnotationFS> it = filtered.getBooleanValue(context, stream)
+            ? stream.getCurrentIterator()
+            : stream.getUnfilteredBasicIterator();
     AnnotationFS pointer = null;
     if (forwardValue) {
       pointer = stream.getEndAnchor(annotation.getEnd());
@@ -74,7 +83,7 @@ public class NearCondition extends TypeS
         FeatureStructure featureStructure = it.get();
         if (featureStructure instanceof RutaBasic) {
           RutaBasic each = (RutaBasic) featureStructure;
-          if (each.isPartOf(type.getType(context, stream))) {
+          if (each.isPartOf(t)) {
             return new EvaluatedCondition(this, true);
           }
         }

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ParseCondition.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ParseCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ParseCondition.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ParseCondition.java
 Wed Jan 16 11:45:02 2019
@@ -52,6 +52,11 @@ public class ParseCondition extends Abst
   @Override
   public EvaluatedCondition eval(MatchContext context, RutaStream stream, 
InferenceCrowd crowd) {
     AnnotationFS annotation = context.getAnnotation();
+
+    if (annotation == null) {
+      return new EvaluatedCondition(this, false);
+    }
+
     RuleElement element = context.getElement();
     String text = annotation.getCoveredText();
     RutaEnvironment env = element.getParent().getEnvironment();

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfCondition.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfCondition.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfCondition.java
 Wed Jan 16 11:45:02 2019
@@ -65,6 +65,9 @@ public class PartOfCondition extends Typ
   }
 
   private boolean check(Type t, AnnotationFS annotation, RuleElement element, 
RutaStream stream) {
+    if (annotation == null || t == null) {
+      return false;
+    }
     RutaBasic beginAnchor = stream.getBeginAnchor(annotation.getBegin());
     if (beginAnchor != null && beginAnchor.isPartOf(t)) {
       return true;

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java
 Wed Jan 16 11:45:02 2019
@@ -63,6 +63,11 @@ public class PartOfNeqCondition extends
   }
 
   private boolean check(AnnotationFS annotation, RutaStream stream, Type t) {
+
+    if (annotation == null || t == null) {
+      return false;
+    }
+
     RutaBasic beginAnchor = stream.getBeginAnchor(annotation.getBegin());
     RutaBasic endAnchor = stream.getEndAnchor(annotation.getEnd());
     boolean partOf = beginAnchor.isPartOf(t) || endAnchor.isPartOf(t);
@@ -84,12 +89,13 @@ public class PartOfNeqCondition extends
       }
       for (AnnotationFS afs : set) {
         if (afs != null
-                && (afs.getType().equals(t) || stream.getCas().getTypeSystem()
-                        .subsumes(t, afs.getType()))
+                && (afs.getType().equals(t)
+                        || stream.getCas().getTypeSystem().subsumes(t, 
afs.getType()))
                 && ((afs.getBegin() < annotation.getBegin() && afs.getEnd() > 
annotation.getEnd())
-                        || (afs.getBegin() == annotation.getBegin() && 
afs.getEnd() > annotation
-                                .getEnd()) || (afs.getBegin() < 
annotation.getBegin() && afs
-                        .getEnd() == annotation.getEnd()))) {
+                        || (afs.getBegin() == annotation.getBegin()
+                                && afs.getEnd() > annotation.getEnd())
+                        || (afs.getBegin() < annotation.getBegin()
+                                && afs.getEnd() == annotation.getEnd()))) {
           return true;
         }
 

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PositionCondition.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PositionCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PositionCondition.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PositionCondition.java
 Wed Jan 16 11:45:02 2019
@@ -52,9 +52,15 @@ public class PositionCondition extends T
   @Override
   public EvaluatedCondition eval(MatchContext context, RutaStream stream, 
InferenceCrowd crowd) {
     AnnotationFS annotation = context.getAnnotation();
-    RuleElement element = context.getElement();
+
     Type t = type.getType(context, stream);
 
+    if (annotation == null || t == null) {
+      return new EvaluatedCondition(this, false);
+    }
+
+    RuleElement element = context.getElement();
+
     RutaBasic beginAnchor = stream.getBeginAnchor(annotation.getBegin());
     RutaBasic endAnchor = stream.getEndAnchor(annotation.getEnd());
     if (beginAnchor == null || endAnchor == null || !beginAnchor.isPartOf(t)

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java
 Wed Jan 16 11:45:02 2019
@@ -53,9 +53,19 @@ public class RegExpCondition extends Ter
   @Override
   public EvaluatedCondition eval(MatchContext context, RutaStream stream, 
InferenceCrowd crowd) {
     AnnotationFS annotation = context.getAnnotation();
+
+    if (annotation == null) {
+      return new EvaluatedCondition(this, false);
+    }
+
     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/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ScoreCondition.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ScoreCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ScoreCondition.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ScoreCondition.java
 Wed Jan 16 11:45:02 2019
@@ -19,11 +19,7 @@
 
 package org.apache.uima.ruta.condition;
 
-import java.util.List;
-
-import org.apache.uima.cas.Type;
 import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.jcas.tcas.Annotation;
 import org.apache.uima.ruta.RutaStream;
 import org.apache.uima.ruta.expression.number.INumberExpression;
 import org.apache.uima.ruta.expression.number.SimpleNumberExpression;
@@ -50,17 +46,16 @@ public class ScoreCondition extends Term
   @Override
   public EvaluatedCondition eval(MatchContext context, RutaStream stream, 
InferenceCrowd crowd) {
     AnnotationFS annotation = context.getAnnotation();
+
+    if (annotation == null) {
+      return new EvaluatedCondition(this, false);
+    }
+
     RuleElement element = context.getElement();
-    Type heuristicType = stream.getJCas().getCasType(RutaAnnotation.type);
-    List<AnnotationFS> annotationsInWindow = 
stream.getAnnotationsInWindow(annotation,
-            heuristicType);
     double score = 0;
-    if (!annotationsInWindow.isEmpty()) {
-      RutaAnnotation heuristicAnnotation = (RutaAnnotation) 
stream.getCas().createAnnotation(
-              heuristicType, annotation.getBegin(), annotation.getEnd());
-      heuristicAnnotation.setAnnotation((Annotation) annotation);
-      RutaAnnotation tma = stream.getCorrectTMA(annotationsInWindow, 
heuristicAnnotation);
-      score = tma.getScore();
+    RutaAnnotation rutaAnnotation = stream.getRutaAnnotationFor(annotation, 
false, stream);
+    if (rutaAnnotation != null) {
+      score = rutaAnnotation.getScore();
     }
     if (var != null) {
       element.getParent().getEnvironment().setVariableValue(var, score);

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/StartsWithCondition.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/StartsWithCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/StartsWithCondition.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/StartsWithCondition.java
 Wed Jan 16 11:45:02 2019
@@ -65,7 +65,8 @@ public class StartsWithCondition extends
   }
 
   private boolean check(AnnotationFS annotation, Type t, RutaStream stream) {
-    if (annotation == null) {
+
+    if (annotation == null || t == null) {
       return false;
     }
     RutaBasic beginAnchor = stream.getBeginAnchor(annotation.getBegin());

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/TotalCountCondition.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/TotalCountCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/TotalCountCondition.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/TotalCountCondition.java
 Wed Jan 16 11:45:02 2019
@@ -51,6 +51,11 @@ public class TotalCountCondition extends
     RuleElement element = context.getElement();
     int count = 0;
     Type t = type.getType(context, stream);
+
+    if (t == null) {
+      return new EvaluatedCondition(this, false);
+    }
+
     AnnotationIndex<Annotation> annotationIndex = 
stream.getJCas().getAnnotationIndex(t);
     count = annotationIndex.size();
     if (var != null) {

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/VoteCondition.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/VoteCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/VoteCondition.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/VoteCondition.java
 Wed Jan 16 11:45:02 2019
@@ -47,10 +47,11 @@ public class VoteCondition extends Termi
     AnnotationFS annotation = context.getAnnotation();
     int count1 = 0;
     int count2 = 0;
-    if (annotation != null) {
+    Type t1 = type1.getType(context, stream);
+    Type t2 = type2.getType(context, stream);
+
+    if (annotation != null && t1 != null && t2 != null) {
       List<RutaBasic> annotations = stream.getBasicsInWindow(annotation);
-      Type t1 = type1.getType(context, stream);
-      Type t2 = type2.getType(context, stream);
       for (RutaBasic each : annotations) {
         if (each.beginsWith(t1)) {
           count1++;

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorBuilder.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorBuilder.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorBuilder.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorBuilder.java
 Wed Jan 16 11:45:02 2019
@@ -76,8 +76,7 @@ public class RutaDescriptorBuilder {
 
   private final URL defaultAnalysisEngine;
 
-  public RutaDescriptorBuilder(URL defaultTypeSystem, URL 
defaultAnalysisEngine)
-          throws InvalidXMLException, IOException {
+  public RutaDescriptorBuilder(URL defaultTypeSystem, URL 
defaultAnalysisEngine) {
     super();
     this.defaultTypeSystem = defaultTypeSystem;
     this.defaultAnalysisEngine = defaultAnalysisEngine;
@@ -154,7 +153,7 @@ public class RutaDescriptorBuilder {
                   "Build process can't find " + eachName + " in " + 
desc.getScriptName());
         }
       }
-      TypeSystemDescription each = getTypeSystemDescriptor(url, options, rm);
+      TypeSystemDescription each = getTypeSystemDescriptor(url, rm);
       if (each != null) {
         fillTypeNameMap(typeNameMap, each);
         if (include) {
@@ -204,7 +203,7 @@ public class RutaDescriptorBuilder {
                   + options.getTypeSystemSuffix() + ".xml" + " in " + 
desc.getScriptName());
         }
       }
-      TypeSystemDescription each = getTypeSystemDescriptor(url, options, rm);
+      TypeSystemDescription each = getTypeSystemDescriptor(url, rm);
       if (each != null) {
         fillTypeNameMap(typeNameMap, each);
         import_impl = new Import_impl();
@@ -572,13 +571,10 @@ public class RutaDescriptorBuilder {
             es.toArray(new String[0]));
   }
 
-  private TypeSystemDescription getTypeSystemDescriptor(URL url, 
RutaBuildOptions option,
-          ResourceManager rm) throws InvalidXMLException, IOException {
+  private TypeSystemDescription getTypeSystemDescriptor(URL url, 
ResourceManager rm) throws InvalidXMLException, IOException {
     TypeSystemDescription tsdesc = UIMAFramework.getXMLParser()
             .parseTypeSystemDescription(new XMLInputSource(url));
-    if (option.isResolveImports()) {
-      tsdesc.resolveImports(rm);
-    }
+    tsdesc.resolveImports(rm);
     return tsdesc;
   }
 

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java
 Wed Jan 16 11:45:02 2019
@@ -39,6 +39,7 @@ import org.apache.uima.resource.Resource
 import org.apache.uima.resource.ResourceManager;
 import org.apache.uima.resource.impl.ResourceManager_impl;
 import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.ruta.RutaConstants;
 import org.apache.uima.ruta.RutaScriptFactory;
 import org.apache.uima.ruta.action.ActionFactory;
 import org.apache.uima.ruta.condition.ConditionFactory;
@@ -52,18 +53,16 @@ import org.apache.uima.util.InvalidXMLEx
 
 public class RutaDescriptorFactory {
 
-  // public static final String ANONYMOUS = "Anonymous";
-
   private URL defaultTypeSystem;
 
   private URL defaultEngine;
 
   public RutaDescriptorFactory() {
     super();
-    this.defaultEngine = 
RutaDescriptorFactory.class.getClassLoader().getResource(
-            "org/apache/uima/ruta/engine/BasicEngine.xml");
-    this.defaultTypeSystem = 
RutaDescriptorFactory.class.getClassLoader().getResource(
-            "org/apache/uima/ruta/engine/BasicTypeSystem.xml");
+    this.defaultEngine = RutaDescriptorFactory.class.getClassLoader()
+            .getResource("org/apache/uima/ruta/engine/BasicEngine.xml");
+    this.defaultTypeSystem = RutaDescriptorFactory.class.getClassLoader()
+            .getResource("org/apache/uima/ruta/engine/BasicTypeSystem.xml");
   }
 
   public RutaDescriptorFactory(String defaultTypeSystem, String defaultEngine)
@@ -86,8 +85,8 @@ public class RutaDescriptorFactory {
 
     RutaDescriptorBuilder builder = new 
RutaDescriptorBuilder(defaultTypeSystem, defaultEngine);
 
-    TypeSystemDescription typeSystemDescription = 
builder.createTypeSystemDescription(
-            descriptorInformation, typeSystemOutput, options, null);
+    TypeSystemDescription typeSystemDescription = builder
+            .createTypeSystemDescription(descriptorInformation, 
typeSystemOutput, options, null);
 
     return typeSystemDescription;
   }
@@ -132,19 +131,18 @@ public class RutaDescriptorFactory {
     RutaLexer lexer = new RutaLexer(st);
     CommonTokenStream tokens = new CommonTokenStream(lexer);
     RutaParser parser = new RutaParser(tokens);
-    
+
     RutaDescriptorInformation descInfo = new RutaDescriptorInformation();
-    
-    
+
     parser.setDescriptorInformation(descInfo);
-    
+
     ExpressionFactory expressionFactory = new ExpressionFactory();
     ActionFactory actionFactory = new ActionFactory();
     ConditionFactory conditionFactory = new ConditionFactory();
     RutaScriptFactory scriptFactory = new RutaScriptFactory(expressionFactory);
     scriptFactory.setContext(null);
     ResourceManager rm = getResourceManager(options);
-    
+
     parser.setScriptFactory(scriptFactory);
     parser.setExpressionFactory(expressionFactory);
     parser.setActionFactory(actionFactory);
@@ -153,7 +151,7 @@ public class RutaDescriptorFactory {
     parser.setContext(null);
     parser.setResourcePaths(new String[0]);
     parser.setResourceManager(rm);
-    
+
     String name = scriptFile.getName();
     int lastIndexOf = name.lastIndexOf(RutaEngine.SCRIPT_FILE_EXTENSION);
     if (lastIndexOf != -1) {
@@ -164,25 +162,30 @@ public class RutaDescriptorFactory {
     return descInfo;
   }
 
-  public RutaDescriptorInformation parseDescriptorInformation(String script) 
throws IOException,
-          RecognitionException {
+  public RutaDescriptorInformation parseDescriptorInformation(String script)
+          throws IOException, RecognitionException {
     return parseDescriptorInformation(script, new RutaBuildOptions());
   }
 
-  public RutaDescriptorInformation parseDescriptorInformation(String script,
+  public RutaDescriptorInformation parseDescriptorInformation(String rules,
           RutaBuildOptions options) throws IOException, RecognitionException {
-    CharStream st = new ANTLRStringStream(script);
+    return parseDescriptorInformation(rules, RutaConstants.ANONYMOUS_SCRIPT, 
options);
+  }
+
+  public RutaDescriptorInformation parseDescriptorInformation(String rules, 
String rulesScriptName,
+          RutaBuildOptions options) throws IOException, RecognitionException {
+    CharStream st = new ANTLRStringStream(rules);
     RutaLexer lexer = new RutaLexer(st);
     CommonTokenStream tokens = new CommonTokenStream(lexer);
     RutaParser parser = new RutaParser(tokens);
     RutaDescriptorInformation descInfo = new RutaDescriptorInformation();
     parser.setDescriptorInformation(descInfo);
-   
+
     ExpressionFactory expressionFactory = new ExpressionFactory();
     ActionFactory actionFactory = new ActionFactory();
     ConditionFactory conditionFactory = new ConditionFactory();
     RutaScriptFactory scriptFactory = new RutaScriptFactory(expressionFactory);
-    
+
     parser.setContext(null);
     parser.setScriptFactory(scriptFactory);
     parser.setExpressionFactory(expressionFactory);
@@ -192,10 +195,9 @@ public class RutaDescriptorFactory {
     parser.setResourcePaths(new String[0]);
     ResourceManager rm = getResourceManager(options);
     parser.setResourceManager(rm);
-    String name = "Anonymous";
-    descInfo.setScriptName(name);
-    parser.file_input(name);
-    descInfo.setRules(script);
+    descInfo.setScriptName(rulesScriptName);
+    parser.file_input(rulesScriptName);
+    descInfo.setRules(rules);
     return descInfo;
   }
 

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java
 Wed Jan 16 11:45:02 2019
@@ -68,11 +68,16 @@ public class Ruta {
   /**
    * This applies the given rule on the given JCas object
    * 
-   * @param jcas - the current document
-   * @param rule - String containing one or more rules in valid ruta syntax
-   * @param configurationData - additional configuration parameter pairs
-   * @throws AnalysisEngineProcessException - problem while processing
-   * @throws ResourceInitializationException - problem while initializing
+   * @param jcas
+   *          - the current document
+   * @param rule
+   *          - String containing one or more rules in valid ruta syntax
+   * @param configurationData
+   *          - additional configuration parameter pairs
+   * @throws AnalysisEngineProcessException
+   *           - problem while processing
+   * @throws ResourceInitializationException
+   *           - problem while initializing
    */
   public static void applyRule(JCas jcas, String rule, Object... 
configurationData)
           throws ResourceInitializationException, 
AnalysisEngineProcessException {
@@ -97,8 +102,8 @@ public class Ruta {
     File scriptFile = File.createTempFile("Ruta", 
RutaEngine.SCRIPT_FILE_EXTENSION);
     scriptFile.deleteOnExit();
     FileUtils.saveString2File(script, scriptFile, "UTF-8");
-    ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { 
scriptFile
-            .getParentFile().getAbsolutePath() });
+    ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS,
+            new String[] { scriptFile.getParentFile().getAbsolutePath() });
     String name = scriptFile.getName().substring(0, 
scriptFile.getName().length() - 5);
     ae.setConfigParameterValue(RutaEngine.PARAM_MAIN_SCRIPT, name);
     if (parameters != null) {
@@ -112,9 +117,9 @@ public class Ruta {
     ae.destroy();
   }
 
-  public static void apply(CAS cas, String script) throws IOException, 
InvalidXMLException,
-          ResourceInitializationException, ResourceConfigurationException,
-          AnalysisEngineProcessException, URISyntaxException {
+  public static void apply(CAS cas, String script)
+          throws IOException, InvalidXMLException, 
ResourceInitializationException,
+          ResourceConfigurationException, AnalysisEngineProcessException, 
URISyntaxException {
     apply(cas, script, null);
   }
 
@@ -126,7 +131,7 @@ public class Ruta {
     }
     return result;
   }
-  
+
   private static int countRuleApplies(JCas jcas) {
     int result = 0;
     Collection<DebugBlockApply> blockApplies = JCasUtil.select(jcas, 
DebugBlockApply.class);
@@ -172,11 +177,12 @@ public class Ruta {
       result.add(dmrm);
     }
   }
-  
+
   /**
    * Removes all debug annotations from the index.
    * 
-   * @param jcas - the current document
+   * @param jcas
+   *          - the current document
    */
   public static void removeDebugInformation(JCas jcas) {
     jcas.removeAllIncludingSubtypes(DebugBlockApply.type);
@@ -192,17 +198,17 @@ public class Ruta {
     StringBuilder sb = new StringBuilder();
     int start = 0;
     int counter = 0;
-    while(matcher.find(start)) {
+    while (matcher.find(start)) {
       String group = matcher.group();
       sb.append(script.substring(start, matcher.start()));
-      if(counter < addresses.length) {
+      if (counter < addresses.length) {
         sb.append("$" + addresses[0]);
       } else {
         sb.append("$" + group);
       }
       start = matcher.end();
     }
-    if(start <script.length()) {
+    if (start < script.length()) {
       sb.append(script.substring(start, script.length()));
     }
     return sb.toString();
@@ -211,14 +217,12 @@ public class Ruta {
   public static String inject(String script, FeatureStructureImpl... 
annotations) {
     return inject(script, "$", getAddresses(annotations));
   }
-  
-
 
   private static int[] getAddresses(FeatureStructureImpl[] annotations) {
     int[] result = new int[annotations.length];
     for (int i = 0; i < annotations.length; i++) {
       result[i] = annotations[i].getAddress();
-      
+
     }
     return result;
   }
@@ -226,12 +230,17 @@ public class Ruta {
   /**
    * This method returns the spans of successful rule applies.
    * 
-   * @param jcas - the current document
-   * @param rule - String containing one or more rules in valid ruta syntax
-   * @param configurationData - additional configuration parameter pairs
+   * @param jcas
+   *          - the current document
+   * @param rule
+   *          - String containing one or more rules in valid ruta syntax
+   * @param configurationData
+   *          - additional configuration parameter pairs
    * @return list of successful rule matches
-   * @throws AnalysisEngineProcessException - problem while processing
-   * @throws ResourceInitializationException - problem while initializing
+   * @throws AnalysisEngineProcessException
+   *           - problem while processing
+   * @throws ResourceInitializationException
+   *           - problem while initializing
    */
   public static List<Annotation> select(JCas jcas, String rule, Object... 
configurationData)
           throws AnalysisEngineProcessException, 
ResourceInitializationException {
@@ -243,16 +252,20 @@ public class Ruta {
     return ruleMatches;
   }
 
-
   /**
    * This method returns true if the rule (or one of the rules) was able to 
match.
    * 
-   * @param jcas - the current document
-   * @param rule - String containing one or more rules in valid ruta syntax
-   * @param configurationData - additional configuration parameter pairs
+   * @param jcas
+   *          - the current document
+   * @param rule
+   *          - String containing one or more rules in valid ruta syntax
+   * @param configurationData
+   *          - additional configuration parameter pairs
    * @return true if matched, false otherwise
-   * @throws AnalysisEngineProcessException - problem while processing
-   * @throws ResourceInitializationException - problem while initializing
+   * @throws AnalysisEngineProcessException
+   *           - problem while processing
+   * @throws ResourceInitializationException
+   *           - problem while initializing
    */
   public static boolean matches(JCas jcas, String rule, Object... 
configurationData)
           throws AnalysisEngineProcessException, 
ResourceInitializationException {
@@ -262,17 +275,18 @@ public class Ruta {
     removeDebugInformation(jcas);
     return applies > 0;
   }
-  
 
-  public static AnalysisEngine wrapAnalysisEngine(URL descriptorUrl, String 
viewName, ResourceManager resourceManager)
-          throws ResourceInitializationException, 
ResourceConfigurationException,
-          InvalidXMLException, IOException, URISyntaxException {
-    return wrapAnalysisEngine(descriptorUrl, viewName, false, 
Charset.defaultCharset().name(), resourceManager);
-  }
-  
   public static AnalysisEngine wrapAnalysisEngine(URL descriptorUrl, String 
viewName,
-          boolean rutaEngine, String encoding, ResourceManager 
resourceManager) throws ResourceInitializationException,
+          ResourceManager resourceManager) throws 
ResourceInitializationException,
           ResourceConfigurationException, InvalidXMLException, IOException, 
URISyntaxException {
+    return wrapAnalysisEngine(descriptorUrl, viewName, false, 
Charset.defaultCharset().name(),
+            resourceManager);
+  }
+
+  public static AnalysisEngine wrapAnalysisEngine(URL descriptorUrl, String 
viewName,
+          boolean rutaEngine, String encoding, ResourceManager resourceManager)
+          throws ResourceInitializationException, 
ResourceConfigurationException,
+          InvalidXMLException, IOException, URISyntaxException {
     if (viewName.equals(CAS.NAME_DEFAULT_SOFA)) {
       XMLInputSource in = new XMLInputSource(descriptorUrl);
       ResourceSpecifier specifier = 
UIMAFramework.getXMLParser().parseResourceSpecifier(in);
@@ -293,7 +307,7 @@ public class Ruta {
       FileUtils.saveString2File(aaedString, tempFile);
       XMLInputSource in = new XMLInputSource(tempFile);
       ResourceSpecifier specifier = 
UIMAFramework.getXMLParser().parseResourceSpecifier(in);
-      AnalysisEngine ae = 
UIMAFramework.produceAnalysisEngine(specifier,resourceManager, null);
+      AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier, 
resourceManager, null);
       tempFile.delete();
       return ae;
     }
@@ -307,8 +321,8 @@ public class Ruta {
 
   @Deprecated
   public static AnalysisEngineDescription 
createAnalysisEngineDescription(String script,
-          TypeSystemDescription... tsds) throws IOException, 
InvalidXMLException,
-          ResourceInitializationException {
+          TypeSystemDescription... tsds)
+          throws IOException, InvalidXMLException, 
ResourceInitializationException {
     File scriptFile = File.createTempFile("Ruta", 
RutaEngine.SCRIPT_FILE_EXTENSION);
     scriptFile.deleteOnExit();
     if (!script.startsWith("PACKAGE")) {
@@ -321,8 +335,8 @@ public class Ruta {
             .parseResourceSpecifier(in);
     AnalysisEngineMetaData metaData = aed.getAnalysisEngineMetaData();
     ConfigurationParameterSettings settings = 
metaData.getConfigurationParameterSettings();
-    settings.setParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { 
scriptFile
-            .getParentFile().getAbsolutePath() });
+    settings.setParameterValue(RutaEngine.PARAM_SCRIPT_PATHS,
+            new String[] { scriptFile.getParentFile().getAbsolutePath() });
     String name = scriptFile.getName().substring(0, 
scriptFile.getName().length() - 5);
     settings.setParameterValue(RutaEngine.PARAM_MAIN_SCRIPT, name);
     if (tsds != null) {

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
 Wed Jan 16 11:45:02 2019
@@ -56,10 +56,12 @@ import org.apache.uima.cas.text.Annotati
 import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
 import org.apache.uima.fit.descriptor.ConfigurationParameter;
 import org.apache.uima.fit.factory.AnalysisEngineFactory;
+import org.apache.uima.fit.internal.ResourceManagerFactory;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.resource.ResourceManager;
 import org.apache.uima.ruta.FilterManager;
+import org.apache.uima.ruta.RutaConstants;
 import org.apache.uima.ruta.RutaEnvironment;
 import org.apache.uima.ruta.RutaModule;
 import org.apache.uima.ruta.RutaScriptFactory;
@@ -73,6 +75,7 @@ import org.apache.uima.ruta.extensions.I
 import org.apache.uima.ruta.extensions.RutaExternalFactory;
 import org.apache.uima.ruta.parser.RutaLexer;
 import org.apache.uima.ruta.parser.RutaParser;
+import org.apache.uima.ruta.resource.CSVTable;
 import org.apache.uima.ruta.resource.RutaResourceLoader;
 import org.apache.uima.ruta.seed.RutaAnnotationSeeder;
 import org.apache.uima.ruta.type.RutaBasic;
@@ -111,6 +114,14 @@ public class RutaEngine extends JCasAnno
   private String rules;
 
   /**
+   * This parameter specifies the name of the non-existing script if the 
parameter 'rules' is used.
+   */
+  public static final String PARAM_RULES_SCRIPT_NAME = "rulesScriptName";
+
+  @ConfigurationParameter(name = PARAM_RULES_SCRIPT_NAME, mandatory = true, 
defaultValue = RutaConstants.ANONYMOUS_SCRIPT)
+  private String rulesScriptName;
+
+  /**
    * 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}.
    */
@@ -251,7 +262,7 @@ public class RutaEngine extends JCasAnno
 
   /**
    * This parameter specifies whether the inference annotations created by the 
analysis engine
-   * should be removed after processing the CAS. The default value is set to 
true.
+   * should be removed after processing the CAS. The default value is set to 
false.
    */
   public static final String PARAM_REMOVE_BASICS = "removeBasics";
 
@@ -383,6 +394,15 @@ public class RutaEngine extends JCasAnno
   private Boolean dictRemoveWS = false;
 
   /**
+   * If this parameter is set to any String value then this String/token is 
used to split columns in
+   * CSV tables
+   */
+  public static final String PARAM_CSV_SEPARATOR = "csvSeparator";
+
+  @ConfigurationParameter(name = PARAM_CSV_SEPARATOR, mandatory = false, 
defaultValue = CSVTable.DEFAULT_CSV_SEPARATOR)
+  private String csvSeparator = CSVTable.DEFAULT_CSV_SEPARATOR;
+
+  /**
    * This parameter specifies the names of variables and is used in 
combination with the parameter
    * varValues, which contains the values of the corresponding variables. The 
n-th entry of this
    * string array specifies the variable of the n-th entry of the string array 
of the parameter
@@ -422,8 +442,8 @@ public class RutaEngine extends JCasAnno
 
   /**
    * If this parameter is activated, then only annotations of types are 
internally reindexed at
-   * beginning that are mentioned with in the rules. This parameter overrides 
the values of the parameter
-   * 'reindexOnly' with the types that are mentioned in the rules.
+   * beginning that are mentioned with in the rules. This parameter overrides 
the values of the
+   * parameter 'reindexOnly' with the types that are mentioned in the rules.
    */
   public static final String PARAM_REINDEX_ONLY_MENTIONED_TYPES = 
"reindexOnlyMentionedTypes";
 
@@ -471,6 +491,35 @@ public class RutaEngine extends JCasAnno
   @ConfigurationParameter(name = PARAM_MODIFY_DATAPATH, mandatory = false, 
defaultValue = "false")
   private boolean modifyDataPath;
 
+  /**
+   * This parameter specifies optional class names implementing the interface
+   * <code>org.apache.uima.ruta.visitor.RutaInferenceVisitor</code>, which 
will be notified during
+   * applying the rules.
+   * 
+   */
+  public static final String PARAM_INFERENCE_VISITORS = "inferenceVisitors";
+
+  @ConfigurationParameter(name = PARAM_INFERENCE_VISITORS, mandatory = false, 
defaultValue = {})
+  private String[] inferenceVisitors;
+
+  /**
+   * Maximum amount of allowed matches of a single rule.
+   */
+  public static final String PARAM_MAX_RULE_MATCHES = "maxRuleMatches";
+
+  @ConfigurationParameter(name = PARAM_MAX_RULE_MATCHES, mandatory = false, 
defaultValue = ""
+          + Integer.MAX_VALUE)
+  private int maxRuleMatches;
+
+  /**
+   * Maximum amount of allowed matches of a single rule element.
+   */
+  public static final String PARAM_MAX_RULE_ELEMENT_MATCHES = 
"maxRuleElementMatches";
+
+  @ConfigurationParameter(name = PARAM_MAX_RULE_ELEMENT_MATCHES, mandatory = 
false, defaultValue = ""
+          + Integer.MAX_VALUE)
+  private int maxRuleElementMatches;
+
   private UimaContext context;
 
   private RutaModule script;
@@ -557,6 +606,8 @@ public class RutaEngine extends JCasAnno
     stream.setDynamicAnchoring(dynamicAnchoring);
     stream.setGreedyRuleElement(greedyRuleElement);
     stream.setGreedyRule(greedyRule);
+    stream.setMaxRuleMatches(maxRuleMatches);
+    stream.setMaxRuleElementMatches(maxRuleElementMatches);
     try {
       script.apply(stream, crowd);
     } catch (Throwable e) {
@@ -582,7 +633,7 @@ public class RutaEngine extends JCasAnno
     }
   }
 
-  private void initializeResourceManager() {
+  private void initializeResourceManager() throws 
ResourceInitializationException {
     if (context instanceof UimaContextAdmin) {
       UimaContextAdmin uca = (UimaContextAdmin) context;
       ResourceManager rm = uca.getResourceManager();
@@ -591,7 +642,7 @@ public class RutaEngine extends JCasAnno
       }
     }
     if (resourceManager == null) {
-      resourceManager = UIMAFramework.newDefaultResourceManager();
+      resourceManager = ResourceManagerFactory.newResourceManager();
     }
   }
 
@@ -629,13 +680,14 @@ public class RutaEngine extends JCasAnno
     resetEnvironment(script, cas, new HashSet<RutaModule>());
   }
 
-  private void resetEnvironment(RutaModule module, CAS cas, 
Collection<RutaModule> alreadyResetted) {
-    if(alreadyResetted.contains(module)) {
+  private void resetEnvironment(RutaModule module, CAS cas,
+          Collection<RutaModule> alreadyResetted) {
+    if (alreadyResetted.contains(module)) {
       // avoid loop in recursion
       return;
     }
     alreadyResetted.add(module);
-    
+
     // reset all blocks
     RutaBlock block = module.getBlock(null);
     block.getEnvironment().reset(cas);
@@ -643,7 +695,7 @@ public class RutaEngine extends JCasAnno
     for (RutaBlock each : blocks) {
       each.getEnvironment().reset(cas);
     }
-    
+
     // reset imported scripts
     Collection<RutaModule> scripts = module.getScripts().values();
     for (RutaModule eachModule : scripts) {
@@ -688,7 +740,7 @@ public class RutaEngine extends JCasAnno
     }
     for (String each : additionalExtensions) {
       try {
-        Class<?> forName = Class.forName(each);
+        Class<?> forName = getClassLoader().loadClass(each);
         if (IRutaExtension.class.isAssignableFrom(forName)) {
           IRutaExtension extension = (IRutaExtension) forName.newInstance();
           verbalizer.addExternalVerbalizers(extension);
@@ -697,11 +749,20 @@ public class RutaEngine extends JCasAnno
           }
         }
       } catch (Exception e) {
-        getLogger().log(Level.WARNING, "Failed to initialze extension " + 
each);
+        getLogger().log(Level.WARNING, "Failed to initialize extension " + 
each);
       }
     }
   }
 
+  private ClassLoader getClassLoader() {
+    ClassLoader extensionClassLoader = 
resourceManager.getExtensionClassLoader();
+    if (extensionClassLoader == null) {
+      return this.getClass().getClassLoader();
+    }
+    return extensionClassLoader;
+
+  }
+
   private InferenceCrowd initializeCrowd() {
     List<RutaInferenceVisitor> visitors = new 
ArrayList<RutaInferenceVisitor>();
     if (debug) {
@@ -717,6 +778,20 @@ public class RutaEngine extends JCasAnno
     if (createdBy) {
       visitors.add(new CreatedByVisitor(verbalizer));
     }
+    if (inferenceVisitors != null && inferenceVisitors.length != 0) {
+      for (String eachClassName : inferenceVisitors) {
+        try {
+          Class<?> forName = getClassLoader().loadClass(eachClassName);
+          if (RutaInferenceVisitor.class.isAssignableFrom(forName)) {
+            RutaInferenceVisitor visitor = (RutaInferenceVisitor) 
forName.newInstance();
+            visitors.add(visitor);
+          }
+        } catch (Exception e) {
+          getLogger().log(Level.WARNING, "Failed to initialize inference 
visitor " + eachClassName);
+        }
+      }
+    }
+
     return new InferenceCrowd(visitors);
   }
 
@@ -746,7 +821,7 @@ public class RutaEngine extends JCasAnno
       for (String seederClass : seeders) {
         Class<?> loadClass = null;
         try {
-          loadClass = Class.forName(seederClass);
+          loadClass = getClassLoader().loadClass(seederClass);
         } catch (ClassNotFoundException e) {
           throw new AnalysisEngineProcessException(e);
         }
@@ -916,8 +991,8 @@ public class RutaEngine extends JCasAnno
     AnalysisEngine eachEngine = null;
     try {
       @SuppressWarnings("unchecked")
-      Class<? extends AnalysisComponent> uimafitClass = (Class<? extends 
AnalysisComponent>) Class
-              .forName(eachUimafitEngine);
+      Class<? extends AnalysisComponent> uimafitClass = (Class<? extends 
AnalysisComponent>) getClassLoader()
+              .loadClass(eachUimafitEngine);
       List<String> configurationData = 
script.getConfigurationData(eachUimafitEngine);
       AnalysisEngineDescription aed = 
AnalysisEngineFactory.createEngineDescription(uimafitClass,
               configurationData.toArray());
@@ -958,12 +1033,12 @@ public class RutaEngine extends JCasAnno
       }
       RutaBlock block = script.getBlock(blockName);
       if (block == null) {
-        return;
+        continue;
       }
 
       RutaEnvironment environment = block.getEnvironment();
       if (!environment.ownsVariable(shortName)) {
-        return;
+        continue;
       }
       Object valueObj = null;
       Class<?> variableType = environment.getVariableType(shortName);
@@ -1055,7 +1130,7 @@ public class RutaEngine extends JCasAnno
     RutaLexer lexer = new RutaLexer(st);
     CommonTokenStream tokens = new CommonTokenStream(lexer);
     RutaParser parser = createParser(tokens);
-    RutaModule script = parser.file_input("Anonymous");
+    RutaModule script = parser.file_input(rulesScriptName);
     return script;
   }
 

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaTestUtils.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaTestUtils.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaTestUtils.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaTestUtils.java
 Wed Jan 16 11:45:02 2019
@@ -55,6 +55,7 @@ import org.apache.uima.util.CasIOUtils;
 import org.apache.uima.util.FileUtils;
 import org.apache.uima.util.InvalidXMLException;
 import org.apache.uima.util.XMLInputSource;
+import org.xml.sax.SAXException;
 
 public class RutaTestUtils {
 
@@ -174,13 +175,15 @@ public class RutaTestUtils {
     aed.getAnalysisEngineMetaData().setTypeSystem(mergeTypeSystems);
 
     AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
-    ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { 
ruleFile
-            .getParentFile().getPath() });
+    ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS,
+            new String[] { ruleFile.getParentFile().getPath() });
     String name = ruleFile.getName();
     if (name.endsWith(RutaEngine.SCRIPT_FILE_EXTENSION)) {
       name = name.substring(0, name.length() - 5);
     }
 
+    ae.setConfigParameterValue(RutaEngine.PARAM_DICT_REMOVE_WS, false);
+
     for (Map.Entry<String, Object> parameter : parameters.entrySet()) {
       ae.setConfigParameterValue(parameter.getKey(), parameter.getValue());
     }
@@ -206,8 +209,10 @@ public class RutaTestUtils {
   /**
    * Helper to get the test type, e.g. org.apache.uima.T1, org.apache.uima.T2, 
...
    * 
-   * @param cas - The CAS object containing the type system
-   * @param i - typeId, converted to {@link #TYPE} + i
+   * @param cas
+   *          - The CAS object containing the type system
+   * @param i
+   *          - typeId, converted to {@link #TYPE} + i
    * @return the test type object with the given counter
    */
   public static Type getTestType(CAS cas, int i) {
@@ -216,14 +221,20 @@ public class RutaTestUtils {
     return cas.getTypeSystem().getType(TYPE + i);
   }
 
-  public static CAS getCAS(String document) throws 
ResourceInitializationException, IOException,
-          InvalidXMLException {
+  public static CAS getCAS(String document)
+          throws ResourceInitializationException, IOException, 
InvalidXMLException {
     return getCAS(document, null, null);
   }
 
   public static CAS getCAS(String document, Map<String, String> complexTypes,
-          Map<String, List<TestFeature>> features) throws 
ResourceInitializationException,
-          IOException, InvalidXMLException {
+          Map<String, List<TestFeature>> features)
+          throws ResourceInitializationException, IOException, 
InvalidXMLException {
+    return getCAS(document, complexTypes, features, false);
+  }
+
+  public static CAS getCAS(String document, Map<String, String> complexTypes,
+          Map<String, List<TestFeature>> features, boolean storeTypeSystem)
+          throws ResourceInitializationException, IOException, 
InvalidXMLException {
     URL url = RutaEngine.class.getClassLoader().getResource("BasicEngine.xml");
     if (url == null) {
       url = RutaTestUtils.class.getClassLoader()
@@ -257,6 +268,16 @@ public class RutaTestUtils {
     tsds.add(basicTypeSystem);
     TypeSystemDescription mergeTypeSystems = 
CasCreationUtils.mergeTypeSystems(tsds);
 
+    if (storeTypeSystem) {
+      try (OutputStream os = new FileOutputStream("TypeSystem.xml")) {
+        try {
+          mergeTypeSystems.toXML(os);
+        } catch (SAXException e) {
+          e.printStackTrace();
+        }
+      }
+    }
+
     aed.getAnalysisEngineMetaData().setTypeSystem(mergeTypeSystems);
     AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
     CAS cas = ae.newCAS();
@@ -271,14 +292,18 @@ public class RutaTestUtils {
       System.out.println(annotationFS.getCoveredText());
     }
   }
-  
+
   /**
    * Helper for common assertion in JUnit tests
    * 
-   * @param cas - The CAS object containing the type system
-   * @param typeId - typeId, converted to {@link #TYPE} + i
-   * @param expectedCnt - the expected amount of annotations
-   * @param expecteds -  the exprected covered texts
+   * @param cas
+   *          - The CAS object containing the type system
+   * @param typeId
+   *          - typeId, converted to {@link #TYPE} + i
+   * @param expectedCnt
+   *          - the expected amount of annotations
+   * @param expecteds
+   *          - the exprected covered texts
    */
   public static void assertAnnotationsEquals(CAS cas, int typeId, int 
expectedCnt,
           String... expecteds) {
@@ -293,8 +318,8 @@ public class RutaTestUtils {
       for (String expected : expecteds) {
         String actual = iterator.next().getCoveredText();
         if (!actual.equals(expected)) {
-          throw new AssertionError("expected text (" + expected + ") does not 
match with actual ("
-                  + actual + ").");
+          throw new AssertionError(
+                  "expected text (" + expected + ") does not match with actual 
(" + actual + ").");
         }
       }
     }
@@ -303,7 +328,8 @@ public class RutaTestUtils {
   /**
    * Helper to run Ruta on a tests script
    * 
-   * @param testClass - the class of the unit test
+   * @param testClass
+   *          - the class of the unit test
    * @return the annotated {@link CAS}
    */
   public static CAS processTestScript(Class<?> testClass) {
@@ -320,15 +346,14 @@ public class RutaTestUtils {
     }
     return cas;
   }
-  
-  
+
   public static void storeCas(CAS cas, String name) {
     File file = new File("input/" + name + ".xmi");
     file.getParentFile().mkdirs();
     OutputStream fos = null;
     try {
       fos = new FileOutputStream(file);
-      CasIOUtils.save(cas, fos , SerialFormat.XMI);
+      CasIOUtils.save(cas, fos, SerialFormat.XMI);
     } catch (IOException e) {
       throw new IllegalArgumentException(e);
     } finally {

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/StyleMapFactory.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/StyleMapFactory.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/StyleMapFactory.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/StyleMapFactory.java
 Wed Jan 16 11:45:02 2019
@@ -22,7 +22,6 @@ package org.apache.uima.ruta.engine;
 import java.awt.Color;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -31,9 +30,6 @@ import java.util.Map;
 import java.util.StringTokenizer;
 
 import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.uima.cas.FSIterator;
@@ -41,6 +37,7 @@ import org.apache.uima.cas.FeatureStruct
 import org.apache.uima.cas.Type;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.ruta.type.RutaColoring;
+import org.apache.uima.ruta.utils.XmlUtils;
 import org.apache.uima.tools.stylemap.ColorParser;
 import org.apache.uima.tools.stylemap.StyleMapEntry;
 import org.apache.uima.tools.stylemap.StyleMapXmlParser;
@@ -257,33 +254,13 @@ public class StyleMapFactory {
 
     File styleMapFile = new File(styleFileString);
     Document parse = null;
-    try {
-      DocumentBuilder db = 
DocumentBuilderFactory.newInstance().newDocumentBuilder();
-      FileInputStream stream = new FileInputStream(styleMapFile);
+   
+    try (FileInputStream stream = new FileInputStream(styleMapFile)) { 
+      DocumentBuilder db = XmlUtils.createDocumentBuilder();
       parse = db.parse(stream);
-      stream.close();
-
-    } catch (FileNotFoundException e) {
-      e.printStackTrace();
-      return null;
-
-    } catch (ParserConfigurationException e) {
-      e.printStackTrace();
-      return null;
-
-    } catch (FactoryConfigurationError e) {
-      e.printStackTrace();
-      return null;
-
-    } catch (SAXException e) {
-      e.printStackTrace();
-      return null;
-
-    } catch (IOException e) {
-      e.printStackTrace();
-      return null;
-    }
-
+    } catch (SAXException | IOException e) {
+      throw new IllegalStateException(e);
+    } 
     final Node root = parse.getDocumentElement();
     final NodeList nodeList = root.getChildNodes();
 

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/AnnotationTypeExpression.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/AnnotationTypeExpression.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/AnnotationTypeExpression.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/AnnotationTypeExpression.java
 Wed Jan 16 11:45:02 2019
@@ -21,7 +21,6 @@ package org.apache.uima.ruta.expression;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 
 import org.apache.uima.cas.FeatureStructure;
@@ -33,6 +32,7 @@ import org.apache.uima.ruta.expression.a
 import org.apache.uima.ruta.expression.feature.FeatureExpression;
 import org.apache.uima.ruta.expression.feature.FeatureMatchExpression;
 import org.apache.uima.ruta.expression.type.ITypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeListExpression;
 import org.apache.uima.ruta.rule.MatchContext;
 
 public class AnnotationTypeExpression extends RutaExpression
@@ -42,6 +42,8 @@ public class AnnotationTypeExpression ex
 
   private ITypeExpression typeExpression;
 
+  private ITypeListExpression typeListExpression;
+
   private IAnnotationExpression annotationExpression;
 
   private IAnnotationListExpression annotationListExpression;
@@ -60,6 +62,7 @@ public class AnnotationTypeExpression ex
     annotationListExpression = reference.getAnnotationListExpression(context, 
stream);
     featureExpression = reference.getFeatureExpression(context, stream);
     typeExpression = reference.getTypeExpression(context, stream);
+    typeListExpression = reference.getTypeListExpression(context, stream);
     initialized = true;
   }
 
@@ -101,37 +104,48 @@ public class AnnotationTypeExpression ex
         }
       }
     } else {
-      Type type = getType(context, stream);
-      if (type != null) {
 
-        List<AnnotationFS> bestGuessedAnnotations = null;
+      List<Type> types = null;
+      if (typeListExpression != null) {
+        types = typeListExpression.getTypeList(context, stream);
+      } else {
+        Type type = getType(context, stream);
+        types = new ArrayList<>(1);
+        types.add(type);
+      }
+      for (Type type : types) {
 
-        if (featureExpression instanceof FeatureMatchExpression) {
-          // allow more matches for feature matches
-          bestGuessedAnnotations = stream.getAnnotationsByTypeInContext(type, 
context);
-        } else if (featureExpression != null) {
-          bestGuessedAnnotations = 
stream.getBestGuessedAnnotationsAt(context.getAnnotation(),
-                  type);
-        } else {
-          bestGuessedAnnotations = 
stream.getBestGuessedAnnotationsAt(context.getAnnotation(),
-                  type);
-          if (bestGuessedAnnotations.isEmpty()) {
-            bestGuessedAnnotations = new ArrayList<>(1);
-            
bestGuessedAnnotations.add(stream.getSingleAnnotationByTypeInContext(type, 
context));
+        if (type != null) {
+
+          List<AnnotationFS> bestGuessedAnnotations = null;
+
+          if (featureExpression instanceof FeatureMatchExpression) {
+            // allow more matches for feature matches
+            bestGuessedAnnotations = 
stream.getAnnotationsByTypeInContext(type, context);
+          } else if (featureExpression != null) {
+            bestGuessedAnnotations = 
stream.getBestGuessedAnnotationsAt(context.getAnnotation(),
+                    type);
+          } else {
+            bestGuessedAnnotations = 
stream.getBestGuessedAnnotationsAt(context.getAnnotation(),
+                    type);
+            if (bestGuessedAnnotations.isEmpty()) {
+              bestGuessedAnnotations = new ArrayList<>(1);
+              
bestGuessedAnnotations.add(stream.getSingleAnnotationByTypeInContext(type, 
context));
+            }
           }
-        }
 
-        if (featureExpression != null) {
-          Collection<AnnotationFS> annotations = new ArrayList<>();
-          annotations.addAll(bestGuessedAnnotations);
-          Collection<? extends AnnotationFS> featureAnnotations = 
featureExpression
-                  .getAnnotations(annotations, true, context, stream);
-          if (featureAnnotations != null && !featureAnnotations.isEmpty()) {
-            return featureAnnotations.iterator().next();
+          if (featureExpression != null) {
+            Collection<AnnotationFS> annotations = new ArrayList<>();
+            annotations.addAll(bestGuessedAnnotations);
+            Collection<? extends AnnotationFS> featureAnnotations = 
featureExpression
+                    .getAnnotations(annotations, true, context, stream);
+            if (featureAnnotations != null && !featureAnnotations.isEmpty()) {
+              return featureAnnotations.iterator().next();
+            }
+          }
+          if (bestGuessedAnnotations != null && 
!bestGuessedAnnotations.isEmpty()) {
+            return bestGuessedAnnotations.get(0);
           }
-        }
-        if (bestGuessedAnnotations != null && 
!bestGuessedAnnotations.isEmpty()) {
-          return bestGuessedAnnotations.get(0);
         }
       }
     }
@@ -171,6 +185,8 @@ public class AnnotationTypeExpression ex
       return annotationListExpression.getStringValue(context, stream);
     } else if (annotationExpression != null) {
       return annotationExpression.getStringValue(context, stream);
+    } else if (typeListExpression != null) {
+      return typeListExpression.getStringValue(context, stream);
     } else if (typeExpression != null) {
       return typeExpression.getStringValue(context, stream);
     }
@@ -199,39 +215,51 @@ public class AnnotationTypeExpression ex
         return result;
       }
     } else {
-      Type type = getType(context, stream);
-      if (type != null) {
 
-        List<AnnotationFS> bestGuessedAnnotations = null;
+      List<Type> types = null;
+      if (typeListExpression != null) {
+        types = typeListExpression.getTypeList(context, stream);
+      } else {
+        Type type = getType(context, stream);
+        types = new ArrayList<>(1);
+        types.add(type);
+      }
+
+      List<AnnotationFS> annotations = new ArrayList<>();
+
+      for (Type type : types) {
+        if (type != null) {
 
-        if (featureExpression instanceof FeatureMatchExpression) {
-          // allow more matches for feature matches
-          bestGuessedAnnotations = stream.getAnnotationsByTypeInContext(type, 
context);
-        } else if (featureExpression != null) {
-          bestGuessedAnnotations = 
stream.getBestGuessedAnnotationsAt(context.getAnnotation(),
-                  type);
-          if (bestGuessedAnnotations.isEmpty()) {
+          List<AnnotationFS> bestGuessedAnnotations = null;
+
+          if (featureExpression instanceof FeatureMatchExpression) {
+            // allow more matches for feature matches
+            bestGuessedAnnotations = 
stream.getAnnotationsByTypeInContext(type, context);
+          } else if (featureExpression != null) {
+            bestGuessedAnnotations = 
stream.getBestGuessedAnnotationsAt(context.getAnnotation(),
+                    type);
+            if (bestGuessedAnnotations.isEmpty()) {
+              bestGuessedAnnotations = 
stream.getAnnotationsByTypeInContext(type, context);
+            }
+          } else {
             bestGuessedAnnotations = 
stream.getAnnotationsByTypeInContext(type, context);
           }
-        } else {
-          bestGuessedAnnotations = stream.getAnnotationsByTypeInContext(type, 
context);
-        }
 
-        if (featureExpression != null) {
-          Collection<AnnotationFS> annotations = new ArrayList<>();
-          annotations.addAll(bestGuessedAnnotations);
-          Collection<? extends AnnotationFS> featureAnnotations = 
featureExpression
-                  .getAnnotations(annotations, true, context, stream);
-          if (featureAnnotations != null && !featureAnnotations.isEmpty()) {
-            return new ArrayList<>(featureAnnotations);
+          if (featureExpression != null) {
+            Collection<? extends AnnotationFS> featureAnnotations = 
featureExpression
+                    .getAnnotations(bestGuessedAnnotations, true, context, 
stream);
+            if (featureAnnotations != null && !featureAnnotations.isEmpty()) {
+              annotations.addAll(featureAnnotations);
+            }
+          }
+          if (bestGuessedAnnotations != null && 
!bestGuessedAnnotations.isEmpty()) {
+            annotations.addAll(bestGuessedAnnotations);
           }
-        }
-        if (bestGuessedAnnotations != null && 
!bestGuessedAnnotations.isEmpty()) {
-          return bestGuessedAnnotations;
         }
       }
+
+      return annotations;
     }
-    return Collections.emptyList();
   }
 
   public MatchReference getReference() {
@@ -246,6 +274,10 @@ public class AnnotationTypeExpression ex
     return typeExpression;
   }
 
+  public ITypeListExpression getTypeListExpression() {
+    return typeListExpression;
+  }
+
   public IAnnotationExpression getAnnotationExpression() {
     return annotationExpression;
   }
@@ -258,6 +290,7 @@ public class AnnotationTypeExpression ex
     return featureExpression;
   }
 
+  @Override
   public String toString() {
     return reference.toString();
   }

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java
 Wed Jan 16 11:45:02 2019
@@ -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) {

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java
 Wed Jan 16 11:45:02 2019
@@ -36,7 +36,9 @@ import org.apache.uima.ruta.expression.f
 import org.apache.uima.ruta.expression.feature.FeatureMatchExpression;
 import org.apache.uima.ruta.expression.feature.SimpleFeatureExpression;
 import org.apache.uima.ruta.expression.type.ITypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeListExpression;
 import org.apache.uima.ruta.expression.type.SimpleTypeExpression;
+import org.apache.uima.ruta.expression.type.TypeListVariableExpression;
 import org.apache.uima.ruta.expression.type.TypeVariableExpression;
 import org.apache.uima.ruta.rule.MatchContext;
 import org.apache.uima.ruta.utils.IndexedReference;
@@ -52,6 +54,8 @@ public class MatchReference extends Ruta
 
   private ITypeExpression typeExpression;
 
+  private ITypeListExpression typeListExpression;
+
   private IAnnotationExpression annotationExpression;
 
   private IAnnotationListExpression annotationListExpression;
@@ -79,6 +83,12 @@ public class MatchReference extends Ruta
     initialized = true;
   }
 
+  public MatchReference(ITypeListExpression expression) {
+    super();
+    this.typeListExpression = expression;
+    initialized = true;
+  }
+
   public MatchReference(IAnnotationExpression expression) {
     super();
     this.annotationExpression = expression;
@@ -127,10 +137,10 @@ public class MatchReference extends Ruta
       }
     }
     initialized = true;
-    if (typeExpression == null && annotationExpression == null
+    if (typeExpression == null && typeListExpression == null && 
annotationExpression == null
             && annotationListExpression == null) {
-      throw new IllegalArgumentException(
-              "Not able to resolve annotation/type expression: " + reference);
+      throw new IllegalArgumentException("Not able to resolve annotation/type 
expression: "
+              + reference + " in script " + context.getParent().getName());
     }
   }
 
@@ -149,6 +159,9 @@ public class MatchReference extends Ruta
       if (environment.isVariableOfType(candidate, 
RutaConstants.RUTA_VARIABLE_TYPE)) {
         typeExpression = new TypeVariableExpression(candidate);
         return true;
+      } else if (environment.isVariableOfType(candidate, 
RutaConstants.RUTA_VARIABLE_TYPE_LIST)) {
+        typeListExpression = new TypeListVariableExpression(candidate);
+        return true;
       } else if (environment.isVariableOfType(candidate, 
RutaConstants.RUTA_VARIABLE_ANNOTATION)) {
         annotationExpression = new AnnotationVariableExpression(candidate);
         return true;
@@ -169,6 +182,11 @@ public class MatchReference extends Ruta
     return typeExpression;
   }
 
+  public ITypeListExpression getTypeListExpression(MatchContext context, 
RutaStream stream) {
+    resolve(context, stream);
+    return typeListExpression;
+  }
+
   public IAnnotationExpression getAnnotationExpression(MatchContext context, 
RutaStream stream) {
     resolve(context, stream);
     return annotationExpression;
@@ -196,6 +214,9 @@ public class MatchReference extends Ruta
     if (typeExpression != null) {
       return typeExpression.toString();
     }
+    if (typeListExpression != null) {
+      return typeListExpression.toString();
+    }
     if (annotationExpression != null) {
       return annotationExpression.toString();
     }

Added: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationExpression.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationExpression.java?rev=1851430&view=auto
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationExpression.java
 (added)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationExpression.java
 Wed Jan 16 11:45:02 2019
@@ -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/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationListExpression.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationListExpression.java?rev=1851430&view=auto
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationListExpression.java
 (added)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanAnnotationListExpression.java
 Wed Jan 16 11:45:02 2019
@@ -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/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java
 Wed Jan 16 11:45:02 2019
@@ -27,6 +27,7 @@ import org.apache.uima.cas.FeatureStruct
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.ruta.RutaStream;
 import org.apache.uima.ruta.expression.feature.FeatureExpression;
+import org.apache.uima.ruta.expression.feature.LazyFeature;
 import org.apache.uima.ruta.rule.MatchContext;
 
 public class BooleanFeatureExpression extends AbstractBooleanExpression {
@@ -48,9 +49,13 @@ public class BooleanFeatureExpression ex
             false, context, stream);
     if (!featureStructures.isEmpty()) {
       FeatureStructure next = featureStructures.iterator().next();
-      if (next instanceof AnnotationFS && next != annotation) {
-        feature = this.fe.getFeature(new MatchContext((AnnotationFS) next, 
context.getElement(),
-                context.getRuleMatch(), context.getDirection()), stream);
+//      if (next instanceof AnnotationFS && next != annotation) {
+//        feature = this.fe.getFeature(new MatchContext((AnnotationFS) next, 
context.getElement(),
+//                context.getRuleMatch(), context.getDirection()), stream);
+//      }
+      if (feature instanceof LazyFeature) {
+        LazyFeature lazyFeature = (LazyFeature) feature;
+        feature = lazyFeature.initialize(next);
       }
       return next.getBooleanValue(feature);
     }

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java
 Wed Jan 16 11:45:02 2019
@@ -32,6 +32,7 @@ import org.apache.uima.cas.FeatureStruct
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.ruta.RutaStream;
 import org.apache.uima.ruta.expression.feature.FeatureExpression;
+import org.apache.uima.ruta.expression.feature.LazyFeature;
 import org.apache.uima.ruta.rule.MatchContext;
 
 /**
@@ -63,9 +64,13 @@ public class BooleanListFeatureExpressio
     List<Boolean> result = new ArrayList<>();
 
     for (FeatureStructure each : featureStructures) {
-      if (each instanceof AnnotationFS && 
!each.getType().equals(annotation.getType())) {
-        feature = this.fe.getFeature(new MatchContext((AnnotationFS) each, 
context.getElement(),
-                context.getRuleMatch(), context.getDirection()), stream);
+//      if (each instanceof AnnotationFS && 
!each.getType().equals(annotation.getType())) {
+//        feature = this.fe.getFeature(new MatchContext((AnnotationFS) each, 
context.getElement(),
+//                context.getRuleMatch(), context.getDirection()), stream);
+//      }
+      if (feature instanceof LazyFeature) {
+        LazyFeature lazyFeature = (LazyFeature) feature;
+        feature = lazyFeature.initialize(each);
       }
       FeatureStructure featureValue = each.getFeatureValue(feature);
       if (featureValue instanceof BooleanArrayFS) {

Modified: 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanStringExpression.java
URL: 
http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanStringExpression.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanStringExpression.java
 (original)
+++ 
uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanStringExpression.java
 Wed Jan 16 11:45:02 2019
@@ -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;


Reply via email to