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 2016/01/22 14:19:10 UTC
svn commit: r1726204 - in /uima/ruta/trunk/ruta-core/src:
main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java
test/java/org/apache/uima/ruta/QuantifierTest.java
Author: pkluegl
Date: Fri Jan 22 13:19:09 2016
New Revision: 1726204
URL: http://svn.apache.org/viewvc?rev=1726204&view=rev
Log:
UIMA-4758
- fixed quantifier
- added test
Added:
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest.java (with props)
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java?rev=1726204&r1=1726203&r2=1726204&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java Fri Jan 22 13:19:09 2016
@@ -91,23 +91,22 @@ public class MinMaxReluctant extends Abs
int minValue = min.getIntegerValue(context, stream);
int maxValue = max.getIntegerValue(context, stream);
List<RuleElementMatch> list = containerMatch.getInnerMatches().get(ruleElement);
+ int matchedSize = list != null ? list.size() : 0;
if (list == null) {
- if (maxValue > 0) {
+ if (maxValue > 0 && minValue != 0) {
return true;
- } else {
- return false;
}
- }
-
- int matchedSize = list.size();
- if (list == null || list.isEmpty() || matchedSize < minValue) {
+ } else if (matchedSize < minValue) {
return true;
}
+
RuleElementMatch lastMatch = null;
- if (after) {
- lastMatch = list.get(list.size() - 1);
- } else {
- lastMatch = list.get(0);
+ if (list != null) {
+ if (after) {
+ lastMatch = list.get(list.size() - 1);
+ } else {
+ lastMatch = list.get(0);
+ }
}
RuleElement nextElement = ruleElement.getContainer().getNextElement(after, ruleElement);
@@ -122,7 +121,8 @@ public class MinMaxReluctant extends Abs
boolean nextMatched = nextElementMatched(nextElement, continueMatch);
return (matchedSize < maxValue && matchedSize >= minValue && !nextMatched)
- || (!lastMatch.matched() && matchedSize >= minValue && matchedSize <= maxValue && !nextMatched);
+ || (lastMatch != null && !lastMatch.matched() && matchedSize >= minValue
+ && matchedSize <= maxValue && !nextMatched);
}
@Override
Added: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest.java?rev=1726204&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest.java (added)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest.java Fri Jan 22 13:19:09 2016
@@ -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.ruta;
+
+import java.io.IOException;
+
+import junit.framework.Assert;
+
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CASException;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.ruta.engine.Ruta;
+import org.apache.uima.ruta.engine.RutaTestUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.junit.Test;
+
+public class QuantifierTest {
+
+ @Test
+ public void testRightToLeftMinMaxReluctantToLiteral() throws CASException, ResourceInitializationException, InvalidXMLException,
+ IOException, AnalysisEngineProcessException {
+
+ JCas jcas = RutaTestUtils.getCAS("a b c d e.").getJCas();
+ Assert.assertEquals("a b c d e.", Ruta.select(jcas, "\"a\" W[0,5]? @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("b c d e.", Ruta.select(jcas, "\"b\" W[0,5]? @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("c d e.", Ruta.select(jcas, "\"c\" W[0,5]? @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("d e.", Ruta.select(jcas, "\"d\" W[0,5]? @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("e.", Ruta.select(jcas, "\"e\" W[0,5]? @PERIOD;").get(0).getCoveredText());
+
+ jcas.release();
+ }
+
+ @Test
+ public void testRightToLeftMinMaxGreedyToLiteral() throws CASException, ResourceInitializationException, InvalidXMLException,
+ IOException, AnalysisEngineProcessException {
+
+ JCas jcas = RutaTestUtils.getCAS("a b c d e.").getJCas();
+ Assert.assertEquals("a b c d e.", Ruta.select(jcas, "\"a\" W[0,4] @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("b c d e.", Ruta.select(jcas, "\"b\" W[0,3] @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("c d e.", Ruta.select(jcas, "\"c\" W[0,2] @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("d e.", Ruta.select(jcas, "\"d\" W[0,1] @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("e.", Ruta.select(jcas, "\"e\" W[0,0] @PERIOD;").get(0).getCoveredText());
+
+ jcas.release();
+ }
+
+
+}
Propchange: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest.java
------------------------------------------------------------------------------
svn:eol-style = native