Author: pkluegl
Date: Fri Jul  6 12:37:48 2012
New Revision: 1358165

URL: http://svn.apache.org/viewvc?rev=1358165&view=rev
Log:
UIMA-2429
- fixed and added test

Added:
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/condition/
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/condition/CurrentCountTest.java
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/condition/
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/condition/CurrentCountTest.tm
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/condition/CurrentCountTest.txt
Modified:
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/condition/CurrentCountCondition.java
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/condition/CurrentCountCondition.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/condition/CurrentCountCondition.java?rev=1358165&r1=1358164&r2=1358165&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/condition/CurrentCountCondition.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/condition/CurrentCountCondition.java
 Fri Jul  6 12:37:48 2012
@@ -49,11 +49,15 @@ public class CurrentCountCondition exten
   public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element,
           TextMarkerStream stream, InferenceCrowd crowd) {
     int count = 0;
-    Iterator<?> it = 
stream.getJCas().getAnnotationIndex(type.getType(element.getParent()))
+    Iterator<AnnotationFS> it = 
stream.getCas().getAnnotationIndex(type.getType(element.getParent()))
             .iterator();
     while (it.hasNext()) {
-      it.next();
-      count++;
+      AnnotationFS next = it.next();
+      if(next.getBegin() < annotation.getBegin()) {
+        count++;
+      } else {
+        break;
+      }
     }
     if (var != null) {
       element.getParent().getEnvironment().setVariableValue(var, count);

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java?rev=1358165&r1=1358164&r2=1358165&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java
 Fri Jul  6 12:37:48 2012
@@ -1,6 +1,7 @@
 package org.apache.uima.textmarker;
 
 import org.apache.uima.textmarker.action.PartOfTest;
+import org.apache.uima.textmarker.condition.CurrentCountTest;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
@@ -8,7 +9,7 @@ import org.junit.runners.Suite.SuiteClas
 @RunWith(Suite.class)
 @SuiteClasses({ DynamicAnchoringTest.class, DynamicAnchoringTest2.class, 
FilteringTest.class,
     QuantifierTest1.class, QuantifierTest2.class, RuleInferenceTest.class,
-    RuleInferenceTest2.class, RuleInferenceTest3.class, LongGreedyTest.class, 
PartOfTest.class })
+    RuleInferenceTest2.class, RuleInferenceTest3.class, LongGreedyTest.class, 
PartOfTest.class, CurrentCountTest.class })
 public class AllTests {
 
 }

Added: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/condition/CurrentCountTest.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/condition/CurrentCountTest.java?rev=1358165&view=auto
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/condition/CurrentCountTest.java
 (added)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/condition/CurrentCountTest.java
 Fri Jul  6 12:37:48 2012
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.condition;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.textmarker.TextMarkerTestUtils;
+import org.junit.Test;
+
+public class CurrentCountTest {
+
+  @Test
+  public void test() {
+    String name = this.getClass().getSimpleName();
+    String namespace = 
this.getClass().getPackage().getName().replaceAll("\\.", "/");
+    
+    CAS cas = null;
+    try {
+      cas = TextMarkerTestUtils.process(namespace + "/" + name + ".tm", 
namespace + "/" + name
+              + ".txt", 50);
+    } catch (Exception e) {
+      e.printStackTrace();
+      assert (false);
+    }
+    Type t = null;
+    AnnotationIndex<AnnotationFS> ai = null;
+    FSIterator<AnnotationFS> iterator = null;
+
+    t = TextMarkerTestUtils.getTestType(cas, 1);
+    ai = cas.getAnnotationIndex(t);
+    assertEquals(1, ai.size());
+    iterator = ai.iterator();
+    assertEquals("and", iterator.next().getCoveredText());
+ 
+    t = TextMarkerTestUtils.getTestType(cas, 2);
+    ai = cas.getAnnotationIndex(t);
+    assertEquals(1, ai.size());
+    iterator = ai.iterator();
+    assertEquals("Georg", iterator.next().getCoveredText());
+ 
+    t = TextMarkerTestUtils.getTestType(cas, 3);
+    ai = cas.getAnnotationIndex(t);
+    assertEquals(1, ai.size());
+    iterator = ai.iterator();
+    assertEquals("Flo", iterator.next().getCoveredText());
+  }
+}

Added: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/condition/CurrentCountTest.tm
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/condition/CurrentCountTest.tm?rev=1358165&view=auto
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/condition/CurrentCountTest.tm
 (added)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/condition/CurrentCountTest.tm
 Fri Jul  6 12:37:48 2012
@@ -0,0 +1,10 @@
+PACKAGE org.apache.uima;
+
+
+DECLARE T1, T2, T3, T4, T5;
+
+INT count;
+
+W{CURRENTCOUNT(W,3,3) -> MARK(T1)};
+W{CURRENTCOUNT(W,2,8,count), IF((count>3)) -> MARK(T2)};
+W{CURRENTCOUNT(W,2,8,count), IF((count<3)) -> MARK(T3)};
\ No newline at end of file

Added: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/condition/CurrentCountTest.txt
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/condition/CurrentCountTest.txt?rev=1358165&view=auto
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/condition/CurrentCountTest.txt
 (added)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/condition/CurrentCountTest.txt
 Fri Jul  6 12:37:48 2012
@@ -0,0 +1 @@
+Peter, Jochen, Flo and Georg.
\ No newline at end of file


Reply via email to