Author: pkluegl Date: Thu Feb 16 14:22:55 2012 New Revision: 1244994 URL: http://svn.apache.org/viewvc?rev=1244994&view=rev Log: UIMA-2347 Parameter was still not correct. Changed current annotation to last matched one. Added additional unit test that covers this situation.
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/RuleInferenceTest3.java uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/RuleInferenceTest3.tm uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/RuleInferenceTest3.txt Modified: uima/sandbox/trunk/TextMarker/uimaj-textmarker/pom.xml uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRuleElement.java uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java Modified: uima/sandbox/trunk/TextMarker/uimaj-textmarker/pom.xml URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/pom.xml?rev=1244994&r1=1244993&r2=1244994&view=diff ============================================================================== --- uima/sandbox/trunk/TextMarker/uimaj-textmarker/pom.xml (original) +++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/pom.xml Thu Feb 16 14:22:55 2012 @@ -64,6 +64,12 @@ <artifactId>uimaj-tools</artifactId> <version>${project.parent.version}</version> <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.uima</groupId> + <artifactId>uimaj-test-util</artifactId> + <version>${project.parent.version}</version> + <scope>test</scope> </dependency> </dependencies> <scm> 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=1244994&r1=1244993&r2=1244994&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 Feb 16 14:22:55 2012 @@ -116,12 +116,14 @@ public class TextMarkerRuleElement exten if (quantifier.continueMatch(after, annotation, this, ruleMatch, containerMatch, stream, crowd)) { boolean stopMatching = false; AnnotationFS eachAnchor = annotation; + AnnotationFS lastAnchor = annotation; ComposedRuleElementMatch extendedContainerMatch = containerMatch; RuleMatch extendedMatch = ruleMatch; extendedMatch.update(extendedContainerMatch); while (!stopMatching) { Collection<AnnotationFS> nextAnnotations = getNextAnnotations(after, eachAnchor, stream); if (nextAnnotations.size() == 1) { + lastAnchor = eachAnchor; eachAnchor = nextAnnotations.iterator().next(); doMatch(eachAnchor, extendedMatch, extendedContainerMatch, false, stream, crowd); if (this.equals(entryPoint)) { @@ -138,12 +140,12 @@ public class TextMarkerRuleElement exten } } else { stopMatching = true; - stepbackMatch(after, eachAnchor, extendedMatch, ruleApply, extendedContainerMatch, + stepbackMatch(after, lastAnchor, extendedMatch, ruleApply, extendedContainerMatch, sideStepOrigin, stream, crowd, entryPoint); } } else { stopMatching = true; - continueMatch(after, eachAnchor, extendedMatch, ruleApply, extendedContainerMatch, + continueMatch(after, lastAnchor, extendedMatch, ruleApply, extendedContainerMatch, sideStepOrigin, entryPoint, stream, crowd); } } 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=1244994&r1=1244993&r2=1244994&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 Feb 16 14:22:55 2012 @@ -6,7 +6,8 @@ import org.junit.runners.Suite.SuiteClas @RunWith(Suite.class) @SuiteClasses({ DynamicAnchoringTest.class, DynamicAnchoringTest2.class, FilteringTest.class, - QuantifierTest1.class, QuantifierTest2.class, RuleInferenceTest.class, LongGreedyTest.class }) + QuantifierTest1.class, QuantifierTest2.class, RuleInferenceTest.class, + RuleInferenceTest2.class, RuleInferenceTest3.class, LongGreedyTest.class }) public class AllTests { } Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/RuleInferenceTest3.java URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/RuleInferenceTest3.java?rev=1244994&view=auto ============================================================================== --- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/RuleInferenceTest3.java (added) +++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/RuleInferenceTest3.java Thu Feb 16 14:22:55 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 RuleInferenceTest3 { + + @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, 4); + ai = cas.getAnnotationIndex(t); + assertEquals(4, ai.size()); + + iterator = ai.iterator(); + assertEquals("[1]", iterator.next().getCoveredText()); + assertEquals("[2]", iterator.next().getCoveredText()); + assertEquals("[3]", iterator.next().getCoveredText()); + assertEquals("[4]", iterator.next().getCoveredText()); + + + + if (cas != null) { + cas.release(); + } + + } +} Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/RuleInferenceTest3.tm URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/RuleInferenceTest3.tm?rev=1244994&view=auto ============================================================================== --- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/RuleInferenceTest3.tm (added) +++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/RuleInferenceTest3.tm Thu Feb 16 14:22:55 2012 @@ -0,0 +1,18 @@ +PACKAGE org.apache.uima; + +DECLARE T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25; + +// T1 = LBrack +// T2 = T2 +// T3 = FirstLBrack +// T4 = RefStart + +Document{-> RETAINTYPE(BREAK)}; + +SPECIAL{REGEXP("\\[") -> MARK(T1)}; +SPECIAL{REGEXP("\\]") -> MARK(T2)}; + +T1{POSITION(Document,1) -> MARK(T3)}; + +BREAK T1 ANY[1,10]{-PARTOF(T2) -> MARK(T4, 2, 3, 4)} T2; +T1{PARTOF(T3)} ANY[1,10]{-PARTOF(T2) -> MARK(T4, 1, 2, 3, 4)} T2; \ No newline at end of file Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/RuleInferenceTest3.txt URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/RuleInferenceTest3.txt?rev=1244994&view=auto ============================================================================== --- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/RuleInferenceTest3.txt (added) +++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/RuleInferenceTest3.txt Thu Feb 16 14:22:55 2012 @@ -0,0 +1,17 @@ +[1] Califf M. E., and R. J. Mooney. Bottom-up Relational +Learning of Pattern Matching Rules for Information +Extraction. Journal of Machine Learning Research, 2003, pp. +177-210. + +[2] Cui H., et al. Generic Soft Pattern Models for Definitional +Question Answering. In Proceedings of SIGIR-05, 2005. + +[3] Hu D., et al. SIIPU*S: A Semantic Pattern Learning +Algorithm. In Proceedings of the second international +conference on Semantics, Knowledge and Grid (SKG2006), +2006. + +[4] Kim, J., and Moldovan, D. Acquisition of Linguistic Patterns +for Knowledge-based Information Extraction. In IEEE +Transactions on Knowledge and Data Engineering, 1995, pp. +713-724. \ No newline at end of file