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/04 14:10:02 UTC
svn commit: r1722863 - in /uima/ruta/trunk/ruta-core/src:
main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
test/java/org/apache/uima/ruta/WildCard2Test.java
Author: pkluegl
Date: Mon Jan 4 13:10:02 2016
New Revision: 1722863
URL: http://svn.apache.org/viewvc?rev=1722863&view=rev
Log:
UIMA-4715
- added test
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCard2Test.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java?rev=1722863&r1=1722862&r2=1722863&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java Mon Jan 4 13:10:02 2016
@@ -63,8 +63,8 @@ public class WildCardRuleElement extends
RuleElement current = this;
int nextDepth = -1;
while (nextElement == null && current != null && current.getContainer() != null) {
- nextElement = current.getContainer().getNextElement(after, current);
RuleElementContainer container = current.getContainer();
+ nextElement = container.getNextElement(after, current);
if (container instanceof RuleElement) {
current = (RuleElement) container;
nextDepth++;
Modified: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCard2Test.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCard2Test.java?rev=1722863&r1=1722862&r2=1722863&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCard2Test.java (original)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCard2Test.java Mon Jan 4 13:10:02 2016
@@ -26,46 +26,66 @@ import org.junit.Test;
public class WildCard2Test {
- @Test
- public void test() {
- String document = "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)";
- document +="\n";
- document += "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.";
- String script = "";
- script += "RETAINTYPE(BREAK, SPACE);\n";
- script += "#{-> T6} BREAK #{-> T6};\n";
- script += "T6{-> TRIM(BREAK, SPACE)};\n";
- script += "CW{REGEXP(\".\")} PERIOD{->T7};\n";
- script += "RETAINTYPE;\n";
- script += "BLOCK(forEach) T6 {}{\n";
- script += "(# COLON){-> T1} (# PERIOD){-> T2} # \"(\" NUM{REGEXP(\"....\")-> T3} \")\";\n";
- script += "(#{-CONTAINS(COLON)} PERIOD{-PARTOF(T7)}){-> T1} (# PERIOD){-> T2} # NUM{REGEXP(\"....\")-> T3};\n";
- script += "}\n";
-
- CAS cas = null;
- try {
- cas = RutaTestUtils.getCAS(document);
- Ruta.apply(cas, script);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "Ogren, P.V., Wetzler, P.G., Bethard, S.:",
- "Stephen Soderland, Claire Cardie, and Raymond Mooney.");
- RutaTestUtils.assertAnnotationsEquals(cas, 2, 2,
- "ClearTK: A UIMA Toolkit for Statistical Natural Language Processing.",
- "Learning Information Extraction Rules for Semi-Structured and Free Text.");
- RutaTestUtils.assertAnnotationsEquals(cas, 3, 2, "2008", "1999");
-
- cas.release();
- }
+ @Test
+ public void test() {
+ String document =
+ "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)";
+ document += "\n";
+ document +=
+ "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.";
+ String script = "";
+ script += "RETAINTYPE(BREAK, SPACE);\n";
+ script += "#{-> T6} BREAK #{-> T6};\n";
+ script += "T6{-> TRIM(BREAK, SPACE)};\n";
+ script += "CW{REGEXP(\".\")} PERIOD{->T7};\n";
+ script += "RETAINTYPE;\n";
+ script += "BLOCK(forEach) T6 {}{\n";
+ script += "(# COLON){-> T1} (# PERIOD){-> T2} # \"(\" NUM{REGEXP(\"....\")-> T3} \")\";\n";
+ script +=
+ "(#{-CONTAINS(COLON)} PERIOD{-PARTOF(T7)}){-> T1} (# PERIOD){-> T2} # NUM{REGEXP(\"....\")-> T3};\n";
+ script += "}\n";
+ CAS cas = null;
+ try {
+ cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
- @Test
- public void testOptional() {
- String document = "Cw 1 2 3";
- String script = "(CW #){-> T1} SW?;";
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "Ogren, P.V., Wetzler, P.G., Bethard, S.:",
+ "Stephen Soderland, Claire Cardie, and Raymond Mooney.");
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 2,
+ "ClearTK: A UIMA Toolkit for Statistical Natural Language Processing.",
+ "Learning Information Extraction Rules for Semi-Structured and Free Text.");
+ RutaTestUtils.assertAnnotationsEquals(cas, 3, 2, "2008", "1999");
+
+ cas.release();
+ }
+
+ @Test
+ public void testOptional() {
+ String document = "Cw 1 2 3";
+ String script = "(CW #){-> T1} SW?;";
+
+ CAS cas = null;
+ try {
+ cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Cw 1 2 3");
+
+ cas.release();
+ }
+ @Test
+ public void testLookaheadInGreedy() {
+ String document = "Some test. Some test. Some test.";
+ String script = "((CW #){-> T1})+;";
+ script += "((# PERIOD){-> T2})+;";
CAS cas = null;
try {
cas = RutaTestUtils.getCAS(document);
@@ -74,9 +94,13 @@ public class WildCard2Test {
e.printStackTrace();
}
- RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Cw 1 2 3");
+ // UIMA-4715: should be
+ // RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "Some test.", "Some test.", "Some test.");
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "Some test. Some test. Some test.",
+ "Some test. Some test.", "Some test.");
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 3, "Some test.", "Some test.", "Some test.");
cas.release();
}
-
+
}