Author: pkluegl
Date: Thu Aug  2 13:03:23 2012
New Revision: 1368445

URL: http://svn.apache.org/viewvc?rev=1368445&view=rev
Log:
UIMA-2446
- fixed evaluation of match for ? and *
- added test for greedy optional quantifiers

Added:
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/OptionalComposedEndTest.java
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/OptionalComposedEndTest.tm
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/OptionalComposedEndTest.txt
Modified:
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/QuestionGreedy.java
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/StarGreedy.java

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/QuestionGreedy.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/QuestionGreedy.java?rev=1368445&r1=1368444&r2=1368445&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/QuestionGreedy.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/QuestionGreedy.java
 Thu Aug  2 13:03:23 2012
@@ -41,7 +41,8 @@ public class QuestionGreedy implements R
       return Collections.emptyList();
     }
     for (RuleElementMatch match : matches) {
-      result &= match.matched() || match.getTextsMatched().isEmpty();
+      result &= match.matched()
+              || (!(match instanceof ComposedRuleElementMatch) && 
match.getTextsMatched().isEmpty());
     }
     if (!result) {
       matches.remove(0);

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/StarGreedy.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/StarGreedy.java?rev=1368445&r1=1368444&r2=1368445&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/StarGreedy.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/StarGreedy.java
 Thu Aug  2 13:03:23 2012
@@ -40,13 +40,12 @@ public class StarGreedy implements RuleE
   public List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches,
           TextMarkerStatement element, InferenceCrowd crowd) {
     boolean result = true;
-    boolean allEmpty = true;
     if (matches == null) {
       return null;
     }
     for (RuleElementMatch match : matches) {
-      allEmpty &= match.getTextsMatched().isEmpty();
-      result &= match.getTextsMatched().isEmpty() || match.matched();
+      result &= match.matched()
+              || (!(match instanceof ComposedRuleElementMatch) && 
match.getTextsMatched().isEmpty());
     }
     if (!result && matches.size() > 0) {
       matches.remove(matches.size() - 1);

Added: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/OptionalComposedEndTest.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/OptionalComposedEndTest.java?rev=1368445&view=auto
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/OptionalComposedEndTest.java
 (added)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/OptionalComposedEndTest.java
 Thu Aug  2 13:03:23 2012
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+
+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.junit.Test;
+
+public class OptionalComposedEndTest {
+  @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(3, ai.size());
+    iterator = ai.iterator();
+    assertEquals("20,20", iterator.next().getCoveredText());
+    assertEquals("20", iterator.next().getCoveredText());
+    assertEquals("20,20", iterator.next().getCoveredText());
+
+    t = TextMarkerTestUtils.getTestType(cas, 2);
+    ai = cas.getAnnotationIndex(t);
+    assertEquals(3, ai.size());
+    iterator = ai.iterator();
+    assertEquals("20,20", iterator.next().getCoveredText());
+    assertEquals("20", iterator.next().getCoveredText());
+    assertEquals("20,20", iterator.next().getCoveredText());
+    
+    t = TextMarkerTestUtils.getTestType(cas, 3);
+    ai = cas.getAnnotationIndex(t);
+    assertEquals(3, ai.size());
+    iterator = ai.iterator();
+    assertEquals("20,20", iterator.next().getCoveredText());
+    assertEquals("20", iterator.next().getCoveredText());
+    assertEquals("20,20", iterator.next().getCoveredText());
+    
+  }
+}

Added: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/OptionalComposedEndTest.tm
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/OptionalComposedEndTest.tm?rev=1368445&view=auto
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/OptionalComposedEndTest.tm
 (added)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/OptionalComposedEndTest.tm
 Thu Aug  2 13:03:23 2012
@@ -0,0 +1,6 @@
+PACKAGE org.apache.uima;
+
+DECLARE T1,T2,T3,T4,T5;
+NUM{-PARTOF(T1)-> MARK(T1,1,2)} (COMMA NUM)?;
+NUM{-PARTOF(T2)-> MARK(T2,1,2)} (COMMA NUM)*;
+NUM{-PARTOF(T3)-> MARK(T3,1,2)} (COMMA NUM)[0,1];

Added: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/OptionalComposedEndTest.txt
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/OptionalComposedEndTest.txt?rev=1368445&view=auto
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/OptionalComposedEndTest.txt
 (added)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/OptionalComposedEndTest.txt
 Thu Aug  2 13:03:23 2012
@@ -0,0 +1,3 @@
+some data : 20,20
+some more data : 20
+and again : 20,20
\ No newline at end of file


Reply via email to