You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2013/12/23 17:10:56 UTC

svn commit: r1553135 - in /uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta: FilterManager.java RutaStream.java engine/RutaEngine.java rule/RutaTypeMatcher.java

Author: pkluegl
Date: Mon Dec 23 16:10:56 2013
New Revision: 1553135

URL: http://svn.apache.org/r1553135
Log:
UIMA-2332
- replaced stupid method for anchoring

Modified:
    uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java
    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/engine/RutaEngine.java
    uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java?rev=1553135&r1=1553134&r2=1553135&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java Mon Dec 23 16:10:56 2013
@@ -54,6 +54,8 @@ public class FilterManager {
 
   private final CAS cas;
 
+  private Set<Type> currentHiddenTypes;
+
   public FilterManager(Collection<Type> filterTypes, CAS cas) {
     super();
     this.defaultFilterTypes = filterTypes;
@@ -122,7 +124,7 @@ public class FilterManager {
         filterTypes.removeAll(subsumedTypes);
       }
     }
-
+    currentHiddenTypes = filterTypes;
     FSMatchConstraint typeConstraint = createTypeConstraint(filterTypes);
 
     FSMatchConstraint constraint = new NotConstraint(typeConstraint);
@@ -202,4 +204,9 @@ public class FilterManager {
     }
   }
 
+  public Set<Type> getCurrentHiddenTypes() {
+    return currentHiddenTypes;
+  }
+
+  
 }

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=1553135&r1=1553134&r2=1553135&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 Mon Dec 23 16:10:56 2013
@@ -25,6 +25,7 @@ import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.NoSuchElementException;
+import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
 
@@ -40,6 +41,7 @@ import org.apache.uima.cas.text.Annotati
 import org.apache.uima.cas.text.AnnotationIndex;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.ruta.engine.RutaEngine;
 import org.apache.uima.ruta.rule.AbstractRule;
 import org.apache.uima.ruta.rule.AbstractRuleMatch;
 import org.apache.uima.ruta.type.RutaAnnotation;
@@ -81,7 +83,7 @@ public class RutaStream extends FSIterat
   private InferenceCrowd crowd;
 
   private Boolean greedyRuleElement;
-  
+
   private Boolean greedyRule;
 
   protected RutaStream(CAS cas, FSIterator<AnnotationFS> current, Type basicType,
@@ -183,7 +185,7 @@ public class RutaStream extends FSIterat
       }
     } else {
       RutaBasic firstBasic = (RutaBasic) basicIndex.iterator().get();
-      if(firstBasic.isLowMemoryProfile() != lowMemoryProfile) {
+      if (firstBasic.isLowMemoryProfile() != lowMemoryProfile) {
         for (AnnotationFS each : basicIndex) {
           RutaBasic eachBasic = (RutaBasic) each;
           eachBasic.setLowMemoryProfile(lowMemoryProfile);
@@ -231,7 +233,6 @@ public class RutaStream extends FSIterat
     crowd.annotationAdded(annotation, creator);
   }
 
-
   private boolean checkSpan(AnnotationFS annotation) {
     boolean result = false;
     int begin = annotation.getBegin();
@@ -291,7 +292,7 @@ public class RutaStream extends FSIterat
   }
 
   private RutaBasic getCeiling(TreeMap<Integer, RutaBasic> anchors, int anchor) {
-    while(anchor <= anchors.lastKey()) {
+    while (anchor <= anchors.lastKey()) {
       RutaBasic basic = anchors.get(anchor);
       if (basic != null) {
         return basic;
@@ -302,7 +303,7 @@ public class RutaStream extends FSIterat
   }
 
   private RutaBasic getFloor(TreeMap<Integer, RutaBasic> anchors, int anchor) {
-    while(anchor >= 0) {
+    while (anchor >= 0) {
       RutaBasic basic = anchors.get(anchor);
       if (basic != null) {
         return basic;
@@ -703,8 +704,8 @@ public class RutaStream extends FSIterat
 
   public RutaStream getCompleteStream() {
     FilterManager defaultFilter = new FilterManager(filter.getDefaultFilterTypes(), getCas());
-    RutaStream stream = new RutaStream(getCas(), basicIt, basicType, defaultFilter, lowMemoryProfile,
-            simpleGreedyForComposed, crowd);
+    RutaStream stream = new RutaStream(getCas(), basicIt, basicType, defaultFilter,
+            lowMemoryProfile, simpleGreedyForComposed, crowd);
     stream.setDynamicAnchoring(dynamicAnchoring);
     stream.setGreedyRuleElement(greedyRuleElement);
     stream.setGreedyRule(greedyRule);
@@ -734,23 +735,23 @@ public class RutaStream extends FSIterat
   public void setDynamicAnchoring(boolean dynamicAnchoring) {
     this.dynamicAnchoring = dynamicAnchoring;
   }
-  
+
   public boolean isGreedyRuleElement() {
     return greedyRuleElement;
   }
-  
+
   public void setGreedyRuleElement(Boolean greedyAnchoring) {
     this.greedyRuleElement = greedyAnchoring;
   }
-  
+
   public boolean isGreedyRule() {
     return greedyRule;
   }
-  
+
   public void setGreedyRule(Boolean greedyAnchoring) {
     this.greedyRule = greedyAnchoring;
   }
-  
+
   public void setIndexPenalty(double indexPenalty) {
     this.indexPenalty = indexPenalty;
   }
@@ -778,8 +779,24 @@ public class RutaStream extends FSIterat
                     .getEnd())) {
       return false;
     }
-    FSMatchConstraint defaultConstraint = filter.getDefaultConstraint();
-    return defaultConstraint.match(annotationFS);
+    int begin = annotationFS.getBegin();
+    int end = annotationFS.getEnd();
+    Set<Type> currentHiddenTypes = filter.getCurrentHiddenTypes();
+    RutaBasic beginAnchor = getBeginAnchor(begin);
+    for (Type type : currentHiddenTypes) {
+      boolean partOf = beginAnchor.isPartOf(type);
+      if(partOf) {
+        return false;
+      }
+    }
+    RutaBasic endAnchor = getEndAnchor(end);
+    for (Type type : currentHiddenTypes) {
+      boolean partOf = endAnchor.isPartOf(type);
+      if(partOf) {
+        return false;
+      }
+    }
+    return true;
   }
 
   public RutaBasic getAnchor(boolean direction, int pointer) {
@@ -802,6 +819,30 @@ public class RutaStream extends FSIterat
     return greedyRule || greedyRuleElement;
   }
 
+  public Collection<AnnotationFS> getAnnotations(Type type) {
+    Collection<AnnotationFS> result = new LinkedList<AnnotationFS>();
+    AnnotationFS windowAnnotation = filter.getWindowAnnotation();
+    if (windowAnnotation != null
+            && (windowAnnotation.getBegin() != cas.getDocumentAnnotation().getBegin() || windowAnnotation
+                    .getEnd() != cas.getDocumentAnnotation().getEnd())) {
+      AnnotationFS frame = cas.createAnnotation(cas.getTypeSystem().getType(RutaEngine.FRAME_TYPE),
+              windowAnnotation.getBegin(), windowAnnotation.getEnd());
+      FSIterator<AnnotationFS> subiterator = cas.getAnnotationIndex(type).subiterator(frame);
+      while (subiterator.hasNext()) {
+        AnnotationFS each = (AnnotationFS) subiterator.next();
+        if (isVisible(each)) {
+          result.add(each);
+        }
+      }
+    } else {
+      AnnotationIndex<AnnotationFS> annotationIndex = cas.getAnnotationIndex(type);
+      for (AnnotationFS each : annotationIndex) {
+        if (isVisible(each)) {
+          result.add(each);
+        }
+      }
+    }
+    return result;
+  }
 
-  
 }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java?rev=1553135&r1=1553134&r2=1553135&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java Mon Dec 23 16:10:56 2013
@@ -82,6 +82,8 @@ public class RutaEngine extends JCasAnno
   public static final String BASIC_TYPE = "org.apache.uima.ruta.type.RutaBasic";
 
   public static final String OPTIONAL_TYPE = "org.apache.uima.ruta.type.RutaOptional";
+  
+  public static final String FRAME_TYPE = "org.apache.uima.ruta.type.RutaFrame";
 
   /**
    * Load script in Java notation, with "{@code .}" as package separator and no extension. File

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java?rev=1553135&r1=1553134&r2=1553135&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java Mon Dec 23 16:10:56 2013
@@ -72,23 +72,7 @@ public class RutaTypeMatcher implements 
         // TODO what about dynamic windowing?
         annotations.add(stream.getDocumentAnnotation());
       } else {
-        stream.moveToFirst();
-        while (stream.isValid()) {
-          RutaBasic nextBasic = (RutaBasic) stream.get();
-          List<Type> allTypes = stream.getCas().getTypeSystem().getProperlySubsumedTypes(type);
-          allTypes.add(type);
-          for (Type eachType : allTypes) {
-            Collection<AnnotationFS> beginAnchors = nextBasic.getBeginAnchors(eachType);
-            if (beginAnchors != null) {
-              for (AnnotationFS afs : beginAnchors) {
-                if (afs.getEnd() <= stream.getDocumentAnnotation().getEnd()) {
-                  annotations.add(afs);
-                }
-              }
-            }
-          }
-          stream.moveToNext();
-        }
+        annotations.addAll(stream.getAnnotations(type));
       }
     }
     FeatureExpression featureExpression = mr.getFeatureExpression(parent, stream);