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/14 18:13:13 UTC

svn commit: r1558113 - in /uima/ruta/trunk: ruta-core/src/main/java/org/apache/uima/ruta/ ruta-core/src/main/java/org/apache/uima/ruta/rule/ ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ ruta-ep-addons/src/main/java/org/apache/uima/ruta/expla...

Author: pkluegl
Date: Tue Jan 14 17:13:13 2014
New Revision: 1558113

URL: http://svn.apache.org/r1558113
Log:
UIMA-3286
- fixed sidestep for dynamic or manual anchoring
- removed unused methods
- fixed anchor visualization in applied rules view

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/rule/RuleElementCaretaker.java
    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/verbalize/ScriptVerbalizer.java
    uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/element/ElementTreeLabelProvider.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=1558113&r1=1558112&r2=1558113&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 Tue Jan 14 17:13:13 2014
@@ -282,28 +282,6 @@ public class RutaStream extends FSIterat
     return false;
   }
 
-  private RutaBasic getCeiling(TreeMap<Integer, RutaBasic> anchors, int anchor) {
-    while (anchor <= anchors.lastKey()) {
-      RutaBasic basic = anchors.get(anchor);
-      if (basic != null) {
-        return basic;
-      }
-      anchor++;
-    }
-    return null;
-  }
-
-  private RutaBasic getFloor(TreeMap<Integer, RutaBasic> anchors, int anchor) {
-    while (anchor >= 0) {
-      RutaBasic basic = anchors.get(anchor);
-      if (basic != null) {
-        return basic;
-      }
-      anchor--;
-    }
-    return null;
-  }
-
   public void removeAnnotation(AnnotationFS annotationFS) {
     removeAnnotation(annotationFS, annotationFS.getType());
   }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java?rev=1558113&r1=1558112&r2=1558113&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java Tue Jan 14 17:13:13 2014
@@ -59,7 +59,9 @@ public class RuleElementCaretaker implem
 
   public RuleElement getAnchoringRuleElement(RutaStream stream) {
     List<RuleElement> ruleElements = container.getRuleElements();
-    if (ruleElements.size() == 1 || containsLiteralMatcher(ruleElements)) {
+    if (ruleElements.size() == 1 
+            //|| containsLiteralMatcher(ruleElements)
+            ) {
       return ruleElements.get(0);
     }
     for (RuleElement ruleElement : ruleElements) {
@@ -93,17 +95,6 @@ public class RuleElementCaretaker implem
 
   }
 
-  private boolean containsLiteralMatcher(List<RuleElement> ruleElements) {
-    for (RuleElement each : ruleElements) {
-      if (each instanceof RutaRuleElement) {
-        RutaRuleElement re = (RutaRuleElement) each;
-        if (re.getMatcher() instanceof RutaLiteralMatcher) {
-          return true;
-        }
-      }
-    }
-    return false;
-  }
 
   public RuleElement getFirstElement() {
     List<RuleElement> ruleElements = container.getRuleElements();

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=1558113&r1=1558112&r2=1558113&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 Tue Jan 14 17:13:13 2014
@@ -59,7 +59,7 @@ public class RutaRuleElement extends Abs
     Collection<AnnotationFS> anchors = getAnchors(stream);
     boolean useAlternatives = anchors.size() != 1;
     for (AnnotationFS eachAnchor : anchors) {
-      if(stream.isGreedyAnchoring() && isAlreadyCovered(eachAnchor, ruleApply, stream)) {
+      if (stream.isGreedyAnchoring() && isAlreadyCovered(eachAnchor, ruleApply, stream)) {
         continue;
       }
       ComposedRuleElementMatch extendedContainerMatch = containerMatch;
@@ -124,17 +124,18 @@ public class RutaRuleElement extends Abs
     List<AbstractRuleMatch<? extends AbstractRule>> list = ruleApply.getList();
     Collections.reverse(list);
     for (AbstractRuleMatch<? extends AbstractRule> each : list) {
-      if(each instanceof RuleMatch) {
+      if (each instanceof RuleMatch) {
         RuleMatch rm = (RuleMatch) each;
         List<AnnotationFS> matchedAnnotationsOf = Collections.emptyList();
-        if(stream.isGreedyRule()) {
+        if (stream.isGreedyRule()) {
           matchedAnnotationsOf = rm.getMatchedAnnotationsOfRoot();
-        } else if(stream.isGreedyRuleElement()) {
+        } else if (stream.isGreedyRuleElement()) {
           matchedAnnotationsOf = rm.getMatchedAnnotationsOf(this);
         }
         for (AnnotationFS annotationFS : matchedAnnotationsOf) {
-          if(eachAnchor.getBegin() >= annotationFS.getBegin() && eachAnchor.getEnd() <= annotationFS.getEnd())
-          return true;
+          if (eachAnchor.getBegin() >= annotationFS.getBegin()
+                  && eachAnchor.getEnd() <= annotationFS.getEnd())
+            return true;
         }
       }
     }
@@ -303,8 +304,7 @@ public class RutaRuleElement extends Abs
         if (getContainer() instanceof ComposedRuleElement) {
           ComposedRuleElement composed = (ComposedRuleElement) getContainer();
           List<RuleMatch> fallbackContinue = composed.fallbackContinue(after, true, annotation,
-                  ruleMatch, ruleApply, containerMatch, sideStepOrigin, entryPoint,
-                  stream, crowd);
+                  ruleMatch, ruleApply, containerMatch, sideStepOrigin, entryPoint, stream, crowd);
           result.addAll(fallbackContinue);
         } else {
           // should never happen!
@@ -322,37 +322,39 @@ public class RutaRuleElement extends Abs
     boolean newDirection = !after;
     List<AnnotationFS> matchedAnnotationsOf = ruleMatch.getMatchedAnnotationsOf(this);
     AnnotationFS annotation = null;
-    if (newDirection) {
-      annotation = matchedAnnotationsOf.get(matchedAnnotationsOf.size() - 1);
-    } else {
-      annotation = matchedAnnotationsOf.get(0);
-    }
-    ComposedRuleElementMatch sideStepContainerMatch = containerMatch;
-    if (!containerMatch.getRuleElement().equals(getContainer())) {
-      List<List<RuleElementMatch>> matchInfo = ruleMatch
-              .getMatchInfo((ComposedRuleElement) getContainer());
+    if (!matchedAnnotationsOf.isEmpty()) {
       if (newDirection) {
-        List<RuleElementMatch> list = matchInfo.get(matchInfo.size() - 1);
-        sideStepContainerMatch = (ComposedRuleElementMatch) list.get(list.size() - 1);
+        annotation = matchedAnnotationsOf.get(matchedAnnotationsOf.size() - 1);
       } else {
-        List<RuleElementMatch> list = matchInfo.get(0);
-        sideStepContainerMatch = (ComposedRuleElementMatch) list.get(0);
+        annotation = matchedAnnotationsOf.get(0);
+      }
+      ComposedRuleElementMatch sideStepContainerMatch = containerMatch;
+      if (!containerMatch.getRuleElement().equals(getContainer())) {
+        List<List<RuleElementMatch>> matchInfo = ruleMatch
+                .getMatchInfo((ComposedRuleElement) getContainer());
+        if (newDirection) {
+          List<RuleElementMatch> list = matchInfo.get(matchInfo.size() - 1);
+          sideStepContainerMatch = (ComposedRuleElementMatch) list.get(list.size() - 1);
+        } else {
+          List<RuleElementMatch> list = matchInfo.get(0);
+          sideStepContainerMatch = (ComposedRuleElementMatch) list.get(0);
+        }
       }
-    }
 
-    if (quantifier.continueMatch(newDirection, annotation, this, ruleMatch, sideStepContainerMatch,
-            stream, crowd)) {
-      continueMatch(newDirection, annotation, ruleMatch, ruleApply, sideStepContainerMatch, null,
-              entryPoint, stream, crowd);
-    } else {
-      RuleElement nextRuleElement = getContainer().getNextElement(newDirection, this);
-      if (nextRuleElement != null) {
-        result = nextRuleElement.continueMatch(newDirection, annotation, ruleMatch, ruleApply,
-                sideStepContainerMatch, null, null, stream, crowd);
-      } else if (getContainer() instanceof ComposedRuleElement) {
-        ComposedRuleElement composed = (ComposedRuleElement) getContainer();
-        result = composed.fallbackContinue(newDirection, false, annotation, ruleMatch, ruleApply,
-                sideStepContainerMatch, null, entryPoint, stream, crowd);
+      if (quantifier.continueMatch(newDirection, annotation, this, ruleMatch,
+              sideStepContainerMatch, stream, crowd)) {
+        continueMatch(newDirection, annotation, ruleMatch, ruleApply, sideStepContainerMatch, null,
+                entryPoint, stream, crowd);
+      } else {
+        RuleElement nextRuleElement = getContainer().getNextElement(newDirection, this);
+        if (nextRuleElement != null) {
+          result = nextRuleElement.continueMatch(newDirection, annotation, ruleMatch, ruleApply,
+                  sideStepContainerMatch, null, null, stream, crowd);
+        } else if (getContainer() instanceof ComposedRuleElement) {
+          ComposedRuleElement composed = (ComposedRuleElement) getContainer();
+          result = composed.fallbackContinue(newDirection, false, annotation, ruleMatch, ruleApply,
+                  sideStepContainerMatch, null, entryPoint, stream, crowd);
+        }
       }
     }
     return result;
@@ -365,9 +367,9 @@ 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) {
+    if (matcher instanceof RutaTypeMatcher) {
       RutaTypeMatcher rtm = (RutaTypeMatcher) matcher;
       MatchReference mr = (MatchReference) rtm.getExpression();
       FeatureExpression featureExpression = mr.getFeatureExpression(parent, stream);

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ScriptVerbalizer.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ScriptVerbalizer.java?rev=1558113&r1=1558112&r2=1558113&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ScriptVerbalizer.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ScriptVerbalizer.java Tue Jan 14 17:13:13 2014
@@ -112,6 +112,9 @@ public class ScriptVerbalizer {
     List<AbstractRutaAction> actions = re.getActions();
     RuleElementQuantifier quantifier = re.getQuantifier();
     StringBuilder result = new StringBuilder();
+    if(re.isStartAnchor()) {
+      result.append("@");
+    }
     if(re instanceof ConjunctRulesRuleElement) {
       result.append(verbalizeConjunct((ConjunctRulesRuleElement) re));
     } else if (re instanceof ComposedRuleElement) {

Modified: uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/element/ElementTreeLabelProvider.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/element/ElementTreeLabelProvider.java?rev=1558113&r1=1558112&r2=1558113&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/element/ElementTreeLabelProvider.java (original)
+++ uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/element/ElementTreeLabelProvider.java Tue Jan 14 17:13:13 2014
@@ -73,8 +73,7 @@ public class ElementTreeLabelProvider ex
         Feature fanchor = type.getFeatureByBaseName(ExplainConstants.RULE_ANCHOR);
         if (f != null && fanchor != null) {
           String v = fs.getStringValue(f);
-          String ruleAnchor = fs.getBooleanValue(fanchor) ? "@" : "";
-          return ruleAnchor + v;
+          return v;
         }
       } else if (element instanceof RuleElementMatchNode) {
         FeatureStructure fs = debugNode.getFeatureStructure();