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 2015/02/13 21:36:47 UTC

svn commit: r1659669 - /uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ShiftAction.java

Author: pkluegl
Date: Fri Feb 13 20:36:46 2015
New Revision: 1659669

URL: http://svn.apache.org/r1659669
Log:
UIMA-4245
- check on window for anchored annotations

Modified:
    uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ShiftAction.java

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ShiftAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ShiftAction.java?rev=1659669&r1=1659668&r2=1659669&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ShiftAction.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ShiftAction.java Fri Feb 13 20:36:46 2015
@@ -33,6 +33,7 @@ import org.apache.uima.ruta.expression.t
 import org.apache.uima.ruta.rule.AnnotationComparator;
 import org.apache.uima.ruta.rule.RuleElement;
 import org.apache.uima.ruta.rule.RuleMatch;
+import org.apache.uima.ruta.type.RutaBasic;
 import org.apache.uima.ruta.visitor.InferenceCrowd;
 
 public class ShiftAction extends MarkAction {
@@ -51,6 +52,11 @@ public class ShiftAction extends MarkAct
             .getMatchedAnnotationsOf(element);
     int size = Math.min(annotationsMatchedByRuleElementofAction.size(),
             destinationAnnotationSpans.size());
+
+    RutaBasic firstBasicOfAll = stream.getFirstBasicOfAll();
+    RutaBasic lastBasicOfAll = stream.getLastBasicOfAll();
+    int windowBegin = firstBasicOfAll == null ? 0 : firstBasicOfAll.getBegin();
+    int windowEnd = lastBasicOfAll == null ? 0 : lastBasicOfAll.getEnd();
     for (int i = 0; i < size; i++) {
       AnnotationFS eachMatched = annotationsMatchedByRuleElementofAction.get(i);
       AnnotationFS eachDestination = destinationAnnotationSpans.get(i);
@@ -58,16 +64,19 @@ public class ShiftAction extends MarkAct
               new AnnotationComparator());
       Collection<AnnotationFS> beginAnchors = stream.getBeginAnchor(eachMatched.getBegin())
               .getBeginAnchors(targetType);
-      Collection<AnnotationFS> endAnchors = stream.getEndAnchor(eachMatched.getEnd()).getEndAnchors(
-              targetType);
+      Collection<AnnotationFS> endAnchors = stream.getEndAnchor(eachMatched.getEnd())
+              .getEndAnchors(targetType);
       allAnchoredAnnotations.addAll(beginAnchors);
       allAnchoredAnnotations.addAll(endAnchors);
+
       for (AnnotationFS eachAnchored : allAnchoredAnnotations) {
-        Annotation a = (Annotation) eachAnchored;
-        stream.removeAnnotation(a);
-        a.setBegin(eachDestination.getBegin());
-        a.setEnd(eachDestination.getEnd());
-        stream.addAnnotation(a, true, match);
+        if (eachAnchored.getBegin() >= windowBegin && eachAnchored.getEnd() <= windowEnd) {
+          Annotation a = (Annotation) eachAnchored;
+          stream.removeAnnotation(a);
+          a.setBegin(eachDestination.getBegin());
+          a.setEnd(eachDestination.getEnd());
+          stream.addAnnotation(a, true, match);
+        }
       }
     }
   }