Author: pkluegl
Date: Thu Jan 10 14:47:37 2019
New Revision: 1850942

URL: http://svn.apache.org/viewvc?rev=1850942&view=rev
Log:
UIMA-5951: reinitialize lazy features later

Modified:
    uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureMatchExpression.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberListFeatureExpression.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringListFeatureExpression.java

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java?rev=1850942&r1=1850941&r2=1850942&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java 
(original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java 
Thu Jan 10 14:47:37 2019
@@ -67,6 +67,7 @@ import org.apache.uima.ruta.expression.b
 import org.apache.uima.ruta.expression.bool.IBooleanListExpression;
 import org.apache.uima.ruta.expression.feature.FeatureExpression;
 import org.apache.uima.ruta.expression.feature.GenericFeatureExpression;
+import org.apache.uima.ruta.expression.feature.LazyFeature;
 import org.apache.uima.ruta.expression.feature.SimpleFeatureExpression;
 import org.apache.uima.ruta.expression.number.INumberExpression;
 import org.apache.uima.ruta.expression.number.INumberListExpression;
@@ -987,6 +988,11 @@ public class RutaStream extends FSIterat
               "Not able to assign feature value (e.g., coveredText) in script "
                       + context.getParent().getName());
     }
+    if (feature instanceof LazyFeature) {
+      LazyFeature lazyFeature = (LazyFeature) feature;
+      feature = lazyFeature.initialize(annotation);
+    }
+
     CAS cas = annotation.getCAS();
     TypeSystem typeSystem = cas.getTypeSystem();
     Type range = feature.getRange();

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java?rev=1850942&r1=1850941&r2=1850942&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java
 Thu Jan 10 14:47:37 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/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java?rev=1850942&r1=1850941&r2=1850942&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java
 Thu Jan 10 14:47:37 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/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=1850942&r1=1850941&r2=1850942&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
 Thu Jan 10 14:47:37 2019
@@ -77,6 +77,10 @@ public class FeatureMatchExpression exte
 
   public boolean checkFeatureValue(FeatureStructure fs, MatchContext context, 
RutaStream stream) {
     Feature feature = getFeature(context, stream);
+    if (feature instanceof LazyFeature) {
+      LazyFeature lazyFeature = (LazyFeature) feature;
+      feature = lazyFeature.initialize(fs);
+    }
     return checkFeatureValue(fs, feature, context, stream);
   }
 

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java?rev=1850942&r1=1850941&r2=1850942&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
 Thu Jan 10 14:47:37 2019
@@ -6,9 +6,9 @@
  * 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
@@ -43,24 +43,28 @@ public class SimpleFeatureExpression ext
   private MatchReference mr;
 
   public SimpleFeatureExpression(MatchReference mr) {
+
     super();
     this.mr = mr;
   }
 
   @Override
   public Feature getFeature(MatchContext context, RutaStream stream) {
-    List<Feature> features = getFeatures(context, stream);
+
+    List<Feature> features = this.getFeatures(context, stream);
     if (features != null && !features.isEmpty()) {
       Feature feature = features.get(features.size() - 1);
       if (feature instanceof LazyFeature) {
         LazyFeature lazyFeature = (LazyFeature) feature;
         AnnotationFS annotation = context.getAnnotation();
-        List<AnnotationFS> targetAnnotation = getTargetAnnotation(annotation, 
this, context,
+        List<AnnotationFS> targetAnnotation = 
this.getTargetAnnotation(annotation, this, context,
                 stream);
         if (targetAnnotation != null && !targetAnnotation.isEmpty()) {
           annotation = targetAnnotation.get(0);
         }
-        feature = lazyFeature.initialize(annotation);
+        if (features.size() == 1) {
+          feature = lazyFeature.initialize(annotation);
+        }
       }
       return feature;
     } else {
@@ -70,25 +74,25 @@ public class SimpleFeatureExpression ext
 
   @Override
   public List<Feature> getFeatures(MatchContext context, RutaStream stream) {
+
     List<Feature> result = new ArrayList<Feature>();
-    Type type = getInitialType(context, stream);
+    Type type = this.getInitialType(context, stream);
     Feature feature = null;
-    for (String each : getFeatureStringList(context, stream)) {
+    for (String each : this.getFeatureStringList(context, stream)) {
       IndexedReference indexedReference = 
ParsingUtils.parseIndexedReference(each);
       if (indexedReference.index != -1) {
         Feature delegate = 
type.getFeatureByBaseName(indexedReference.reference);
         if (delegate != null) {
           feature = new IndexedFeature(delegate, indexedReference.index);
         } else {
-          throw new IllegalArgumentException(
-                  "Not able to access feature " + each + " of type " + 
type.getName() + 
-                  "in script " + context.getParent().getName());
+          throw new IllegalArgumentException("Not able to access feature " + 
each + " of type "
+                  + type.getName() + "in script " + 
context.getParent().getName());
         }
       } else if (StringUtils.equals(each, UIMAConstants.FEATURE_COVERED_TEXT)
               || StringUtils.equals(each, 
UIMAConstants.FEATURE_COVERED_TEXT_SHORT)) {
         if (type != null) {
           feature = type.getFeatureByBaseName(each);
-          if(feature == null) {
+          if (feature == null) {
             // there is no explicit feature for coveredText
             feature = new CoveredTextFeature();
           }
@@ -118,17 +122,19 @@ public class SimpleFeatureExpression ext
 
   @Override
   public Type getInitialType(MatchContext context, RutaStream stream) {
-    ITypeExpression typeExpression = mr.getTypeExpression(context, stream);
-    IAnnotationExpression annotationExpression = 
mr.getAnnotationExpression(context, stream);
-    IAnnotationExpression annotationListExpression = 
mr.getAnnotationExpression(context, stream);
-    if (typeExpression!= null) {
+
+    ITypeExpression typeExpression = this.mr.getTypeExpression(context, 
stream);
+    IAnnotationExpression annotationExpression = 
this.mr.getAnnotationExpression(context, stream);
+    IAnnotationExpression annotationListExpression = 
this.mr.getAnnotationExpression(context,
+            stream);
+    if (typeExpression != null) {
       return typeExpression.getType(context, stream);
-    } else if(annotationExpression != null) {
-        AnnotationFS annotation = annotationExpression.getAnnotation(context, 
stream);
-        if (annotation != null) {
-          return annotation.getType();
-        }
-    } else if(annotationListExpression != null) {
+    } else if (annotationExpression != null) {
+      AnnotationFS annotation = annotationExpression.getAnnotation(context, 
stream);
+      if (annotation != null) {
+        return annotation.getType();
+      }
+    } else if (annotationListExpression != null) {
       AnnotationFS annotation = 
annotationListExpression.getAnnotation(context, stream);
       if (annotation != null) {
         return annotation.getType();
@@ -139,7 +145,8 @@ public class SimpleFeatureExpression ext
 
   @Override
   public List<String> getFeatureStringList(MatchContext context, RutaStream 
stream) {
-    return mr.getFeatureList();
+
+    return this.mr.getFeatureList();
   }
 
   @Override
@@ -148,13 +155,13 @@ public class SimpleFeatureExpression ext
           MatchContext context, RutaStream stream) {
 
     Collection<AnnotationFS> result = new ArrayList<>();
-    List<Feature> features = getFeatures(context, stream);
+    List<Feature> features = this.getFeatures(context, stream);
     if (features != null && !features.isEmpty()) {
-      collectFeatureStructures(featureStructures, features, 
checkOnFeatureValue, true, result,
+      this.collectFeatureStructures(featureStructures, features, 
checkOnFeatureValue, true, result,
               stream, context);
       return result;
     } else {
-      return filterAnnotations(featureStructures);
+      return this.filterAnnotations(featureStructures);
     }
   }
 
@@ -162,10 +169,11 @@ public class SimpleFeatureExpression ext
   public Collection<? extends FeatureStructure> getFeatureStructures(
           Collection<? extends FeatureStructure> featureStructures, boolean 
checkOnFeatureValue,
           MatchContext context, RutaStream stream) {
+
     Collection<FeatureStructure> result = new ArrayList<>();
-    List<Feature> features = getFeatures(context, stream);
+    List<Feature> features = this.getFeatures(context, stream);
     if (features != null && !features.isEmpty()) {
-      collectFeatureStructures(featureStructures, features, 
checkOnFeatureValue, false, result,
+      this.collectFeatureStructures(featureStructures, features, 
checkOnFeatureValue, false, result,
               stream, context);
       return result;
     } else {
@@ -173,25 +181,28 @@ public class SimpleFeatureExpression ext
     }
   }
 
-  private <T> void collectFeatureStructures(Collection<? extends 
FeatureStructure> featureStructures,
-          List<Feature> features, boolean checkOnFeatureValue, boolean 
onlyAnnotations,
-          Collection<T> result, RutaStream stream, MatchContext context) {
+  private <T> void collectFeatureStructures(
+          Collection<? extends FeatureStructure> featureStructures, 
List<Feature> features,
+          boolean checkOnFeatureValue, boolean onlyAnnotations, Collection<T> 
result,
+          RutaStream stream, MatchContext context) {
+
     for (FeatureStructure each : featureStructures) {
-      collectFeatureStructures(each, features, checkOnFeatureValue, 
onlyAnnotations, null, result,
-              stream, context);
+      this.collectFeatureStructures(each, features, checkOnFeatureValue, 
onlyAnnotations, null,
+              result, stream, context);
     }
   }
 
   @SuppressWarnings("unchecked")
-  private <T> void collectFeatureStructures(FeatureStructure featureStructure, 
List<Feature> features,
-          boolean checkOnFeatureValue, boolean collectOnlyAnnotations,
-          T lastValidFeatureStructure, Collection<T> result,
-          RutaStream stream, MatchContext context) {
+  private <T> void collectFeatureStructures(FeatureStructure featureStructure,
+          List<Feature> features, boolean checkOnFeatureValue, boolean 
collectOnlyAnnotations,
+          T lastValidFeatureStructure, Collection<T> result, RutaStream stream,
+          MatchContext context) {
+
     if (featureStructure == null) {
       return;
     }
     if (!collectOnlyAnnotations) {
-      if(!featureStructure.getType().isArray()) {
+      if (!featureStructure.getType().isArray()) {
         lastValidFeatureStructure = (T) featureStructure;
       }
     } else if (featureStructure instanceof AnnotationFS) {
@@ -208,7 +219,8 @@ public class SimpleFeatureExpression ext
         Feature delegate = lazyFeature.initialize(featureStructure);
         if (delegate == null) {
           throw new RuntimeException("Invalid feature! Feature '" + 
lazyFeature.getFeatureName()
-                  + "' is not defined for type '" + featureStructure.getType() 
+ "' in script " + context.getParent().getName() + ".");
+                  + "' is not defined for type '" + featureStructure.getType() 
+ "' in script "
+                  + context.getParent().getName() + ".");
         } else {
           currentFeature = delegate;
         }
@@ -232,15 +244,15 @@ public class SimpleFeatureExpression ext
         result.add(lastValidFeatureStructure);
       }
     } else {
-      collectFeatureStructures(featureStructure, currentFeature, tail, 
checkOnFeatureValue,
+      this.collectFeatureStructures(featureStructure, currentFeature, tail, 
checkOnFeatureValue,
               collectOnlyAnnotations, lastValidFeatureStructure, result, 
stream, context);
     }
   }
 
-  private <T> void collectFeatureStructures(FeatureStructure featureStructure, 
Feature currentFeature,
-          List<Feature> tail, boolean checkOnFeatureValue, boolean 
collectOnlyAnnotations,
-          T lastValidFeatureStructure, Collection<T> result, RutaStream stream,
-          MatchContext context) {
+  private <T> void collectFeatureStructures(FeatureStructure featureStructure,
+          Feature currentFeature, List<Feature> tail, boolean 
checkOnFeatureValue,
+          boolean collectOnlyAnnotations, T lastValidFeatureStructure, 
Collection<T> result,
+          RutaStream stream, MatchContext context) {
 
     // stop early for match expressions
     if (this instanceof FeatureMatchExpression && (tail == null || 
tail.isEmpty())) {
@@ -265,7 +277,7 @@ public class SimpleFeatureExpression ext
     FeatureStructure value = featureStructure.getFeatureValue(currentFeature);
     if (value instanceof AnnotationFS) {
       AnnotationFS next = (AnnotationFS) value;
-      collectFeatureStructures(next, tail, checkOnFeatureValue, 
collectOnlyAnnotations,
+      this.collectFeatureStructures(next, tail, checkOnFeatureValue, 
collectOnlyAnnotations,
               lastValidFeatureStructure, result, stream, context);
     } else if (value instanceof FSArray && index >= 0) {
       FSArray array = (FSArray) value;
@@ -273,7 +285,7 @@ public class SimpleFeatureExpression ext
         FeatureStructure fs = array.get(index);
         if (fs instanceof AnnotationFS) {
           AnnotationFS next = (AnnotationFS) fs;
-          collectFeatureStructures(next, tail, checkOnFeatureValue, 
collectOnlyAnnotations,
+          this.collectFeatureStructures(next, tail, checkOnFeatureValue, 
collectOnlyAnnotations,
                   lastValidFeatureStructure, result, stream, context);
         }
       }
@@ -281,12 +293,12 @@ public class SimpleFeatureExpression ext
       FSArray array = (FSArray) value;
       for (int i = 0; i < array.size(); i++) {
         FeatureStructure fs = array.get(i);
-        collectFeatureStructures(fs, tail, checkOnFeatureValue, 
collectOnlyAnnotations,
+        this.collectFeatureStructures(fs, tail, checkOnFeatureValue, 
collectOnlyAnnotations,
                 lastValidFeatureStructure, result, stream, context);
       }
     } else if (value != null && !value.getType().isPrimitive()) {
       // feature structure feature values
-      collectFeatureStructures(value, tail, checkOnFeatureValue, 
collectOnlyAnnotations,
+      this.collectFeatureStructures(value, tail, checkOnFeatureValue, 
collectOnlyAnnotations,
               lastValidFeatureStructure, result, stream, context);
     } else if (value != null) {
       // primitive? -> return last annotation for further processing
@@ -297,16 +309,19 @@ public class SimpleFeatureExpression ext
   }
 
   public MatchReference getMatchReference() {
-    return mr;
+
+    return this.mr;
   }
 
   @Override
   public String toString() {
-    return mr.getMatch();
+
+    return this.mr.getMatch();
   }
 
   private Collection<AnnotationFS> filterAnnotations(
           Collection<? extends FeatureStructure> featureStructures) {
+
     Collection<AnnotationFS> result = new 
ArrayList<>(featureStructures.size());
 
     for (FeatureStructure featureStructure : featureStructures) {

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java?rev=1850942&r1=1850941&r2=1850942&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java
 Thu Jan 10 14:47:37 2019
@@ -29,6 +29,7 @@ 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.feature.FeatureExpression;
+import org.apache.uima.ruta.expression.feature.LazyFeature;
 import org.apache.uima.ruta.rule.MatchContext;
 
 public class NumberFeatureExpression extends AbstractNumberExpression {
@@ -72,9 +73,13 @@ public class NumberFeatureExpression ext
       Feature feature = this.fe.getFeature(context, stream);
       Type range = feature.getRange();
       FeatureStructure next = featureStructures.iterator().next();
-      if (next instanceof AnnotationFS && 
!next.getType().equals(annotation.getType())) {
-        feature = this.fe.getFeature(new MatchContext((AnnotationFS) next, 
context.getElement(),
-                context.getRuleMatch(), context.getDirection()), stream);
+//      if (next instanceof AnnotationFS && 
!next.getType().equals(annotation.getType())) {
+//        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);
       }
       if (CAS.TYPE_NAME_BYTE.equals(range.getName())) {
         result = next.getByteValue(feature);

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberListFeatureExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberListFeatureExpression.java?rev=1850942&r1=1850941&r2=1850942&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberListFeatureExpression.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberListFeatureExpression.java
 Thu Jan 10 14:47:37 2019
@@ -34,6 +34,7 @@ import org.apache.uima.cas.IntArrayFS;
 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;
 
 /**
@@ -64,9 +65,13 @@ public class NumberListFeatureExpression
     List<Number> 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 IntArrayFS) {

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java?rev=1850942&r1=1850941&r2=1850942&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java
 Thu Jan 10 14:47:37 2019
@@ -28,6 +28,7 @@ import org.apache.uima.cas.text.Annotati
 import org.apache.uima.ruta.RutaStream;
 import org.apache.uima.ruta.expression.feature.CoveredTextFeature;
 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 StringFeatureExpression extends AbstractStringExpression {
@@ -35,6 +36,7 @@ public class StringFeatureExpression ext
   private FeatureExpression fe;
 
   public StringFeatureExpression(FeatureExpression fe) {
+
     super();
     this.fe = fe;
   }
@@ -49,9 +51,13 @@ public class StringFeatureExpression ext
             false, context, stream);
     if (!featureStructures.isEmpty()) {
       FeatureStructure next = featureStructures.iterator().next();
-      if (next instanceof AnnotationFS && 
!next.getType().equals(annotation.getType())) {
-        feature = this.fe.getFeature(new MatchContext((AnnotationFS) next, 
context.getElement(),
-                context.getRuleMatch(), context.getDirection()), stream);
+      // if (next instanceof AnnotationFS && 
!next.getType().equals(annotation.getType())) {
+      // 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);
       }
       if (next instanceof AnnotationFS && feature instanceof 
CoveredTextFeature) {
         return ((AnnotationFS) next).getCoveredText();

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringListFeatureExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringListFeatureExpression.java?rev=1850942&r1=1850941&r2=1850942&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringListFeatureExpression.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringListFeatureExpression.java
 Thu Jan 10 14:47:37 2019
@@ -32,6 +32,7 @@ import org.apache.uima.cas.StringArrayFS
 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 StringListFeatureExpression
     List<String> 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 StringArrayFS) {


Reply via email to