Author: pkluegl
Date: Sat May 11 17:37:41 2013
New Revision: 1481384

URL: http://svn.apache.org/r1481384
Log:
UIMA-2758
- return feature that actually needs to be checked
- allow anchoring without feature check: improves explanation of inference

Modified:
    
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
    
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java

Modified: 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java?rev=1481384&r1=1481383&r2=1481384&view=diff
==============================================================================
--- 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
 (original)
+++ 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
 Sat May 11 17:37:41 2013
@@ -15,7 +15,7 @@
  * 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.feature;
 
@@ -31,6 +31,7 @@ import org.apache.uima.ruta.expression.t
 public class SimpleFeatureExpression extends FeatureExpression {
 
   private TypeExpression typeExpr;
+
   private List<String> features;
 
   public SimpleFeatureExpression(TypeExpression te, List<String> 
featureReferences) {
@@ -42,12 +43,18 @@ public class SimpleFeatureExpression ext
   public SimpleFeatureExpression(TypeExpression te, String[] 
featureReferences) {
     this(te, Arrays.asList(featureReferences));
   }
-  
+
   @Override
   public Feature getFeature(RutaStatement parent) {
-    return getFeatures(parent).get(0);
+    List<Feature> features = getFeatures(parent);
+    if (!features.isEmpty()) {
+      return features.get(features.size() - 1);
+    } else {
+      return null;
+    }
+
   }
-  
+
   @Override
   public List<Feature> getFeatures(RutaStatement parent) {
     List<Feature> result = new ArrayList<Feature>();
@@ -60,7 +67,7 @@ public class SimpleFeatureExpression ext
     }
     return result;
   }
-  
+
   public TypeExpression getTypeExpr() {
     return typeExpr;
   }
@@ -77,6 +84,4 @@ public class SimpleFeatureExpression ext
     this.features = features;
   }
 
-
-  
 }

Modified: 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java?rev=1481384&r1=1481383&r2=1481384&view=diff
==============================================================================
--- 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
 (original)
+++ 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
 Sat May 11 17:37:41 2013
@@ -48,6 +48,8 @@ import org.apache.uima.ruta.type.RutaBas
 
 public class RutaTypeMatcher implements RutaMatcher {
 
+  private static final boolean CHECK_ON_FEATURE = false;
+
   protected final MatchReference mr;
 
   protected AnnotationComparator comparator;
@@ -94,7 +96,6 @@ public class RutaTypeMatcher implements 
         }
       }
     }
-    Collection<AnnotationFS> result = new TreeSet<AnnotationFS>(comparator);
     FeatureExpression featureExpression = mr.getFeatureExpression(parent, 
stream);
     if (featureExpression != null) {
       return getFeatureAnnotations(annotations, featureExpression, stream, 
parent);
@@ -110,11 +111,14 @@ public class RutaTypeMatcher implements 
     for (AnnotationFS eachBase : annotations) {
       AnnotationFS afs = eachBase;
       for (Feature feature : features) {
-        if (feature.getRange().isPrimitive()
-                && featureExpression instanceof FeatureMatchExpression) {
+        if (feature.getRange().isPrimitive() && featureExpression instanceof 
FeatureMatchExpression) {
           FeatureMatchExpression fme = (FeatureMatchExpression) 
featureExpression;
           RutaExpression arg = fme.getArg();
-          if (checkFeatureValue(afs, feature, arg, stream, parent)) {
+          if (CHECK_ON_FEATURE) {
+            if (checkFeatureValue(afs, feature, arg, stream, parent)) {
+              result.add(afs);
+            }
+          } else {
             result.add(afs);
           }
           break;
@@ -159,7 +163,7 @@ public class RutaTypeMatcher implements 
         }
       }
       FeatureExpression fm = mr.getFeatureExpression(parent, stream);
-      if(fm != null) {
+      if (fm != null) {
         return getFeatureAnnotations(anchors, fm, stream, parent);
       } else {
         return anchors;
@@ -197,7 +201,7 @@ public class RutaTypeMatcher implements 
         }
       }
       FeatureExpression fm = mr.getFeatureExpression(parent, stream);
-      if(fm != null) {
+      if (fm != null) {
         return getFeatureAnnotations(anchors, fm, stream, parent);
       } else {
         return anchors;
@@ -229,21 +233,18 @@ public class RutaTypeMatcher implements 
       return false;
     }
     FeatureExpression featureExpression = mr.getFeatureExpression(parent, 
stream);
-    if(featureExpression ==null) {
+    if (featureExpression == null) {
       boolean b = checkType(annotation, stream, parent);
-      if(b) {
+      if (b) {
         return true;
       }
     } else {
-      List<Type> types = getTypes(parent, stream);
-      for (Type type : types) {
-        boolean b = checkFeature(annotation,  stream,  parent);
-        if(b) {
-          return true;
-        }
+      boolean b = checkFeature(annotation, stream, parent);
+      if (b) {
+        return true;
       }
     }
-   
+
     return false;
 
   }
@@ -267,16 +268,17 @@ public class RutaTypeMatcher implements 
   private boolean checkFeature(AnnotationFS annotation, RutaStream stream, 
RutaBlock parent) {
     FeatureExpression fe = mr.getFeatureExpression(parent, stream);
     Feature feature = fe.getFeature(parent);
-    if(fe instanceof FeatureMatchExpression) {
+    if (fe instanceof FeatureMatchExpression) {
       FeatureMatchExpression fme = (FeatureMatchExpression) fe;
-      boolean checkFeatureValue = checkFeatureValue(annotation, feature, 
fme.getArg(), stream, parent);
-      if(checkFeatureValue) {
+      boolean checkFeatureValue = checkFeatureValue(annotation, feature, 
fme.getArg(), stream,
+              parent);
+      if (checkFeatureValue) {
         return true;
       }
     } else {
       TypeSystem typeSystem = stream.getCas().getTypeSystem();
       boolean subsumes = typeSystem.subsumes(feature.getRange(), 
annotation.getType());
-      if(subsumes) {
+      if (subsumes) {
         return true;
       }
     }


Reply via email to