This is an automated email from the ASF dual-hosted git repository. pkluegl pushed a commit to branch bugfix/UIMA-6405-Local-variable-not-captured-properly-in-a-wildcard-matching-condition in repository https://gitbox.apache.org/repos/asf/uima-ruta.git
commit 351ddcafb4b8c5b903d7acc107169e358139a793 Author: Peter Klügl <peter.klu...@averbis.com> AuthorDate: Mon Jan 3 10:56:29 2022 +0100 UIMA-6405: Local variable not captured properly in a wildcard matching condition - added test --- .../org/apache/uima/ruta/rule/WildCard2Test.java | 33 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java b/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java index 38dabdf..af6f5b4 100644 --- a/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java +++ b/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java @@ -275,13 +275,12 @@ public class WildCard2Test { public void testLabelForFailedLookahead() throws Exception { String document = "A x B x C x D"; String script = "(w1:CW{REGEXP(\"A\")} # w2:CW{REGEXP(\"C\")})->{w1{->T1};};"; - - CAS cas = RutaTestUtils.getCAS(document, null, null, false); + + CAS cas = RutaTestUtils.getCAS(document, null, null, false); Ruta.apply(cas, script); - - RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "A"); - } + RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "A"); + } @Test public void testLastElementAlsoAnnotatedWithLookahead() throws Exception { @@ -297,4 +296,28 @@ public class WildCard2Test { RutaTestUtils.assertAnnotationsEquals(cas, 4, 2, "c", "c"); } + @Test + public void testLookaheadWithFeatureMatch() throws Exception { + String document = "a 2 b 3 c 4 d"; + String script = ""; + script += "\"2\"{->s:Struct,s.s=\"x\"};\n"; + script += "\"3\"{->s:Struct};\n"; + script += "\"4\"{->s:Struct,s.s=\"y\"};\n"; + script += "s1:Struct.s==\"x\" # s2:Struct.s==\"y\"{->s2.s=s1.s, T1};\n"; + script += "s:Struct.s==\"x\"{->T2};\n"; + + Map<String, String> complexType = new HashMap<>(); + complexType.put("Struct", CAS.TYPE_NAME_ANNOTATION); + Map<String, List<TestFeature>> featureMap = new HashMap<>(); + List<TestFeature> list = new ArrayList<>(); + list.add(new TestFeature("s", "", CAS.TYPE_NAME_STRING)); + featureMap.put("Struct", list); + + CAS cas = RutaTestUtils.getCAS(document, complexType, featureMap); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "4"); + RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "2", "4"); + } + }