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 2012/11/07 10:36:56 UTC

svn commit: r1406511 - in /uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker: TextMarkerStream.java action/ExecAction.java condition/PositionCondition.java

Author: pkluegl
Date: Wed Nov  7 09:36:55 2012
New Revision: 1406511

URL: http://svn.apache.org/viewvc?rev=1406511&view=rev
Log:
no jira
- some formatting in TextMarkerStream
- added check on null in PositionCondition
- removed redundant index operation in ExecAction

Modified:
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/action/ExecAction.java
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/condition/PositionCondition.java

Modified: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java?rev=1406511&r1=1406510&r2=1406511&view=diff
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java (original)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java Wed Nov  7 09:36:55 2012
@@ -86,9 +86,9 @@ public class TextMarkerStream extends FS
 
   private InferenceCrowd crowd;
 
-
   protected TextMarkerStream(CAS cas, FSIterator<AnnotationFS> current, Type basicType,
-          FilterManager filter, boolean lowMemoryProfile, boolean simpleGreedyForComposed, InferenceCrowd crowd) {
+          FilterManager filter, boolean lowMemoryProfile, boolean simpleGreedyForComposed,
+          InferenceCrowd crowd) {
     super();
     this.cas = cas;
     this.filter = filter;
@@ -139,7 +139,8 @@ public class TextMarkerStream extends FS
     currentIt = filter.createFilteredIterator(cas, basicType);
   }
 
-  public TextMarkerStream(CAS cas, Type basicType, FilterManager filter, boolean lowMemoryProfile, boolean simpleGreedyForComposed, InferenceCrowd crowd) {
+  public TextMarkerStream(CAS cas, Type basicType, FilterManager filter, boolean lowMemoryProfile,
+          boolean simpleGreedyForComposed, InferenceCrowd crowd) {
     this(cas, null, basicType, filter, lowMemoryProfile, simpleGreedyForComposed, crowd);
   }
 
@@ -177,16 +178,15 @@ public class TextMarkerStream extends FS
 
   public void addAnnotation(AnnotationFS annotation, boolean update, RuleMatch creator) {
     Type type = annotation.getType();
-    Type parent = type;
     boolean modified = checkSpan(annotation);
     if (modified) {
       updateIterators(filter.getWindowAnnotation());
     }
     TextMarkerBasic beginAnchor = getBeginAnchor(annotation.getBegin());
     TextMarkerBasic endAnchor = getEndAnchor(annotation.getEnd());
-    beginAnchor.addBegin(annotation, parent);
-    if(endAnchor!= null) {
-      endAnchor.addEnd(annotation, parent);
+    beginAnchor.addBegin(annotation, type);
+    if (endAnchor != null) {
+      endAnchor.addEnd(annotation, type);
     }
     Collection<TextMarkerBasic> basicAnnotationsInWindow = getAllBasicsInWindow(annotation);
     for (TextMarkerBasic basic : basicAnnotationsInWindow) {
@@ -268,12 +268,14 @@ public class TextMarkerStream extends FS
     FilterManager filterManager = new FilterManager(filter.getDefaultFilterTypes(),
             filter.getCurrentFilterTypes(), filter.getCurrentRetainTypes(), windowAnnotation,
             windowType, cas);
-    TextMarkerStream stream = new TextMarkerStream(cas, basicIt, basicType, filterManager, lowMemoryProfile,simpleGreedyForComposed, crowd);
+    TextMarkerStream stream = new TextMarkerStream(cas, basicIt, basicType, filterManager,
+            lowMemoryProfile, simpleGreedyForComposed, crowd);
     return stream;
   }
 
   public FSIterator<AnnotationFS> copy() {
-    return new TextMarkerStream(cas, currentIt.copy(), basicType, filter, lowMemoryProfile,simpleGreedyForComposed, crowd);
+    return new TextMarkerStream(cas, currentIt.copy(), basicType, filter, lowMemoryProfile,
+            simpleGreedyForComposed, crowd);
   }
 
   public AnnotationFS get() throws NoSuchElementException {
@@ -423,7 +425,7 @@ public class TextMarkerStream extends FS
   }
 
   public Collection<TextMarkerBasic> getAllBasicsInWindow(AnnotationFS windowAnnotation) {
-    if(windowAnnotation.getBegin() >= windowAnnotation.getEnd()) {
+    if (windowAnnotation.getBegin() >= windowAnnotation.getEnd()) {
       return Collections.emptySet();
     }
     TextMarkerBasic beginAnchor = getBeginAnchor(windowAnnotation.getBegin());
@@ -457,25 +459,24 @@ public class TextMarkerStream extends FS
   }
 
   public TextMarkerBasic getBasicNextTo(boolean before, AnnotationFS annotation) {
-    if(before) {
+    if (before) {
       TextMarkerBasic pointer = beginAnchors.get(annotation.getBegin());
       moveTo(pointer);
       moveToPrevious();
-      if(isValid()) {
-        return (TextMarkerBasic)get();
+      if (isValid()) {
+        return (TextMarkerBasic) get();
       }
     } else {
       TextMarkerBasic pointer = endAnchors.get(annotation.getEnd());
       moveTo(pointer);
       moveToNext();
-      if(isValid()) {
-        return (TextMarkerBasic)get();
+      if (isValid()) {
+        return (TextMarkerBasic) get();
       }
     }
     return null;
   }
-  
-  
+
   public List<TextMarkerBasic> getBasicsInWindow(AnnotationFS windowAnnotation) {
     List<TextMarkerBasic> result = new ArrayList<TextMarkerBasic>();
     if (windowAnnotation instanceof TextMarkerBasic) {
@@ -643,7 +644,8 @@ public class TextMarkerStream extends FS
 
   public TextMarkerStream getCompleteStream() {
     FilterManager defaultFilter = new FilterManager(filter.getDefaultFilterTypes(), getCas());
-    return new TextMarkerStream(getCas(), basicIt, basicType, defaultFilter, lowMemoryProfile,simpleGreedyForComposed, crowd);
+    return new TextMarkerStream(getCas(), basicIt, basicType, defaultFilter, lowMemoryProfile,
+            simpleGreedyForComposed, crowd);
   }
 
   public int getHistogram(Type type) {
@@ -683,7 +685,7 @@ public class TextMarkerStream extends FS
   }
 
   public boolean isSimpleGreedyForComposed() {
-       return simpleGreedyForComposed;
+    return simpleGreedyForComposed;
   }
 
   public void setSimpleGreedyForComposed(boolean simpleGreedyForComposed) {

Modified: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/action/ExecAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/action/ExecAction.java?rev=1406511&r1=1406510&r2=1406511&view=diff
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/action/ExecAction.java (original)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/action/ExecAction.java Wed Nov  7 09:36:55 2012
@@ -95,9 +95,7 @@ public class ExecAction extends CallActi
         Set<Entry<TextMarkerBasic, Collection<AnnotationFS>>> entrySet = map.entrySet();
         for (Entry<TextMarkerBasic, Collection<AnnotationFS>> entry : entrySet) {
           for (AnnotationFS each : entry.getValue()) {
-            cas.removeFsFromIndexes(each);
-            stream.removeAnnotation(entry.getKey(), each.getType());
-            cas.addFsToIndexes(each);
+            stream.removeAnnotation(each);
             stream.addAnnotation(each, match);
           }
         }

Modified: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/condition/PositionCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/condition/PositionCondition.java?rev=1406511&r1=1406510&r2=1406511&view=diff
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/condition/PositionCondition.java (original)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/condition/PositionCondition.java Wed Nov  7 09:36:55 2012
@@ -55,14 +55,14 @@ public class PositionCondition extends T
 
     TextMarkerBasic beginAnchor = stream.getBeginAnchor(annotation.getBegin());
     TextMarkerBasic endAnchor = stream.getEndAnchor(annotation.getEnd());
-    if (!beginAnchor.isPartOf(t) || !endAnchor.isPartOf(t)) {
+    if (beginAnchor == null || endAnchor == null || !beginAnchor.isPartOf(t)
+            || !endAnchor.isPartOf(t)) {
       return new EvaluatedCondition(this, false);
     }
 
     boolean relatively = relative == null ? true : relative.getBooleanValue(element.getParent());
 
-    FSIterator<AnnotationFS> iterator = stream.getCas().getAnnotationIndex(t)
-            .iterator(beginAnchor);
+    FSIterator<AnnotationFS> iterator = stream.getCas().getAnnotationIndex(t).iterator(beginAnchor);
     if (!iterator.isValid()) {
       iterator.moveToNext();
     }
@@ -79,16 +79,15 @@ public class PositionCondition extends T
       }
       iterator.moveToPrevious();
     }
-    
-    
+
     List<Type> targetTypes = new ArrayList<Type>();
-    if(element instanceof TextMarkerRuleElement) {
+    if (element instanceof TextMarkerRuleElement) {
       TextMarkerRuleElement re = (TextMarkerRuleElement) element;
       targetTypes.addAll(re.getMatcher().getTypes(element.getParent(), stream));
     } else {
       targetTypes.add(annotation.getType());
     }
-    
+
     if (window == null) {
       return new EvaluatedCondition(this, false);
     }
@@ -97,15 +96,15 @@ public class PositionCondition extends T
       int counter = 0;
       List<TextMarkerBasic> inWindow = stream.getBasicsInWindow(window);
       for (TextMarkerBasic each : inWindow) {
-        if(beginsWith(each, targetTypes)) {
+        if (beginsWith(each, targetTypes)) {
           counter++;
-          if(counter == integerValue) {
-            if(each.getBegin() == beginAnchor.getBegin()) {
+          if (counter == integerValue) {
+            if (each.getBegin() == beginAnchor.getBegin()) {
               return new EvaluatedCondition(this, true);
             } else {
               return new EvaluatedCondition(this, false);
             }
-          } else if(counter > integerValue) {
+          } else if (counter > integerValue) {
             return new EvaluatedCondition(this, false);
           }
         }
@@ -129,7 +128,7 @@ public class PositionCondition extends T
 
   private boolean beginsWith(TextMarkerBasic each, List<Type> targetTypes) {
     for (Type type : targetTypes) {
-      if(each.beginsWith(type)) {
+      if (each.beginsWith(type)) {
         return true;
       }
     }