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/12/06 14:24:58 UTC

svn commit: r1417839 - in /uima/sandbox/trunk/TextMarker/uimaj-textmarker/src: main/java/org/apache/uima/textmarker/rule/ main/java/org/apache/uima/textmarker/rule/quantifier/ test/java/org/apache/uima/textmarker/ test/resources/org/apache/uima/textmar...

Author: pkluegl
Date: Thu Dec  6 13:24:57 2012
New Revision: 1417839

URL: http://svn.apache.org/viewvc?rev=1417839&view=rev
Log:
UIMA-2514
- fixed min/max reluctant quantifier
- added test

Added:
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest3.java
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/QuantifierTest3.tm
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/QuantifierTest3.txt
Modified:
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRuleElement.java
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/MinMaxReluctant.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/rule/TextMarkerRuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRuleElement.java?rev=1417839&r1=1417838&r2=1417839&view=diff
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRuleElement.java (original)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRuleElement.java Thu Dec  6 13:24:57 2012
@@ -121,6 +121,13 @@ public class TextMarkerRuleElement exten
       RuleMatch extendedMatch = ruleMatch;
       extendedMatch.update(extendedContainerMatch);
       while (!stopMatching) {
+        if (!quantifier.continueMatch(after, eachAnchor, this, extendedMatch,
+                extendedContainerMatch, stream, crowd)) {
+          stopMatching = true;
+          stepbackMatch(after, lastAnchor, extendedMatch, ruleApply, extendedContainerMatch,
+                  sideStepOrigin, stream, crowd, entryPoint);
+          break;
+        }
         Collection<AnnotationFS> nextAnnotations = getNextAnnotations(after, eachAnchor, stream);
         if (nextAnnotations.size() == 1) {
           lastAnchor = eachAnchor;

Modified: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/MinMaxReluctant.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/MinMaxReluctant.java?rev=1417839&r1=1417838&r2=1417839&view=diff
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/MinMaxReluctant.java (original)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/quantifier/MinMaxReluctant.java Thu Dec  6 13:24:57 2012
@@ -110,9 +110,9 @@ public class MinMaxReluctant implements 
     nextElement.continueMatch(after, annotation, extendedMatch, null, extendedContainerMatch, null,
             nextElement, stream, crowd);
     List<RuleElementMatch> nextList = extendedContainerMatch.getInnerMatches().get(nextElement);
-    boolean nextMatched = (nextList == null || nextList.isEmpty());
+    boolean nextMatched = (nextList != null && !nextList.isEmpty());
 
-    return matchedSize < maxValue
+    return (matchedSize < maxValue && matchedSize >= minValue && !nextMatched)
             || (!lastMatch.matched() && matchedSize >= minValue && matchedSize <= maxValue && !nextMatched);
   }
 

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=1417839&r1=1417838&r2=1417839&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 Thu Dec  6 13:24:57 2012
@@ -30,7 +30,7 @@ import org.junit.runners.Suite.SuiteClas
 @RunWith(Suite.class)
 @SuiteClasses({ DynamicAnchoringTest.class, DynamicAnchoringTest2.class, FilteringTest.class,
     LiteralStringMatchTest.class, LongGreedyTest.class, OutOfWindowTest.class,
-    QuantifierTest1.class, QuantifierTest2.class, RuleInferenceTest.class,
+    QuantifierTest1.class, QuantifierTest2.class, QuantifierTest3.class, RuleInferenceTest.class,
     RuleInferenceTest2.class, RuleInferenceTest3.class, AllActionsTest.class,
     AllConditionsTest.class, CurrentCountTest.class,
     PartOfTest.class, PositionTest.class, DefaultSeederTest.class })

Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest3.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest3.java?rev=1417839&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest3.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest3.java Thu Dec  6 13:24:57 2012
@@ -0,0 +1,66 @@
+/*
+ * 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 QuantifierTest3 {
+  @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("Big Big Big", iterator.next().getCoveredText());
+
+    t = TextMarkerTestUtils.getTestType(cas, 2);
+    ai = cas.getAnnotationIndex(t);
+    assertEquals(1, ai.size());
+    iterator = ai.iterator();
+    assertEquals("Big Big Big", iterator.next().getCoveredText());
+
+    t = TextMarkerTestUtils.getTestType(cas, 3);
+    ai = cas.getAnnotationIndex(t);
+    assertEquals(0, ai.size());
+
+
+  }
+}

Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/QuantifierTest3.tm
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/QuantifierTest3.tm?rev=1417839&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/QuantifierTest3.tm (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/QuantifierTest3.tm Thu Dec  6 13:24:57 2012
@@ -0,0 +1,9 @@
+PACKAGE org.apache.uima;
+
+
+DECLARE T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17;
+SW CW[2,100]?{-> MARK(T1)} SW;
+SW W[2,100]?{-> MARK(T2)} SW;
+SW W[4,5]?{-> MARK(T3)} SW;
+
+

Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/QuantifierTest3.txt
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/QuantifierTest3.txt?rev=1417839&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/QuantifierTest3.txt (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/QuantifierTest3.txt Thu Dec  6 13:24:57 2012
@@ -0,0 +1 @@
+123 456 small Big Big Big small Big.
\ No newline at end of file