Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/OutOfWindowTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/OutOfWindowTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/OutOfWindowTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/OutOfWindowTest.java Mon Nov 18 12:19:31 2019 @@ -41,18 +41,18 @@ public class OutOfWindowTest { cas.release(); } - + @Test public void testFeatureMatch() { String document = "First Sentence. Second Sentence."; String script = ""; script += "(# PERIOD){-> T1};"; script += "T1 #{-> T1};"; - + script += "CW.ct==\"First\"{-> GATHER(Struct, \"next\" = 3)} # CW.ct==\"Second\";"; script += "T1->{Struct.next{REGEXP(\"Sec.*\") -> T2};};"; script += "T1<-{Struct.next{PARTOF(CW) -> T3};};"; - + Map<String, String> complexTypes = new TreeMap<String, String>(); String typeName = "org.apache.uima.Struct"; complexTypes.put(typeName, "uima.tcas.Annotation"); @@ -62,33 +62,32 @@ public class OutOfWindowTest { features.put(typeName, list); String fn1 = "next"; list.add(new TestFeature(fn1, "", "uima.tcas.Annotation")); - + CAS cas = null; try { cas = RutaTestUtils.getCAS(document, complexTypes, features); Ruta.apply(cas, script); } catch (Exception e) { - throw new AssertionError("No exception is expected when applying the rules.", e); + throw new RuntimeException("No exception is expected when applying the rules.", e); } - - + RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "Second"); RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "Second"); cas.release(); } - + @Test public void testSequentialAfterOutOfWindowFeatureMatch() { String document = "First Sentence. Second one."; String script = ""; script += "(# PERIOD){-> T1};"; script += "T1 #{-> T1};"; - + script += "CW.ct==\"First\"{-> GATHER(Struct, \"next\" = 3)} # CW.ct==\"Second\";"; script += "T1->{Struct.next{REGEXP(\"Sec.*\")} ANY{-> T2};};"; script += "T1<-{Struct.next{PARTOF(CW)} ANY{-> T3};};"; - + Map<String, String> complexTypes = new TreeMap<String, String>(); String typeName = "org.apache.uima.Struct"; complexTypes.put(typeName, "uima.tcas.Annotation"); @@ -98,20 +97,19 @@ public class OutOfWindowTest { features.put(typeName, list); String fn1 = "next"; list.add(new TestFeature(fn1, "", "uima.tcas.Annotation")); - + CAS cas = null; try { cas = RutaTestUtils.getCAS(document, complexTypes, features); Ruta.apply(cas, script); } catch (Exception e) { - throw new AssertionError("No exception is expected when applying the rules.", e); + throw new RuntimeException("No exception is expected when applying the rules.", e); } - - + RutaTestUtils.assertAnnotationsEquals(cas, 2, 0); RutaTestUtils.assertAnnotationsEquals(cas, 3, 0); cas.release(); } - + }
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/StrictImportTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/StrictImportTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/StrictImportTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/StrictImportTest.java Mon Nov 18 12:19:31 2019 @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.uima.UIMAFramework; import org.apache.uima.analysis_engine.AnalysisEngine; import org.apache.uima.analysis_engine.AnalysisEngineDescription; import org.apache.uima.analysis_engine.AnalysisEngineProcessException; @@ -39,6 +40,7 @@ import org.apache.uima.fit.factory.Analy import org.apache.uima.fit.factory.TypeSystemDescriptionFactory; import org.apache.uima.fit.util.CasUtil; import org.apache.uima.jcas.tcas.Annotation; +import org.apache.uima.resource.ResourceManager; import org.apache.uima.resource.metadata.TypeSystemDescription; import org.apache.uima.ruta.engine.Ruta; import org.apache.uima.ruta.engine.RutaEngine; @@ -75,7 +77,9 @@ public class StrictImportTest { tsd.addType(script.replaceAll("/", ".") + ".T1", "Type for Testing", "uima.tcas.Annotation"); ruta.getAnalysisEngineMetaData().setTypeSystem(tsd); - return AnalysisEngineFactory.createEngine(ruta); + ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager(); + AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(ruta, resourceManager, null); + return ae; } @Test @@ -153,10 +157,13 @@ public class StrictImportTest { CAS cas = RutaTestUtils.getCAS("Some text.", complexTypes, null); - AnalysisEngine ae = AnalysisEngineFactory.createEngine(RutaEngine.class, - RutaEngine.PARAM_MAIN_SCRIPT, "org.apache.uima.ruta.StrictScript1", + AnalysisEngineDescription description = AnalysisEngineFactory.createEngineDescription( + RutaEngine.class, RutaEngine.PARAM_MAIN_SCRIPT, "org.apache.uima.ruta.StrictScript1", RutaEngine.PARAM_ADDITIONAL_SCRIPTS, "org.apache.uima.ruta.StrictScript2", RutaEngine.PARAM_STRICT_IMPORTS, true); + ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager(); + AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(description, resourceManager, null); + ae.process(cas); Type t1 = cas.getTypeSystem().getType(s1); Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/CreateTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/CreateTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/CreateTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/CreateTest.java Mon Nov 18 12:19:31 2019 @@ -89,7 +89,7 @@ public class CreateTest { } @Test - public void testFeature() { + public void testFeature() throws Exception { String document = "Test."; String script = ""; script += "W{-> CREATE(Inner, \"word\" = W)};"; @@ -122,13 +122,8 @@ public class CreateTest { String fn3 = "word"; list.add(new TestFeature(fn3, "", "uima.tcas.Annotation")); - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document, typeMap, featureMap); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } + CAS cas = RutaTestUtils.getCAS(document, typeMap, featureMap); + Ruta.apply(cas, script); Type t = null; AnnotationIndex<AnnotationFS> ai = null; @@ -145,6 +140,5 @@ public class CreateTest { assertEquals("Test", ((AnnotationFS) fv1).getCoveredText()); - cas.release(); } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GatherTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GatherTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GatherTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GatherTest.java Mon Nov 18 12:19:31 2019 @@ -41,7 +41,7 @@ import org.junit.Test; public class GatherTest { @Test - public void test() { + public void test() throws Exception { String name = this.getClass().getSimpleName(); String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/"); @@ -57,15 +57,9 @@ public class GatherTest { String fn2 = "b"; list.add(new TestFeature(fn2, "", "uima.tcas.Annotation")); - CAS cas = null; - try { - cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION, - namespace + "/" + name + ".txt", 50, false, false, complexTypes, features, namespace - + "/"); - } catch (Exception e) { - e.printStackTrace(); - assert (false); - } + CAS cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION, + namespace + "/" + name + ".txt", 50, false, false, complexTypes, features, + namespace + "/"); Type t = null; AnnotationIndex<AnnotationFS> ai = null; FSIterator<AnnotationFS> iterator = null; @@ -84,7 +78,6 @@ public class GatherTest { assertEquals("A", v1.getCoveredText()); assertEquals("B", v2.getCoveredText()); - cas.release(); } @Test @@ -105,8 +98,8 @@ public class GatherTest { list.add(new TestFeature(fn1, "", "uima.tcas.Annotation")); String fn2 = "b"; list.add(new TestFeature(fn2, "", "uima.tcas.Annotation")); - CAS cas = RutaTestUtils.getCAS(document, complexTypes, features); - Ruta.apply(cas, script); + CAS cas = RutaTestUtils.getCAS(document, complexTypes, features); + Ruta.apply(cas, script); Type t = null; AnnotationIndex<AnnotationFS> ai = null; Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GetFeatureTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GetFeatureTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GetFeatureTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GetFeatureTest.java Mon Nov 18 12:19:31 2019 @@ -29,9 +29,7 @@ public class GetFeatureTest { public void test() { CAS cas = RutaTestUtils.processTestScript(this.getClass()); - RutaTestUtils.assertAnnotationsEquals(cas, 1, 1); - - cas.release(); } + } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MacroActionTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MacroActionTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MacroActionTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MacroActionTest.java Mon Nov 18 12:19:31 2019 @@ -19,54 +19,56 @@ package org.apache.uima.ruta.action; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + import org.apache.uima.cas.CAS; +import org.apache.uima.cas.FSIterator; +import org.apache.uima.cas.Feature; +import org.apache.uima.cas.FeatureStructure; +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.Ruta; import org.apache.uima.ruta.engine.RutaTestUtils; +import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature; +import org.junit.Ignore; import org.junit.Test; public class MacroActionTest { @Test - public void test() { + public void test() throws Exception { String document = "Test"; String script = "INT j;\n"; script += "ACTION macro(TYPE t, INT inc) = MARK(t),ASSIGN(j,j+inc);\n"; script += "Document{-> macro(T1,1)};\n"; script += "Document{(j>0)->T2};\n"; - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Test"); RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "Test"); - - cas.release(); } @Test - public void testNoArgs() { + public void testNoArgs() throws Exception { String document = "Test."; String script = "INT j;\n"; script += "ACTION macro() = MARK(T1), MARK(T2);\n"; script += "W{-> macro()};\n"; - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Test"); RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "Test"); - - cas.release(); } @Test @@ -81,8 +83,59 @@ public class MacroActionTest { Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Test"); + } + + @Test + public void testLabel() throws Exception { + String document = "Test"; + String script = ""; + script += "ACTION doit() = MARK(T1);\n"; + script += "CW{-> t:doit()}-> {t{->T2};};\n"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Test"); + RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "Test"); + } + + @Test + @Ignore + public void testShareSameNameArgumentAndLabel() throws Exception { + String document = "Day 5"; + String script = "ACTION CreateDate(ANNOTATION day) = CREATE(Date, \"day\"=day);\n"; + script += "(CW day:NUM){-> CreateDate(day)};\n"; + + Map<String, String> typeMap = new TreeMap<String, String>(); + String typeName1 = "Date"; + typeMap.put(typeName1, "uima.tcas.Annotation"); + + Map<String, List<TestFeature>> featureMap = new TreeMap<String, List<TestFeature>>(); + List<TestFeature> list = new ArrayList<RutaTestUtils.TestFeature>(); + featureMap.put(typeName1, list); + String fn1 = "day"; + list.add(new TestFeature(fn1, "", "uima.tcas.Annotation")); + + CAS cas = RutaTestUtils.getCAS(document, typeMap, featureMap); + Ruta.apply(cas, script); + + Type t = null; + AnnotationIndex<AnnotationFS> ai = null; + FSIterator<AnnotationFS> iterator = null; + + t = cas.getTypeSystem().getType(typeName1); + Feature feat = t.getFeatureByBaseName(fn1); + + ai = cas.getAnnotationIndex(t); + + iterator = ai.iterator(); + + AnnotationFS nextFS = iterator.next(); + + FeatureStructure fv1 = nextFS.getFeatureValue(feat); + assertNotNull(fv1); - cas.release(); + assertEquals("5", ((AnnotationFS) fv1).getCoveredText()); } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MarkFastTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MarkFastTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MarkFastTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MarkFastTest.java Mon Nov 18 12:19:31 2019 @@ -19,32 +19,56 @@ package org.apache.uima.ruta.action; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + import org.apache.uima.cas.CAS; +import org.apache.uima.ruta.engine.Ruta; import org.apache.uima.ruta.engine.RutaEngine; import org.apache.uima.ruta.engine.RutaTestUtils; +import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature; import org.junit.Test; public class MarkFastTest { @Test - public void test() { + public void test() throws Exception { 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, false, false, null, namespace + "/"); - } catch (Exception e) { - e.printStackTrace(); - assert (false); - } + CAS cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION, + namespace + "/" + name + ".txt", 50, false, false, null, namespace + "/"); RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "1 0 0", "100", "2 0 0"); RutaTestUtils.assertAnnotationsEquals(cas, 2, 0); - RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "100"); + RutaTestUtils.assertAnnotationsEquals(cas, 3, 3, "1 0 0", "100", "2 0 0"); RutaTestUtils.assertAnnotationsEquals(cas, 4, 2, "1 0 0", "2 0 0"); - cas.release(); } + + @Test + public void testWithNullStringList() throws Exception { + + String text = "Some text."; + String script = ""; + script += "STRINGLIST list;\n"; + script += "Document{-> ADD(list, null)};\n"; + script += "MARKFAST(T1,list);\n"; + + Map<String, String> complexTypes = new TreeMap<String, String>(); + String typeName = "org.apache.uima.Struct"; + complexTypes.put(typeName, "uima.tcas.Annotation"); + + Map<String, List<TestFeature>> features = new TreeMap<String, List<TestFeature>>(); + List<TestFeature> list = new ArrayList<RutaTestUtils.TestFeature>(); + features.put(typeName, list); + String fn1 = "s"; + list.add(new TestFeature(fn1, "", "uima.cas.String")); + CAS cas = RutaTestUtils.getCAS(text, complexTypes, features); + Ruta.apply(cas, script); + RutaTestUtils.assertAnnotationsEquals(cas, 1, 0); + } + } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/Shift1Test.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/Shift1Test.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/Shift1Test.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/Shift1Test.java Mon Nov 18 12:19:31 2019 @@ -45,7 +45,6 @@ public class Shift1Test { CAS cas = RutaTestUtils.getCAS(text); Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "2 3", "3 x 4", "4"); - cas.release(); } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/block/ForEachBlockTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/block/ForEachBlockTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/block/ForEachBlockTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/block/ForEachBlockTest.java Mon Nov 18 12:19:31 2019 @@ -19,13 +19,17 @@ package org.apache.uima.ruta.block; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.TreeMap; import org.apache.uima.cas.CAS; import org.apache.uima.ruta.engine.Ruta; import org.apache.uima.ruta.engine.RutaEngine; import org.apache.uima.ruta.engine.RutaTestUtils; +import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature; import org.apache.uima.ruta.seed.TextSeeder; import org.junit.Ignore; import org.junit.Test; @@ -35,17 +39,12 @@ public class ForEachBlockTest { private String text = "Some text 4 more text."; @Test - public void testDefault() { + public void testDefault() throws Exception { String script = getForEachScript(); - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(text); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } + CAS cas = RutaTestUtils.getCAS(text); + Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "4"); RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "4"); @@ -58,7 +57,6 @@ public class ForEachBlockTest { RutaTestUtils.assertAnnotationsEquals(cas, 9, 1, "Some"); RutaTestUtils.assertAnnotationsEquals(cas, 10, 1, "4"); - cas.release(); } @Test @@ -90,8 +88,6 @@ public class ForEachBlockTest { long endForEach = System.currentTimeMillis(); System.out.println("FOREACH: " + (endForEach - startForEach) + "ms"); - cas.release(); - } private String getForEachScript() { @@ -128,7 +124,6 @@ public class ForEachBlockTest { Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "2^3", "2"); - cas.release(); } @Test @@ -144,7 +139,6 @@ public class ForEachBlockTest { Ruta.apply(cas, script, parameters); RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "4", "2^3"); - cas.release(); } @Test @@ -161,7 +155,6 @@ public class ForEachBlockTest { RutaTestUtils.assertAnnotationsEquals(cas, 2, 3, "text 4x2^3", "text 4x2", "text 4"); RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "text 4x2^3"); - cas.release(); } @Test @@ -175,7 +168,6 @@ public class ForEachBlockTest { Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "4x2^3"); - cas.release(); } @Test @@ -189,7 +181,6 @@ public class ForEachBlockTest { Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "1"); - cas.release(); } @Test @@ -207,7 +198,42 @@ public class ForEachBlockTest { RutaTestUtils.assertAnnotationsEquals(cas, 1, 0); RutaTestUtils.assertAnnotationsEquals(cas, 2, 3, "1", "22", "333"); - cas.release(); + } + + @Test + public void testWithOptional() throws Exception { + String script = ""; + script += "FOREACH(num) NUM{} {\n"; + script += "_{-PARTOF(W)} num{-> T1};\n"; + script += "}\n"; + + CAS cas = RutaTestUtils.getCAS("1 22 333"); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "1", "22", "333"); + } + + @Test + public void testFSArrayFeatureMatch() throws Exception { + String script = "Document {-> s:Struct, s.elements = SW};"; + script += "FOREACH(struct) Struct{} {\n"; + script += "struct.elements{-> T1};\n"; + script += "}\n"; + + Map<String, String> typeMap = new TreeMap<String, String>(); + String typeName1 = "Struct"; + typeMap.put(typeName1, "uima.tcas.Annotation"); + + Map<String, List<TestFeature>> featureMap = new TreeMap<String, List<TestFeature>>(); + List<TestFeature> list = new ArrayList<RutaTestUtils.TestFeature>(); + featureMap.put(typeName1, list); + String fn1 = "elements"; + list.add(new TestFeature(fn1, "", "uima.cas.FSArray")); + + CAS cas = RutaTestUtils.getCAS("This is a test.", typeMap, featureMap); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "is", "a", "test"); } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/block/RutaScriptBlockTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/block/RutaScriptBlockTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/block/RutaScriptBlockTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/block/RutaScriptBlockTest.java Mon Nov 18 12:19:31 2019 @@ -28,7 +28,7 @@ import org.junit.Test; public class RutaScriptBlockTest { @Test - public void testInnerDocumentMatch() { + public void testInnerDocumentMatch() throws Exception { String document = "Some text"; String script = ""; script += "CW{ -> CREATE(RutaAnnotation, \"score\"=1)};"; @@ -39,19 +39,12 @@ public class RutaScriptBlockTest { script += "RutaAnnotation{-> T3};"; script += "}"; - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Some"); RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "Some"); RutaTestUtils.assertAnnotationsEquals(cas, 3, 2, "Some", "Some"); - - cas.release(); } @Test @@ -78,7 +71,6 @@ public class RutaScriptBlockTest { Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "1"); - cas.release(); } @Test @@ -92,7 +84,6 @@ public class RutaScriptBlockTest { Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 2, 3, "1", "22", "333"); - cas.release(); } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/descriptor/GenerateDescriptorTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/descriptor/GenerateDescriptorTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/descriptor/GenerateDescriptorTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/descriptor/GenerateDescriptorTest.java Mon Nov 18 12:19:31 2019 @@ -180,7 +180,7 @@ public class GenerateDescriptorTest { } @Test - public void testRuleScriptName() throws Exception { + public void testTypeWithRuleScriptNameWithPackage() throws Exception { String script = ""; script += "PACKAGE test.package;\n"; @@ -191,7 +191,7 @@ public class GenerateDescriptorTest { RutaBuildOptions options = new RutaBuildOptions(); RutaDescriptorInformation descriptorInformation = rdf.parseDescriptorInformation(script, null, options); - String typeSystemOutput = "target/temp/testRuleScriptName_TypeSystem.xml"; + String typeSystemOutput = "target/temp/testTypeWithRuleScriptNameWithPackage_TypeSystem.xml"; ClassLoader classLoader = GenerateDescriptorTest.class.getClassLoader(); TypeSystemDescription tsd = rdf.createTypeSystemDescription(typeSystemOutput, descriptorInformation, options, classLoader); @@ -202,6 +202,29 @@ public class GenerateDescriptorTest { Assert.assertNotNull(tagType); } + + @Test + public void testTypeWithRuleScriptNameWithoutPackage() throws Exception { + + String script = ""; + script += "DECLARE SimpleType;\n"; + + RutaDescriptorFactory rdf = new RutaDescriptorFactory(GenerateDescriptorTest.basicTSUrl, + GenerateDescriptorTest.basicAEUrl); + RutaBuildOptions options = new RutaBuildOptions(); + RutaDescriptorInformation descriptorInformation = rdf.parseDescriptorInformation(script, null, + options); + String typeSystemOutput = "target/temp/testTypeWithRuleScriptNameWithoutPackage_TypeSystem.xml"; + ClassLoader classLoader = GenerateDescriptorTest.class.getClassLoader(); + TypeSystemDescription tsd = rdf.createTypeSystemDescription(typeSystemOutput, + descriptorInformation, options, classLoader); + ResourceManager rm = new ResourceManager_impl(classLoader); + tsd.resolveImports(rm); + + TypeDescription tagType = tsd.getType("SimpleType"); + Assert.assertNotNull(tagType); + + } @Test public void testScriptOnly() throws Exception { Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ResourcesFromDataPathTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ResourcesFromDataPathTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ResourcesFromDataPathTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ResourcesFromDataPathTest.java Mon Nov 18 12:19:31 2019 @@ -66,8 +66,8 @@ public class ResourcesFromDataPathTest { ae.process(cas); RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "1 0 0", "100", "2 0 0"); - RutaTestUtils.assertAnnotationsEquals(cas, 2, 0); + RutaTestUtils.assertAnnotationsEquals(cas, 2, 3, "1 0 0", "100", "2 0 0"); RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "100"); - RutaTestUtils.assertAnnotationsEquals(cas, 4, 2, "1 0 0", "2 0 0"); + RutaTestUtils.assertAnnotationsEquals(cas, 4, 1, "100"); } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/RutaEngineTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/RutaEngineTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/RutaEngineTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/RutaEngineTest.java Mon Nov 18 12:19:31 2019 @@ -26,17 +26,27 @@ import java.util.List; import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.reflect.FieldUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.uima.UIMAFramework; import org.apache.uima.analysis_engine.AnalysisEngine; +import org.apache.uima.analysis_engine.AnalysisEngineDescription; import org.apache.uima.analysis_engine.AnalysisEngineProcessException; import org.apache.uima.cas.CAS; +import org.apache.uima.cas.Type; +import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.fit.factory.AnalysisEngineFactory; import org.apache.uima.fit.internal.ResourceManagerFactory; import org.apache.uima.fit.internal.ResourceManagerFactory.ResourceManagerCreator; +import org.apache.uima.fit.util.CasUtil; import org.apache.uima.jcas.JCas; import org.apache.uima.resource.ResourceInitializationException; import org.apache.uima.resource.ResourceManager; +import org.apache.uima.resource.metadata.TypeSystemDescription; import org.apache.uima.ruta.RutaProcessRuntimeException; import org.apache.uima.ruta.TypeUsageInformation; +import org.apache.uima.ruta.descriptor.RutaBuildOptions; +import org.apache.uima.ruta.descriptor.RutaDescriptorFactory; +import org.apache.uima.ruta.descriptor.RutaDescriptorInformation; import org.junit.Assert; import org.junit.Test; @@ -179,4 +189,56 @@ public class RutaEngineTest { ae.process(cas); } + @Test + public void testProcessWithRulesDeclareWithoutPackage() throws Throwable { + + String rules = "DECLARE MyType; SW{-> MyType};"; + String text = "This is a test"; + + RutaDescriptorFactory rdf = new RutaDescriptorFactory(); + RutaBuildOptions buildOptions = new RutaBuildOptions(); + RutaDescriptorInformation descriptorInformation = rdf.parseDescriptorInformation(rules, "", + buildOptions); + Pair<AnalysisEngineDescription, TypeSystemDescription> descriptions = rdf + .createDescriptions(null, null, descriptorInformation, buildOptions, null, null, null); + + AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(descriptions.getLeft()); + CAS cas = ae.newCAS(); + cas.setDocumentText(text); + + ae.process(cas); + + Type type = cas.getTypeSystem().getType("MyType"); + Assert.assertNotNull(type); + Collection<AnnotationFS> select = CasUtil.select(cas, type); + Assert.assertEquals(3, select.size()); + + } + + @Test + public void testProcessWithRulesDeclareWithPackage() throws Throwable { + + String rules = "PACKAGE pack; DECLARE MyType; SW{-> MyType};"; + String text = "This is a test"; + + RutaDescriptorFactory rdf = new RutaDescriptorFactory(); + RutaBuildOptions buildOptions = new RutaBuildOptions(); + RutaDescriptorInformation descriptorInformation = rdf.parseDescriptorInformation(rules, "", + buildOptions); + Pair<AnalysisEngineDescription, TypeSystemDescription> descriptions = rdf + .createDescriptions(null, null, descriptorInformation, buildOptions, null, null, null); + + AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(descriptions.getLeft()); + CAS cas = ae.newCAS(); + cas.setDocumentText(text); + + ae.process(cas); + + Type type = cas.getTypeSystem().getType("pack.MyType"); + Assert.assertNotNull(type); + Collection<AnnotationFS> select = CasUtil.select(cas, type); + Assert.assertEquals(3, select.size()); + + } + } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/StackedScriptsTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/StackedScriptsTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/StackedScriptsTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/StackedScriptsTest.java Mon Nov 18 12:19:31 2019 @@ -18,7 +18,6 @@ */ package org.apache.uima.ruta.engine; -import static org.apache.uima.fit.factory.AnalysisEngineFactory.createEngine; import static org.apache.uima.fit.factory.AnalysisEngineFactory.createEngineDescription; import java.net.URL; @@ -29,6 +28,7 @@ import org.apache.uima.UIMAFramework; import org.apache.uima.analysis_engine.AnalysisEngine; import org.apache.uima.analysis_engine.AnalysisEngineDescription; import org.apache.uima.cas.CAS; +import org.apache.uima.resource.ResourceManager; import org.apache.uima.resource.ResourceSpecifier; import org.apache.uima.resource.metadata.TypeSystemDescription; import org.apache.uima.util.CasCreationUtils; @@ -52,10 +52,13 @@ public class StackedScriptsTest { @Test public void testWithUimaFitAggregated() throws Exception { - AnalysisEngine aae = createEngine(createEngineDescription( + AnalysisEngineDescription description = createEngineDescription( createEngineDescription(RutaEngine.class, RutaEngine.PARAM_RULES, rules1), createEngineDescription(RutaEngine.class, RutaEngine.PARAM_RULES, rules2), - createEngineDescription(RutaEngine.class, RutaEngine.PARAM_RULES, rules3))); + createEngineDescription(RutaEngine.class, RutaEngine.PARAM_RULES, rules3)); + + ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager(); + AnalysisEngine aae = UIMAFramework.produceAnalysisEngine(description, resourceManager, null); CAS cas = getCAS(LINES); @@ -87,7 +90,6 @@ public class StackedScriptsTest { checkResult(cas, LINES); - cas.release(); } private void checkResult(CAS cas, int lines) { @@ -147,7 +149,8 @@ public class StackedScriptsTest { tsds.add(basicTypeSystem); TypeSystemDescription mergeTypeSystems = CasCreationUtils.mergeTypeSystems(tsds); aed.getAnalysisEngineMetaData().setTypeSystem(mergeTypeSystems); - AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(aed); + ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager(); + AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(aed, resourceManager, null); ae.setConfigParameterValue(RutaEngine.PARAM_RULES, rules); if (reindexOnly != null) { @@ -160,18 +163,24 @@ public class StackedScriptsTest { @Test public void testPerformanceOfReindexOnly() throws Exception { - AnalysisEngine aaeNoReindex = createEngine(createEngineDescription( + AnalysisEngineDescription noReindexDescription = createEngineDescription( createEngineDescription(RutaEngine.class, RutaEngine.PARAM_RULES, rules1), createEngineDescription(RutaEngine.class, RutaEngine.PARAM_RULES, rules2), - createEngineDescription(RutaEngine.class, RutaEngine.PARAM_RULES, rules3))); - AnalysisEngine aaeReindex = createEngine(createEngineDescription( + createEngineDescription(RutaEngine.class, RutaEngine.PARAM_RULES, rules3)); + AnalysisEngineDescription reindexDescription = createEngineDescription( createEngineDescription(RutaEngine.class, RutaEngine.PARAM_RULES, rules1, RutaEngine.PARAM_REINDEX_ONLY, new String[] { CAS.TYPE_NAME_ANNOTATION }), createEngineDescription(RutaEngine.class, RutaEngine.PARAM_RULES, rules2, RutaEngine.PARAM_REINDEX_ONLY, new String[] { RutaTestUtils.TYPE + "1" }), createEngineDescription(RutaEngine.class, RutaEngine.PARAM_RULES, rules3, RutaEngine.PARAM_REINDEX_ONLY, - new String[] { RutaTestUtils.TYPE + "2", RutaTestUtils.TYPE + "3" }))); + new String[] { RutaTestUtils.TYPE + "2", RutaTestUtils.TYPE + "3" })); + + ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager(); + AnalysisEngine aaeNoReindex = UIMAFramework.produceAnalysisEngine(noReindexDescription, + resourceManager, null); + AnalysisEngine aaeReindex = UIMAFramework.produceAnalysisEngine(reindexDescription, + resourceManager, null); long start = 0; long end = 0; Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/UimaFitAnalysisEngineWithManditoryParameterTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/UimaFitAnalysisEngineWithManditoryParameterTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/UimaFitAnalysisEngineWithManditoryParameterTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/UimaFitAnalysisEngineWithManditoryParameterTest.java Mon Nov 18 12:19:31 2019 @@ -19,10 +19,12 @@ package org.apache.uima.ruta.engine; +import org.apache.uima.UIMAFramework; import org.apache.uima.analysis_engine.AnalysisEngine; import org.apache.uima.analysis_engine.AnalysisEngineDescription; import org.apache.uima.cas.CAS; import org.apache.uima.fit.factory.AnalysisEngineFactory; +import org.apache.uima.resource.ResourceManager; import org.apache.uima.ruta.descriptor.RutaBuildOptions; import org.apache.uima.ruta.descriptor.RutaDescriptorFactory; import org.apache.uima.ruta.descriptor.RutaDescriptorInformation; @@ -42,15 +44,16 @@ public class UimaFitAnalysisEngineWithMa RutaDescriptorInformation rdi = factory.parseDescriptorInformation(script); AnalysisEngineDescription aed = factory.createAnalysisEngineDescription(null, rdi, new RutaBuildOptions(), null, null, null, this.getClass().getClassLoader()); - AnalysisEngine ae = AnalysisEngineFactory.createEngine(aed, RutaEngine.PARAM_RULES, script); + aed.getAnalysisEngineMetaData().getConfigurationParameterSettings() + .setParameterValue(RutaEngine.PARAM_RULES, script); + ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager(); + AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(aed, resourceManager, null); CAS cas = RutaTestUtils.getCAS(document); ae.process(cas); RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Some text."); - - cas.release(); } - + @Test public void testScriptOnly() throws Exception { @@ -58,12 +61,12 @@ public class UimaFitAnalysisEngineWithMa String script = "UIMAFIT org.apache.uima.ruta.engine.UimaFitAnalysisEngineWithManditoryParameter (type, " + RutaTestUtils.TYPE + "1);"; script += "EXEC(UimaFitAnalysisEngineWithManditoryParameter);"; - - AnalysisEngine ae = AnalysisEngineFactory.createEngine(RutaEngine.class, RutaEngine.PARAM_RULES, script); + + AnalysisEngine ae = AnalysisEngineFactory.createEngine(RutaEngine.class, RutaEngine.PARAM_RULES, + script); CAS cas = RutaTestUtils.getCAS(document); ae.process(cas); RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Some text."); - cas.release(); } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java Mon Nov 18 12:19:31 2019 @@ -762,4 +762,37 @@ public class AnnotationLabelExpressionTe } + @Test + public void testTemporalFailingLabelAssignment() throws Exception { + + String document = "Some text."; + Map<String, String> typeMap = new TreeMap<String, String>(); + typeMap.put("Struct1", "uima.tcas.Annotation"); + typeMap.put("Struct2", "uima.tcas.Annotation"); + + Map<String, List<TestFeature>> featureMap = new TreeMap<String, List<TestFeature>>(); + List<TestFeature> list = new ArrayList<RutaTestUtils.TestFeature>(); + featureMap.put("Struct1", list); + featureMap.put("Struct2", list); + list.add(new TestFeature("a", "", "uima.tcas.Annotation")); + list.add(new TestFeature("b", "", "uima.tcas.Annotation")); + + String script = ""; + script += "Document{->CREATE(Struct1, \"a\" = a, \"b\" = b)} <-{a:W b:W;};\n"; + script += "Document{->CREATE(Struct2, \"a\" = a, \"b\" = b)} <-{a:W{STARTSWITH(Document)} b:W;};\n"; + script += "Struct1.a{-> T1};\n"; + script += "Struct1.b{-> T2};\n"; + script += "Struct2.a{-> T3};\n"; + script += "Struct2.b{-> T4};\n"; + + CAS cas = RutaTestUtils.getCAS(document, typeMap, featureMap); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Some"); + RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "text"); + RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "Some"); + RutaTestUtils.assertAnnotationsEquals(cas, 4, 1, "text"); + + } + } Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/type/TypeFeatureTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/type/TypeFeatureTest.java?rev=1869967&view=auto ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/type/TypeFeatureTest.java (added) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/type/TypeFeatureTest.java Mon Nov 18 12:19:31 2019 @@ -0,0 +1,48 @@ +/* + * 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.expression.type; + +import org.apache.uima.cas.CAS; +import org.apache.uima.ruta.engine.Ruta; +import org.apache.uima.ruta.engine.RutaTestUtils; +import org.junit.Test; + +public class TypeFeatureTest { + + @Test + public void test() throws Exception { + + String document = "This is a test."; + + String script = "CW{-> T1};\n"; + script += "SW{-> T2};\n"; + script += "T1{-> MARK(T1.type)};\n"; + script += "t2:T2{-> t2.type};\n"; + script += "(a1:ANY a2:ANY){a1.type==a2.type -> T3};\n"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "This", "This"); + RutaTestUtils.assertAnnotationsEquals(cas, 2, 6, "is", "is", "a", "a", "test", "test"); + RutaTestUtils.assertAnnotationsEquals(cas, 3, 2, "is a", "a test"); + + } + +} Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/resource/TreeWordListTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/resource/TreeWordListTest.java?rev=1869967&view=auto ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/resource/TreeWordListTest.java (added) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/resource/TreeWordListTest.java Mon Nov 18 12:19:31 2019 @@ -0,0 +1,110 @@ +/* + * 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.resource; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.apache.uima.cas.CAS; +import org.apache.uima.cas.Type; +import org.apache.uima.cas.TypeSystem; +import org.apache.uima.cas.text.AnnotationFS; +import org.apache.uima.fit.factory.JCasFactory; +import org.apache.uima.jcas.JCas; +import org.apache.uima.ruta.FilterManager; +import org.apache.uima.ruta.RutaStream; +import org.apache.uima.ruta.engine.Ruta; +import org.apache.uima.ruta.engine.RutaTestUtils; +import org.apache.uima.ruta.seed.TextSeeder; +import org.apache.uima.ruta.type.RutaBasic; +import org.apache.uima.ruta.visitor.InferenceCrowd; +import org.junit.Assert; +import org.junit.Test; + +public class TreeWordListTest { + + @Test + public void testWithAction() throws Exception { + + String text = "ab"; + String script = "STRINGLIST list = {\"ab\", \"a c\", \"a d\"};"; + script += "MARKFAST(T1, list);"; + + CAS cas = RutaTestUtils.getCAS(text); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, text); + } + + @Test + public void testFind() throws Exception { + + String text = "ab"; + List<String> data = Arrays.asList(text, "a c", "a d"); + TreeWordList twl = new TreeWordList(data, false); + + JCas jcas = JCasFactory.createJCas(); + jcas.setDocumentText(text); + CAS cas = jcas.getCas(); + RutaStream stream = createStream(text, cas); + + List<AnnotationFS> result1 = twl.find(stream, false, 0, null, 0, false); + Assert.assertEquals(1, result1.size()); + Assert.assertEquals(text, result1.get(0).getCoveredText()); + + List<AnnotationFS> result2 = twl.find(stream, false, 0, null, 0, true); + Assert.assertEquals(1, result2.size()); + Assert.assertEquals(text, result2.get(0).getCoveredText()); + + List<AnnotationFS> result3 = twl.find(stream, true, 0, null, 0, false); + Assert.assertEquals(1, result3.size()); + Assert.assertEquals(text, result3.get(0).getCoveredText()); + } + + private RutaStream createStream(String text, CAS cas) { + Type basicType = cas.getTypeSystem().getType(RutaBasic.class.getName()); + + Collection<Type> filterTypes = getDefaultFilterTypes(cas); + + FilterManager filter = new FilterManager(filterTypes, true, cas); + TextSeeder seeder = new TextSeeder(); + seeder.seed(text, cas); + InferenceCrowd crowd = new InferenceCrowd(new ArrayList<>()); + RutaStream stream = new RutaStream(cas, basicType, filter, false, false, true, null, crowd); + stream.initalizeBasics(new String[] { CAS.TYPE_NAME_ANNOTATION }, false); + return stream; + } + + private Collection<Type> getDefaultFilterTypes(CAS cas) { + Collection<Type> filterTypes = new ArrayList<Type>(); + TypeSystem typeSystem = cas.getTypeSystem(); + String[] defaultFilteredTypes = new String[] { "org.apache.uima.ruta.type.SPACE", + "org.apache.uima.ruta.type.BREAK", "org.apache.uima.ruta.type.MARKUP" }; + for (String each : defaultFilteredTypes) { + Type type = typeSystem.getType(each); + if (type != null) { + filterTypes.add(type); + } + } + return filterTypes; + } + +} \ No newline at end of file Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RutaLiteralMatcherTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RutaLiteralMatcherTest.java?rev=1869967&view=auto ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RutaLiteralMatcherTest.java (added) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RutaLiteralMatcherTest.java Mon Nov 18 12:19:31 2019 @@ -0,0 +1,51 @@ +/* + * 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.rule; + +import org.apache.uima.cas.CAS; +import org.apache.uima.ruta.engine.Ruta; +import org.apache.uima.ruta.engine.RutaTestUtils; +import org.junit.Test; + +public class RutaLiteralMatcherTest { + + @Test + public void test() throws Exception { + + String text = "This is a test."; + String script = ""; +// script += "\"" + text + "\" {-> T1};\n"; +// script += "\"is a\" {-> T2} \"test.\";\n"; +// script += "\"is a test\" {-> T3} @PERIOD;\n"; +// script += "\" \" {-> T4};\n"; +// script += "ADDRETAINTYPE(SPACE);\n\" \" {-> T5};\nREMOVERETAINTYPE(SPACE);\n"; + script += "\" is a test\" {-> T6} @PERIOD;\n"; + + CAS cas = RutaTestUtils.getCAS(text); + Ruta.apply(cas, script); + +// RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, text); +// RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "is a"); +// RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "is a test"); +// RutaTestUtils.assertAnnotationsEquals(cas, 4, 0); +// RutaTestUtils.assertAnnotationsEquals(cas, 5, 3, " ", " ", " "); + RutaTestUtils.assertAnnotationsEquals(cas, 6, 0); + } +} Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/SidestepInComposedTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/SidestepInComposedTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/SidestepInComposedTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/SidestepInComposedTest.java Mon Nov 18 12:19:31 2019 @@ -36,7 +36,34 @@ public class SidestepInComposedTest { Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "15"); + } + + @Test + public void testAnchorAtDisjunct() throws Exception { + String document = "15. Mai 2005"; + String script = "(NUM PERIOD @(SW | CW) NUM){-> T1};\n"; + script += "(NUM PERIOD (@((SW | CW))) NUM){-> T2};\n"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "15. Mai 2005"); + RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "15. Mai 2005"); + + } + + @Test + public void testAnchorAtConjunct() throws Exception { + String document = "15. Mai 2005"; + String script = "(NUM PERIOD @(W & CW) NUM){-> T1};\n"; + script += "(NUM PERIOD (@((CW & W))) NUM){-> T2};\n"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "15. Mai 2005"); + RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "15. Mai 2005"); - cas.release(); } + } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java Mon Nov 18 12:19:31 2019 @@ -76,6 +76,17 @@ public class WildCard2Test { } @Test + public void testOptional2() throws Exception { + String document = "Cw 1 2 3 test"; + String script = "(CW # COLON?){-> T1} SW;"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Cw 1 2 3"); + } + + @Test public void testLookaheadInGreedy() throws Exception { String document = "Some test. Some test. Some test."; String script = "((CW #){-> T1})+;"; @@ -184,6 +195,29 @@ public class WildCard2Test { } @Test + public void testConditionAtComposedWithWildcard() throws Exception { + String document = "1 A a , 2 D d . 3"; + String script = "(NUM #){CONTAINS(CAP)->T1} NUM;"; + script += "((NUM #){CONTAINS(COMMA)}){CONTAINS(PERIOD)-> T2} NUM;"; + script += "((NUM #){CONTAINS(SW)}){CONTAINS(PERIOD)-> T3} NUM;"; + script += "(NUM #){CONTAINS(CAP)->T4} (NUM);"; + script += "((NUM #){CONTAINS(CAP)->T5}) ((NUM));"; + script += "((NUM #){CONTAINS(CAP)->T6}) \"2\";"; + script += "((NUM #){CONTAINS(CAP)->T7}) \"3\";"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 0); + RutaTestUtils.assertAnnotationsEquals(cas, 2, 0); + RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "2 D d ."); + RutaTestUtils.assertAnnotationsEquals(cas, 4, 0); + RutaTestUtils.assertAnnotationsEquals(cas, 5, 0); + RutaTestUtils.assertAnnotationsEquals(cas, 6, 0); + RutaTestUtils.assertAnnotationsEquals(cas, 7, 0); + } + + @Test public void testDuplicateAnnotation() throws Exception { String document = "x x x 1 a b c 2 d e f 3"; String script = "NUM{->T1, T1};"; @@ -209,6 +243,20 @@ public class WildCard2Test { } @Test + public void testInlinedRulesAtWildcardWithOptional() throws Exception { + String document = "1 a a b / A 1"; + String script = "NUM #{->T1} NUM;\n"; + script += "T1{->T2}<-{# COLON? CW;} NUM;\n"; + script += "T2 -> {(#<-{SW # NUM?;} COLON? SPECIAL){-> T3} CW;};\n"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "a a b / A"); + RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "a a b /"); + } + + @Test public void testWithFailingNextRuleElement() throws Exception { String document = "a b c 1 d e f 2 g h i 3 / 4 m n o"; String script = "\"a\" -> T1;\n"; Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCardInWindowTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCardInWindowTest.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCardInWindowTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCardInWindowTest.java Mon Nov 18 12:19:31 2019 @@ -41,7 +41,6 @@ public class WildCardInWindowTest { e.printStackTrace(); } - RutaTestUtils.assertAnnotationsEquals(cas, 1, 4, "a 1 b", "c 1 D", "e 1 1 1 f", "g 1 1 1 H"); RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "1", "1 1 1"); RutaTestUtils.assertAnnotationsEquals(cas, 3, 2, "b", "f"); RutaTestUtils.assertAnnotationsEquals(cas, 4, 2, "1", "1 1 1"); Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/visitor/InlinedRulesExplanationTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/visitor/InlinedRulesExplanationTest.java?rev=1869967&view=auto ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/visitor/InlinedRulesExplanationTest.java (added) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/visitor/InlinedRulesExplanationTest.java Mon Nov 18 12:19:31 2019 @@ -0,0 +1,105 @@ +/* + * 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.visitor; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.uima.cas.CAS; +import org.apache.uima.cas.FeatureStructure; +import org.apache.uima.fit.util.JCasUtil; +import org.apache.uima.jcas.JCas; +import org.apache.uima.jcas.cas.FSArray; +import org.apache.uima.ruta.engine.Ruta; +import org.apache.uima.ruta.engine.RutaEngine; +import org.apache.uima.ruta.engine.RutaTestUtils; +import org.apache.uima.ruta.type.DebugBlockApply; +import org.apache.uima.ruta.type.DebugMatchedRuleMatch; +import org.apache.uima.ruta.type.DebugRuleApply; +import org.apache.uima.ruta.type.DebugRuleElementMatch; +import org.apache.uima.ruta.type.DebugRuleElementMatches; +import org.apache.uima.ruta.type.DebugScriptApply; +import org.junit.Assert; +import org.junit.Test; + +public class InlinedRulesExplanationTest { + + @Test + public void test() throws Exception { + + String document = "This is a test."; + String script = ""; + script += "CW<-{ANY;W;}<-{ANY;CW;}->{Document;} SW<-{ANY; SW;}->{Document; ANY;}->{ANY; NUM;};"; + + CAS cas = RutaTestUtils.getCAS(document); + Map<String, Object> parameters = new HashMap<>(); + parameters.put(RutaEngine.PARAM_DEBUG, Boolean.TRUE); + parameters.put(RutaEngine.PARAM_DEBUG_WITH_MATCHES, Boolean.TRUE); + + Ruta.apply(cas, script, parameters); + + JCas jcas = cas.getJCas(); + + Collection<DebugScriptApply> debugScriptApplies = JCasUtil.select(jcas, DebugScriptApply.class); + Assert.assertEquals(1, debugScriptApplies.size()); + DebugScriptApply debugScriptApply = debugScriptApplies.iterator().next(); + Assert.assertTrue(debugScriptApply instanceof DebugBlockApply); + DebugBlockApply debugBlockApply = (DebugBlockApply) debugScriptApply; + + FSArray innerApply = debugBlockApply.getInnerApply(); + Assert.assertEquals(1, innerApply.size()); + FeatureStructure innerApplyFS = innerApply.get(0); + Assert.assertTrue(debugScriptApply instanceof DebugRuleApply); + DebugRuleApply debugRuleApply = (DebugRuleApply) innerApplyFS; + + FSArray rules = debugRuleApply.getRules(); + Assert.assertEquals(1, rules.size()); + FeatureStructure ruleMatchFS = rules.get(0); + Assert.assertTrue(ruleMatchFS instanceof DebugMatchedRuleMatch); + DebugMatchedRuleMatch debugMatchedRuleMatch = (DebugMatchedRuleMatch) ruleMatchFS; + Assert.assertEquals(0, debugMatchedRuleMatch.getDelegates().size()); + + FSArray reMatchesArray = debugMatchedRuleMatch.getElements(); + Assert.assertEquals(2, reMatchesArray.size()); + FeatureStructure reMatches1FS = reMatchesArray.get(0); + FeatureStructure reMatches2FS = reMatchesArray.get(1); + Assert.assertTrue(reMatches1FS instanceof DebugRuleElementMatches); + Assert.assertTrue(reMatches2FS instanceof DebugRuleElementMatches); + DebugRuleElementMatches re1Matches = (DebugRuleElementMatches) reMatches1FS; + DebugRuleElementMatches re2Matches = (DebugRuleElementMatches) reMatches2FS; + + FSArray inlinedActionRules1 = re1Matches.getInlinedActionBlocks(); + FSArray inlinedActionRules2 = re2Matches.getInlinedActionBlocks(); + + Assert.assertEquals(1, inlinedActionRules1.size()); + Assert.assertEquals(2, inlinedActionRules2.size()); + + DebugRuleElementMatch re1Match = (DebugRuleElementMatch) re1Matches.getMatches().get(0); + DebugRuleElementMatch re2Match = (DebugRuleElementMatch) re2Matches.getMatches().get(0); + + FSArray inlinedConditionRules1 = re1Match.getInlinedConditionBlocks(); + FSArray inlinedConditionRules2 = re2Match.getInlinedConditionBlocks(); + + Assert.assertEquals(2, inlinedConditionRules1.size()); + Assert.assertEquals(1, inlinedConditionRules2.size()); + + } +} Modified: uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.overview.xml URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.overview.xml?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.overview.xml (original) +++ uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.overview.xml Mon Nov 18 12:19:31 2019 @@ -254,7 +254,7 @@ Document{-> MARKFAST(Animal, AnimalsList <para> - There is a <quote>wild card</quote> rule element, which can be used to skip some text or annotations until the next rule element is able to match. + There is a <quote>wild card</quote> (<quote>#</quote>) rule element, which can be used to skip some text or annotations until the next rule element is able to match. </para> <programlisting><![CDATA[DECLARE Sentence; @@ -262,7 +262,24 @@ PERIOD #{-> MARK(Sentence)} PERIOD;]]></ <para> This rule annotates everything between two <quote>PERIOD</quote> annotations with the type <quote>Sentence</quote>. Please note that the resulting - annotations is automatically trimmed using the current filtering settings. + annotations is automatically trimmed using the current filtering settings. Conditions at wild card rule elements should by avoided and only be used + by advanced users. + </para> + + <para> + Another special rule element is called <quote>optional</quote> (<quote>_</quote>). Sometimes, an annotation should be created on a + text position if it is not followed by an annotation of a specific property. In contrast to normal rule elements with optional quantifier, + the optional rule element does not need to match at all. + </para> + + <programlisting><![CDATA[W ANY{-PARTOF(NUM)}; +W _{-PARTOF(NUM)};]]></programlisting> + + <para> + The two rules in this example specify the same pattern: A word that is not followed by a number. The difference between the rules + shows itself at the border of the matching window, e.g., at the end of the document. If the document contains only a single word, + the first rule will not match successfully because the second rule element already fails at its matching condition. The second rule, however, + will successfully match due to the optional rule element. </para> <para> @@ -413,21 +430,31 @@ Entity{-> MentionedAfter, MentionedAfter </para> <para> - Expressions for annoations can be extended by a feature match and also conditions. This does also apply for type expressions - that represent annoations. This functionality is illustrated with a simple example: + Expressions for annotations can be extended by a feature match and also conditions. This does also apply for type expressions + that represent annotations. This functionality is illustrated with a simple example: </para> <programlisting><![CDATA[Sentence{-> CREATE(EmplRelation, "employeeRef" = -Employee.ct=="Peter"{ENDSWITH(Sentence)})};]]></programlisting> + Employee.ct=="Peter"{ENDSWITH(Sentence)})};]]></programlisting> <para> - Here, an annotation of the type <code>EmplRelation</code> ios created for each sentence. + Here, an annotation of the type <code>EmplRelation</code> is created for each sentence. The feature <code>employeeRef</code> is filled with one <code>Employee</code> annotation. This annotation is specified by its type <code>Employee</code>. The first annotation - of this type within the matched sentence, which coveres the text <quote>Peter</quote> and also + of this type within the matched sentence, which covers the text <quote>Peter</quote> and also ends with a <code>Sentence</code> annotation, is selected. </para> <para> + Sometimes, an annotation which was just created by an action should be assigned to a feature. + This can be achieved by referring to the annotation given its type like it was shown in the + first example with <quote>EmplRelation</quote>. However, this can cause problems in situations, e.g. where + several annotation of a type are present at a specific span. Local variables using labels can also be used directly at actions, + which create or modify actions. The action will assign the new annotation the the label variable, + which can then be utilized by following actions as shown in the following example: + </para> + <programlisting><![CDATA[W.ct=="Peter"{-> e:Employee, CREATE(EmplRelation, "employeeRef" = e)};]]></programlisting> + + <para> In the last examples, the values of features were defined as annotation types. However, also primitive types can be used, as will be shown in the next example, together with a short introduction of variables. </para> @@ -559,8 +586,16 @@ Sentence{}->{ <programlisting><![CDATA[DECLARE SentenceWithNPNP; Sentence{-> SentenceWithNPNP}<-{ NP NP; -}; -]]></programlisting> +};]]></programlisting> + + <para> + A rule element may be extended with several inlined rule block as condition or action. If there a more than one inlined rule blocks as condition, + each needs to contain at least one rule that was successfully applied. In the following example, the rule will one match if the sentence contains + a number followed by a another number and a period followed by a comma, independently from their location within the sentence: + </para> + + <programlisting><![CDATA[Sentence<-{NUM NUM;}<-{PERIOD COMMA;};]]></programlisting> + <para> Let us take a closer look on what exactly the UIMA Ruta rules match. The following rule matches on a word followed by another word: </para> Modified: uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.workbench.explain_perspective.xml URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.workbench.explain_perspective.xml?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.workbench.explain_perspective.xml (original) +++ uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.workbench.explain_perspective.xml Mon Nov 18 12:19:31 2019 @@ -244,6 +244,28 @@ <quote>NameLinker</quote> annotation the whole rule fails. </para> </section> + + <section + id="section.ugr.tools.ruta.workbench.explain_perspective.inlined_rules"> + <title>Inlined Rules</title> + <para> + The Inlined Rules view provides additional information about the blocks of rules + that are inlined as condition or as actions. The view is automatically updated + if a element in a different view is selected, which contains inlined rules. + This includes the Rule Elements view, the Matched View and the Failed View. + If a rule apply in the Applied Rules View contains only a single rule match + and this match, then the Inlined Rules View is also updated. + If a rule apply in the Inlined Rules View is selected, then + the Matched Rules View and the Failed Rules View is updated with the matched + of this inlined rule. + </para> + <para> + This view is not by default included in the perspective, but need to be added manually, + e.g., by using the Quick Access near the perspectives. + </para> + + + </section> <section id="section.ugr.tools.ruta.workbench.explain_perspective.covering_rules"> Modified: uima/uv3/ruta-v3/trunk/ruta-eclipse-update-site/pom.xml URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-eclipse-update-site/pom.xml?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-eclipse-update-site/pom.xml (original) +++ uima/uv3/ruta-v3/trunk/ruta-eclipse-update-site/pom.xml Mon Nov 18 12:19:31 2019 @@ -23,7 +23,7 @@ <parent> <groupId>org.apache.uima</groupId> <artifactId>parent-pom</artifactId> - <version>12</version> + <version>13</version> <relativePath /> </parent> @@ -53,6 +53,7 @@ <eclipseUpdateSubSite>${project.build.directory}/eclipse-update-site/${eclipseUpdateSiteComponent}</eclipseUpdateSubSite> <item-maven-release-version>3.0.0</item-maven-release-version> <item-eclipse-release-version>3.0.0</item-eclipse-release-version> + <dropPrevVersions>false</dropPrevVersions> </properties> <build> <pluginManagement> Modified: uima/uv3/ruta-v3/trunk/ruta-ep-addons/plugin.xml URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-ep-addons/plugin.xml?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-ep-addons/plugin.xml (original) +++ uima/uv3/ruta-v3/trunk/ruta-ep-addons/plugin.xml Mon Nov 18 12:19:31 2019 @@ -605,6 +605,13 @@ under the License. id="org.apache.uima.ruta.explain.failed" name="Failed Rules"> </view> + <view + category="org.apache.uima.ruta.ide.ui" + class="org.apache.uima.ruta.explain.inlined.InlinedView" + icon="icons/chart_organisation.png" + id="org.apache.uima.ruta.explain.inlined" + name="Inlined Rules"> + </view> <view category="org.apache.uima.ruta.ide.ui" class="org.apache.uima.ruta.explain.element.ElementView" Modified: uima/uv3/ruta-v3/trunk/ruta-ep-addons/pom.xml URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-ep-addons/pom.xml?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-ep-addons/pom.xml (original) +++ uima/uv3/ruta-v3/trunk/ruta-ep-addons/pom.xml Mon Nov 18 12:19:31 2019 @@ -172,6 +172,7 @@ <exclude>release.properties</exclude> <!-- release generated artifact --> <exclude>src/test/resources/ManualTests/*</exclude> <!-- test data --> <exclude>marker-file-identifying-*</exclude> + <exclude>META-INF/MANIFEST.MF</exclude> <exclude>issuesFixed/**</exclude> </excludes> </configuration> @@ -192,7 +193,7 @@ <instructions> <Bundle-SymbolicName>org.apache.uima.ruta.addons;singleton:=true</Bundle-SymbolicName> <Bundle-Activator>org.apache.uima.ruta.addons.RutaAddonsPlugin</Bundle-Activator> - <Bundle-RequiredExecutionEnvironment>JavaSE-1.7</Bundle-RequiredExecutionEnvironment> + <Bundle-RequiredExecutionEnvironment>JavaSE-1.8</Bundle-RequiredExecutionEnvironment> <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy> <_nouses>true</_nouses> <Export-Package> Modified: uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/RutaGEConstraint.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/RutaGEConstraint.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/RutaGEConstraint.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/RutaGEConstraint.java Mon Nov 18 12:19:31 2019 @@ -113,6 +113,7 @@ public class RutaGEConstraint implements ae.reconfigure(); } + @Override public Double processConstraint(CAS cas) throws Exception { if (!initalized) { initialize(); @@ -120,8 +121,8 @@ public class RutaGEConstraint implements int runCount = 0; int printCount = 0; ArrayList<Double[]> results = new ArrayList<Double[]>(); - Type matchedType = cas.getTypeSystem().getType( - "org.apache.uima.ruta.type.DebugMatchedRuleMatch"); + Type matchedType = cas.getTypeSystem() + .getType("org.apache.uima.ruta.type.DebugMatchedRuleMatch"); Type ruleApplyType = cas.getTypeSystem().getType("org.apache.uima.ruta.type.DebugRuleApply"); Type blockApplyType = cas.getTypeSystem().getType("org.apache.uima.ruta.type.DebugBlockApply"); @@ -155,8 +156,6 @@ public class RutaGEConstraint implements Double ratioInConstraint = rulesMap.get(key); if (ratioInConstraint != null) { results.add(new Double[] { ratioInConstraint, ratioInDocument }); - } else { - System.out.println("rule not found!!!: " + key); } } } @@ -169,13 +168,13 @@ public class RutaGEConstraint implements removeDebugAnnotations(cas, matchedType, ruleApplyType, blockApplyType); ae.destroy(); - runCount++; - printCount++; - if (printCount == 10) { - System.out.println(runCount); - System.out.println("time: " + System.currentTimeMillis()); - printCount = 0; - } +// runCount++; +// printCount++; +// if (printCount == 10) { +// System.out.println(runCount); +// System.out.println("time: " + System.currentTimeMillis()); +// printCount = 0; +// } // calculate cosinus similarity for result values: return EvaluationMeasures.cosine(results); @@ -201,10 +200,12 @@ public class RutaGEConstraint implements } } + @Override public String getDescription() { return this.description; } + @Override public void setDescription(String description) { this.description = description; } @@ -248,10 +249,12 @@ public class RutaGEConstraint implements return rulesMap; } + @Override public String getData() { return constraintText; } + @Override public void setData(String data) { this.constraintText = data; } Modified: uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintXMLUtils.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintXMLUtils.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintXMLUtils.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintXMLUtils.java Mon Nov 18 12:19:31 2019 @@ -24,9 +24,9 @@ import java.io.FileReader; import java.util.List; import org.apache.commons.io.FileUtils; +import org.apache.uima.internal.util.XMLUtils; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; public class ConstraintXMLUtils { @@ -46,15 +46,16 @@ public class ConstraintXMLUtils { } public static List<ConstraintData> readConstraints(String location) throws Exception { - XMLReader xmlReader = XMLReaderFactory.createXMLReader(); - xmlReader.setFeature("http://xml.org/sax/features/external-general-entities", false); - xmlReader.setFeature("http://xml.org/sax/features/external-parameter-entities", false); - xmlReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false); - FileReader reader = new FileReader(location); - InputSource inputSource = new InputSource(reader); - ConstraintContentHandler handler = new ConstraintContentHandler(); - xmlReader.setContentHandler(handler); - xmlReader.parse(inputSource); - return handler.getConstraints(); + + try (FileReader reader = new FileReader(location)) { + + InputSource inputSource = new InputSource(reader); + ConstraintContentHandler handler = new ConstraintContentHandler(); + XMLReader xmlReader = XMLUtils.createXMLReader(); + xmlReader.setContentHandler(handler); + xmlReader.parse(inputSource); + return handler.getConstraints(); + } + } } Modified: uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckComposite.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckComposite.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckComposite.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/AnnotationCheckComposite.java Mon Nov 18 12:19:31 2019 @@ -732,7 +732,7 @@ public class AnnotationCheckComposite ex } File dataFile = new File(goldFolderLocation, "data.xml"); try { - XMLUtils.write(docs, dataFile); + CheckDocumentXMLUtils.write(docs, dataFile); } catch (IOException e) { RutaAddonsPlugin.error(e); } Added: uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocumentXMLUtils.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocumentXMLUtils.java?rev=1869967&view=auto ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocumentXMLUtils.java (added) +++ uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/CheckDocumentXMLUtils.java Mon Nov 18 12:19:31 2019 @@ -0,0 +1,64 @@ +/* + * 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.check; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.uima.internal.util.XMLUtils; +import org.apache.uima.util.FileUtils; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +public class CheckDocumentXMLUtils { + + public static void write(List<CheckDocument> docs, File file) throws IOException { + StringBuilder sb = new StringBuilder(); + sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); + sb.append("\n"); + sb.append("<documents>"); + sb.append("\n"); + for (CheckDocument checkDocument : docs) { + sb.append(checkDocument.toXML()); + } + sb.append("</documents>"); + FileUtils.saveString2File(sb.toString(), file, "UTF-8"); + } + + public static List<CheckDocument> read(File file) throws SAXException, IOException { + if (file == null || !file.exists()) { + return new ArrayList<CheckDocument>(); + } + + try (FileReader reader = new FileReader(file)) { + InputSource inputSource = new InputSource(reader); + CheckDocumentsContentHandler handler = new CheckDocumentsContentHandler(); + XMLReader xmlReader = XMLUtils.createXMLReader(); + xmlReader.setContentHandler(handler); + xmlReader.parse(inputSource); + return handler.getCheckDocuments(); + } + } + +} Modified: uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/UpdateTaskHandler.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/UpdateTaskHandler.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/UpdateTaskHandler.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/UpdateTaskHandler.java Mon Nov 18 12:19:31 2019 @@ -108,7 +108,7 @@ public class UpdateTaskHandler implement File dataFile = new File(documentSink, "data.xml"); List<CheckDocument> docs = new ArrayList<CheckDocument>(); try { - docs = XMLUtils.read(dataFile); + docs = CheckDocumentXMLUtils.read(dataFile); } catch (SAXException e) { RutaAddonsPlugin.error(e); } catch (IOException e) { Modified: uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/ExplainConstants.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/ExplainConstants.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/ExplainConstants.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/ExplainConstants.java Mon Nov 18 12:19:31 2019 @@ -22,6 +22,17 @@ package org.apache.uima.ruta.explain; import org.apache.uima.ruta.engine.RutaEngine; public class ExplainConstants { + + public static final String INLINED_AS_CONDITION = "inlinedAsCondition"; + + public static final String INLINED_AS_ACTION = "inlinedAsAction"; + + public static final String INLINED_ACTION_BLOCK = "inlinedActionBlock"; + + public static final String INLINED_CONDITION_BLOCK_MATCHED = "inlinedConditionBlockMatched"; + + public static final String INLINED_CONDITION_BLOCK_FAILED = "inlinedConditionBlockFailed"; + public static final String BASIC_TYPE = RutaEngine.BASIC_TYPE; public static final String SCRIPT_APPLY_TYPE = "org.apache.uima.ruta.type.DebugScriptApply"; Modified: uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/apply/ApplyTreeContentProvider.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/apply/ApplyTreeContentProvider.java?rev=1869967&r1=1869966&r2=1869967&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/apply/ApplyTreeContentProvider.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/apply/ApplyTreeContentProvider.java Mon Nov 18 12:19:31 2019 @@ -29,6 +29,7 @@ import org.eclipse.jface.viewers.Viewer; public class ApplyTreeContentProvider implements ITreeContentProvider { + @Override public Object[] getChildren(Object parentElement) { if (parentElement instanceof IExplainTreeNode) { List<Object> result = new ArrayList<Object>(); @@ -43,6 +44,7 @@ public class ApplyTreeContentProvider im return null; } + @Override public Object getParent(Object element) { if (element instanceof IExplainTreeNode) { return ((IExplainTreeNode) element).getParent(); @@ -50,10 +52,12 @@ public class ApplyTreeContentProvider im return null; } + @Override public Object[] getElements(Object parentElement) { return getChildren(parentElement); } + @Override public boolean hasChildren(Object parentElement) { if (parentElement instanceof IExplainTreeNode) { IExplainTreeNode debugNode = (IExplainTreeNode) parentElement; @@ -66,10 +70,11 @@ public class ApplyTreeContentProvider im return false; } + @Override public void dispose() { } + @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } - }
