Author: pkluegl Date: Wed May 8 11:26:36 2013 New Revision: 1480227 URL: http://svn.apache.org/r1480227 Log: UIMA-2867 - rule match has not failed if the element match is invalid, but the quantifier wants to continue - added test
Added: uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest4.java uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/QuantifierTest4.ruta uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/QuantifierTest4.txt Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/AllTests.java Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java?rev=1480227&r1=1480226&r2=1480227&view=diff ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java (original) +++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java Wed May 8 11:26:36 2013 @@ -139,8 +139,10 @@ public class ComposedRuleElement extends ComposedRuleElementMatch parentContainerMatch = containerMatch.getContainerMatch(); RuleElement nextElement = container.getNextElement(after, this); List<RuleElementMatch> match = getMatch(ruleMatch, parentContainerMatch); + boolean continueMatch = quantifier.continueMatch(after, annotation, this, ruleMatch, + parentContainerMatch, stream, crowd); List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(match, parent, crowd); - ruleMatch.setMatched(ruleMatch.matched() && evaluateMatches != null); + ruleMatch.setMatched(ruleMatch.matched() && (evaluateMatches != null || continueMatch)); if (failed) { if (nextElement != null) { AnnotationFS backtrackedAnnotation = getBacktrackedAnnotation(evaluateMatches); @@ -156,8 +158,7 @@ public class ComposedRuleElement extends sideStepOrigin, entryPoint, stream, crowd); } } else { - if (quantifier.continueMatch(after, annotation, this, ruleMatch, parentContainerMatch, - stream, crowd)) { + if (continueMatch) { continueOwnMatch(after, annotation, ruleMatch, ruleApply, parentContainerMatch, sideStepOrigin, null, stream, crowd); } else if (nextElement != null) { Modified: uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/AllTests.java URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/AllTests.java?rev=1480227&r1=1480226&r2=1480227&view=diff ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/AllTests.java (original) +++ uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/AllTests.java Wed May 8 11:26:36 2013 @@ -37,12 +37,12 @@ import org.junit.runners.Suite.SuiteClas @SuiteClasses({ DynamicAnchoringTest.class, DynamicAnchoringTest2.class, FilteringTest.class, IncompletePartitioningTest.class, LiteralStringMatchTest.class, LongGreedyTest.class, OutOfWindowTest.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, ConditionVerbalizerTest.class, - ActionVerbalizerTest.class, ExpressionVerbalizerTest.class, HtmlAnnotatorTest.class, - HtmlConverterTest.class, EmptyDocumentTest.class, RutaModifierTest.class, - RegExpRuleTest.class, WildCardTest.class, EqualShortNameTest.class }) + QuantifierTest4.class, RuleInferenceTest.class, RuleInferenceTest2.class, + RuleInferenceTest3.class, AllActionsTest.class, AllConditionsTest.class, + CurrentCountTest.class, PartOfTest.class, PositionTest.class, DefaultSeederTest.class, + ConditionVerbalizerTest.class, ActionVerbalizerTest.class, ExpressionVerbalizerTest.class, + HtmlAnnotatorTest.class, HtmlConverterTest.class, EmptyDocumentTest.class, + RutaModifierTest.class, RegExpRuleTest.class, WildCardTest.class, EqualShortNameTest.class }) public class AllTests { } Added: uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest4.java URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest4.java?rev=1480227&view=auto ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest4.java (added) +++ uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest4.java Wed May 8 11:26:36 2013 @@ -0,0 +1,57 @@ +/* + * 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 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.apache.uima.ruta.engine.RutaEngine; +import org.junit.Test; + +public class QuantifierTest4 { + @Test + public void test() { + String name = this.getClass().getSimpleName(); + String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/"); + CAS cas = null; + try { + cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION, namespace + "/" + name + + ".txt", 50); + } catch (Exception e) { + e.printStackTrace(); + assert (false); + } + Type t = null; + AnnotationIndex<AnnotationFS> ai = null; + FSIterator<AnnotationFS> iterator = null; + + t = RutaTestUtils.getTestType(cas, 1); + ai = cas.getAnnotationIndex(t); + assertEquals(1, ai.size()); + iterator = ai.iterator(); + assertEquals("org.apache.uima.ruta.type.CW", iterator.next().getCoveredText()); + + cas.release(); + } +} Added: uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/QuantifierTest4.ruta URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/QuantifierTest4.ruta?rev=1480227&view=auto ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/QuantifierTest4.ruta (added) +++ uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/QuantifierTest4.ruta Wed May 8 11:26:36 2013 @@ -0,0 +1,5 @@ +PACKAGE org.apache.uima; +DECLARE T1; +((W PERIOD)[5,5] W){-> MARK(T1)}; + + Added: uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/QuantifierTest4.txt URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/QuantifierTest4.txt?rev=1480227&view=auto ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/QuantifierTest4.txt (added) +++ uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/QuantifierTest4.txt Wed May 8 11:26:36 2013 @@ -0,0 +1 @@ +org.apache.uima.ruta.type.CW \ No newline at end of file