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 2014/01/08 16:57:02 UTC

svn commit: r1556562 - in /uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta: rule/RutaRuleElement.java type/RutaBasic.java

Author: pkluegl
Date: Wed Jan  8 15:57:01 2014
New Revision: 1556562

URL: http://svn.apache.org/r1556562
Log:
UIMA-2332
- do not reevaluate the match reference for normal type expressions
- cache the partof relations in int arrays

Modified:
    uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
    uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/type/RutaBasic.java

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java?rev=1556562&r1=1556561&r2=1556562&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java Wed Jan  8 15:57:01 2014
@@ -29,6 +29,8 @@ import org.apache.uima.ruta.RutaBlock;
 import org.apache.uima.ruta.RutaStream;
 import org.apache.uima.ruta.action.AbstractRutaAction;
 import org.apache.uima.ruta.condition.AbstractRutaCondition;
+import org.apache.uima.ruta.expression.MatchReference;
+import org.apache.uima.ruta.expression.feature.FeatureExpression;
 import org.apache.uima.ruta.rule.quantifier.RuleElementQuantifier;
 import org.apache.uima.ruta.visitor.InferenceCrowd;
 
@@ -363,7 +365,16 @@ public class RutaRuleElement extends Abs
     result.setRuleAnchor(ruleAnchor);
     List<EvaluatedCondition> evaluatedConditions = new ArrayList<EvaluatedCondition>(
             conditions.size());
-    boolean base = matcher.match(annotation, stream, getParent());
+//    boolean base = matcher.match(annotation, stream, getParent());
+    boolean base = true;
+    if(matcher instanceof RutaTypeMatcher) {
+      RutaTypeMatcher rtm = (RutaTypeMatcher) matcher;
+      MatchReference mr = (MatchReference) rtm.getExpression();
+      FeatureExpression featureExpression = mr.getFeatureExpression(parent, stream);
+      if (featureExpression != null) {
+        base = matcher.match(annotation, stream, getParent());
+      }
+    }
     List<AnnotationFS> textsMatched = new ArrayList<AnnotationFS>(1);
     if (base) {
       for (AbstractRutaCondition condition : conditions) {

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/type/RutaBasic.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/type/RutaBasic.java?rev=1556562&r1=1556561&r2=1556562&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/type/RutaBasic.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/type/RutaBasic.java Wed Jan  8 15:57:01 2014
@@ -7,10 +7,11 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.TreeMap;
 
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.impl.TypeImpl;
+import org.apache.uima.cas.impl.TypeSystemImpl;
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.JCasRegistry;
@@ -26,7 +27,7 @@ import org.apache.uima.jcas.tcas.Annotat
  */
 public class RutaBasic extends Annotation {
 
-  private static final int INITIAL_CAPACITY = 2;
+  private static final int INITIAL_CAPACITY = 5;
 
   private static final String ROOT_TYPE1 = "uima.tcas.Annotation";
 
@@ -34,7 +35,7 @@ public class RutaBasic extends Annotatio
 
   private boolean lowMemoryProfile = false;
 
-  private Map<String, Integer> partOf = new TreeMap<String, Integer>();
+  private int[] partOf = new int[((TypeSystemImpl) getCAS().getTypeSystem()).getLargestTypeCode()];
 
   private final Map<Type, Set<AnnotationFS>> beginMap = new HashMap<Type, Set<AnnotationFS>>(
           INITIAL_CAPACITY);
@@ -51,47 +52,49 @@ public class RutaBasic extends Annotatio
   }
 
   public void addPartOf(Type type) {
-    Integer count = partOf.get(type.getName());
-    if (count == null) {
-      count = 0;
-    }
-    count++;
-    partOf.put(type.getName(), count);
-    if (!lowMemoryProfile && !type.getName().equals(ROOT_TYPE1)
-            && !type.getName().equals(ROOT_TYPE2)) {
-      TypeSystem typeSystem = getCAS().getTypeSystem();
-      Type parent = typeSystem.getParent(type);
-      if (parent != null) {
-        addPartOf(parent);
+    int code = ((TypeImpl) type).getCode();
+    addPartOf(code);
+  }
+
+  private void addPartOf(int code) {
+    partOf[code] = partOf[code] + 1;
+    if (!lowMemoryProfile) {
+      int parentCode = getCAS().getTypeSystem().getLowLevelTypeSystem().ll_getParentType(code);
+      if (parentCode > 0) {
+        addPartOf(parentCode);
       }
     }
   }
 
   public void removePartOf(Type type) {
-    Integer count = partOf.get(type.getName());
-    if (count != null && count > 0) {
-      count--;
-      partOf.put(type.getName(), count);
+    int code = ((TypeImpl) type).getCode();
+    removePartOf(code);
+  }
+
+  private void removePartOf(int code) {
+    if (partOf[code] != 0) {
+      partOf[code] = partOf[code] - 1;
     }
     if (!lowMemoryProfile) {
-      TypeSystem typeSystem = getCAS().getTypeSystem();
-      Type parent = typeSystem.getParent(type);
-      if (parent != null) {
-        removePartOf(parent);
+      int parentCode = getCAS().getTypeSystem().getLowLevelTypeSystem().ll_getParentType(code);
+      if (parentCode > 0) {
+        removePartOf(parentCode);
       }
     }
   }
 
   public boolean isPartOf(Type type) {
-    Integer count = partOf.get(type.getName());
-    if (count != null && count > 0) {
+    int code = ((TypeImpl) type).getCode();
+    int count = partOf[code];
+    if (count > 0) {
       return true;
     }
     if (lowMemoryProfile) {
       List<Type> subsumedTypes = getCAS().getTypeSystem().getProperlySubsumedTypes(type);
       for (Type each : subsumedTypes) {
-        Integer parentCount = partOf.get(each.getName());
-        if (parentCount != null && parentCount > 0) {
+        int code2 = ((TypeImpl) each).getCode();
+        int count2 = partOf[code2];
+        if (count2 > 0) {
           return true;
         }
       }