Author: pkluegl Date: Tue May 28 08:45:23 2013 New Revision: 1486819 URL: http://svn.apache.org/r1486819 Log: UIMA-2945 - fixed check for next match - added test
Added: uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCardTest2.java uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/WildcardTest2.ruta uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/WildcardTest2.txt Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java?rev=1486819&r1=1486818&r2=1486819&view=diff ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java (original) +++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java Tue May 28 08:45:23 2013 @@ -242,7 +242,7 @@ public class WildCardRuleElement extends nextElement.continueMatch(after, endAnchor, extendedMatch, ruleApply, extendedContainerMatch, sideStepOrigin, nextElement, stream, crowd); List<RuleElementMatch> nextList = extendedContainerMatch.getInnerMatches().get(nextElement); - if (nextList == null || nextList.isEmpty()) { + if (nextList == null || nextList.isEmpty() || !nextList.get(nextList.size() - 1).matched()) { moveOn(after, iterator); } else { doneHere = true; Added: uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCardTest2.java URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCardTest2.java?rev=1486819&view=auto ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCardTest2.java (added) +++ uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCardTest2.java Tue May 28 08:45:23 2013 @@ -0,0 +1,76 @@ +/* + * 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 WildCardTest2 { + + @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(2, ai.size()); + iterator = ai.iterator(); + assertEquals("Ogren, P.V., Wetzler, P.G., Bethard, S.:", iterator.next().getCoveredText()); + assertEquals("Stephen Soderland, Claire Cardie, and Raymond Mooney.", iterator.next().getCoveredText()); + + t = RutaTestUtils.getTestType(cas, 2); + ai = cas.getAnnotationIndex(t); + assertEquals(2, ai.size()); + iterator = ai.iterator(); + assertEquals(" ClearTK: A UIMA Toolkit for Statistical Natural Language Processing.", iterator.next().getCoveredText()); + assertEquals(" Learning Information Extraction Rules for Semi-Structured and Free Text.", iterator.next().getCoveredText()); + + t = RutaTestUtils.getTestType(cas, 3); + ai = cas.getAnnotationIndex(t); + assertEquals(2, ai.size()); + iterator = ai.iterator(); + assertEquals("2008", iterator.next().getCoveredText()); + assertEquals("1999", iterator.next().getCoveredText()); + + if (cas != null) { + cas.release(); + } + + } +} Added: uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/WildcardTest2.ruta URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/WildcardTest2.ruta?rev=1486819&view=auto ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/WildcardTest2.ruta (added) +++ uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/WildcardTest2.ruta Tue May 28 08:45:23 2013 @@ -0,0 +1,14 @@ +PACKAGE uima.ruta.tests; + +DECLARE T1, T2, T3, T4, T5, T6, T7; + +Document{-> RETAINTYPE(BREAK, SPACE)}; +#{-> T6} BREAK #{-> T6}; +T6{-> TRIM(BREAK, SPACE)}; +CW{REGEXP(".")} PERIOD{->T7}; +Document{-> RETAINTYPE}; + +BLOCK(forEach) T6 {}{ + (# COLON){-> T1} (# PERIOD){-> T2} # "(" NUM{REGEXP("....")-> T3} ")"; + (#{-CONTAINS(COLON)} PERIOD{-PARTOF(T7)}){-> T1} (# PERIOD){-> T2} # NUM{REGEXP("....")-> T3}; +} Added: uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/WildcardTest2.txt URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/WildcardTest2.txt?rev=1486819&view=auto ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/WildcardTest2.txt (added) +++ uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/WildcardTest2.txt Tue May 28 08:45:23 2013 @@ -0,0 +1,2 @@ +Ogren, P.V., Wetzler, P.G., Bethard, S.: ClearTK: A UIMA Toolkit for Statistical Natural Language Processing. In: UIMA for NLP workshop at LREC 08. (2008) +Stephen Soderland, Claire Cardie, and Raymond Mooney. Learning Information Extraction Rules for Semi-Structured and Free Text. In Machine Learning, volume 34, pages 233â272, 1999. \ No newline at end of file