Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/resource/CSVTableTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/resource/CSVTableTest.java?rev=1851430&view=auto ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/resource/CSVTableTest.java (added) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/resource/CSVTableTest.java Wed Jan 16 11:45:02 2019 @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.uima.ruta.resource; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.io.IOException; + +import org.junit.Test; + +public class CSVTableTest { + private static final String CUSTOM_SEPARATOR = "#|#"; + + @Test + public void testDefaultLookup() throws IOException { + CSVTable csvTable = new CSVTable(CSVTable.class.getResourceAsStream("test_csvfile.csv"), + CSVTable.DEFAULT_CSV_SEPARATOR); + checkValue(csvTable, 0, 0, "this is the first line first column"); + checkValue(csvTable, 0, 1, "ONE"); + checkValue(csvTable, 1, 0, "this is the second line first column"); + checkValue(csvTable, 1, 1, "TWO"); + checkValue(csvTable, 2, 0, "this is the a line with custom"); + checkValue(csvTable, 2, 1, " non default separator used#|#THREE"); + } + + @Test + public void testDefaultLookupWithEmptyColumn() throws IOException { + CSVTable csvTable = new CSVTable(CSVTable.class.getResourceAsStream("test_csvfile.csv"), + CSVTable.DEFAULT_CSV_SEPARATOR); + checkValue(csvTable, 3, 0, "line with empty column"); + checkValue(csvTable, 3, 1, " "); // spacer added by table implementation + checkValue(csvTable, 3, 2, "AFTER_EMPTY_COLUMN"); + } + + @Test + public void testLookupWithCustomSeparator() throws IOException { + CSVTable csvTable = new CSVTable(CSVTable.class.getResourceAsStream("test_csvfile.csv"), + CUSTOM_SEPARATOR); + checkValue(csvTable, 0, 0, "this is the first line first column;ONE"); + checkValue(csvTable, 1, 0, "this is the second line first column;TWO"); + checkValue(csvTable, 2, 0, "this is the a line with custom; non default separator used"); + checkValue(csvTable, 2, 1, "THREE"); + } + + @Test + public void testLookupWithCustomSeparatorAndEmptyColumn() throws IOException { + CSVTable csvTable = new CSVTable(CSVTable.class.getResourceAsStream("test_csvfile.csv"), + CUSTOM_SEPARATOR); + checkValue(csvTable, 4, 0, "line with empty column custom separator"); + checkValue(csvTable, 4, 1, " "); // spacer added by table implementation + checkValue(csvTable, 4, 2, "AFTER_EMPTY_COLUMN2"); + } + + private void checkValue(CSVTable table, int row, int column, String expectedValue) { + String actualValue = table.getEntry(row, column); + assertThat(actualValue, is(expectedValue)); + } + +} \ No newline at end of file
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/InlinedRulesTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/InlinedRulesTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/InlinedRulesTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/InlinedRulesTest.java Wed Jan 16 11:45:02 2019 @@ -19,73 +19,77 @@ package org.apache.uima.ruta.rule; +import java.io.IOException; + import org.apache.uima.cas.CAS; +import org.apache.uima.resource.ResourceInitializationException; import org.apache.uima.ruta.engine.Ruta; import org.apache.uima.ruta.engine.RutaTestUtils; +import org.apache.uima.util.InvalidXMLException; import org.junit.Test; public class InlinedRulesTest { @Test - public void test() { + public void test() throws Exception { String document = "The Ruta language is an imperative rule language extended with scripting elements. A Ruta rule defines a pattern of annotations with additional conditions. If this pattern applies, then the actions of the rule are performed on the matched annotations. A rule is composed of a sequence of rule elements and a rule element essentially consists of four parts: A matching condition, an optional quantifier, a list of conditions and a list of actions. The matching condition is typically a type of an annotation by which the rule element matches on the covered text of one of those annotations. The quantifier specifies, whether it is necessary that the rule element successfully matches and how often the rule element may match. The list of conditions specifies additional constraints that the matched text or annotations need to fulfill. The list of actions defines the consequences of the rule and often creates new annotations or modifies existing annotations."; String script = ""; script += "PERIOD #{-> T1} @PERIOD;\n"; script += "#{-> T1} PERIOD;\n"; - // inlined as block - script += "T1{STARTSWITH(Document)}->{CW{->T2};};\n"; - script += "(T1 PERIOD T1){CONTAINS(COLON)}->{COMMA #{->T3} COMMA; COLON ANY{-> T4};};\n"; - script += "(COLON # COMMA)->{ANY{REGEXP(\"a.*\", true)-> T5};};"; - // inlined as condition - script += "T1{->T6}<-{ANY COLON ANY{->T6};};\n"; - script += "T1{->T7}<-{CW COLON CW{->T7};};\n"; - script += - "(T1 PERIOD{ -> T8} T1){CONTAINS(COLON)}<-{CW COLON CW{->T9}; COLON ANY{-> T10};};\n"; - script += "(T1 PERIOD{ -> T11} T1){CONTAINS(COLON)}<-{CW COLON CW{->T11};};\n"; - script += - "(T1 PERIOD T1{-> T12}){CONTAINS(COLON)}<-{W COLON (W W)<-{ANY{REGEXP(\"match.*\")};};};\n"; + // inlined as block + script += "T1{STARTSWITH(Document)}->{CW{->T2};};\n"; + script += "(T1 PERIOD T1){CONTAINS(COLON)}->{COMMA #{->T3} COMMA; COLON ANY{-> T4};};\n"; + script += "(COLON # COMMA)->{ANY{REGEXP(\"a.*\", true)-> T5};};"; + // inlined as condition + script += "T1{->T6}<-{ANY COLON ANY{->T6};};\n"; + script += "T1{->T7}<-{CW COLON CW{->T7};};\n"; + script += "(T1 PERIOD{ -> T8} T1){CONTAINS(COLON)}<-{CW COLON CW{->T9}; COLON ANY{-> T10};};\n"; + script += "(T1 PERIOD{ -> T11} T1){CONTAINS(COLON)}<-{CW COLON CW{->T11};};\n"; + script += "(T1 PERIOD T1{-> T12}){CONTAINS(COLON)}<-{W COLON (W W)<-{ANY{REGEXP(\"match.*\")};};};\n"; // both types script += "T1<-{W COLON W W;}->{COLON{->T13};};\n"; script += "(T1 PERIOD T1){CONTAINS(COLON)}<-{W COLON (W W)<-{ANY{REGEXP(\"match.*\")};}->{W{->T14};};};\n"; - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document); - Ruta.apply(cas, script); - } catch (Exception e) { - } + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "The", "Ruta"); - RutaTestUtils - .assertAnnotationsEquals( - cas, - 3, - 3,// - "then the actions of the rule are performed on the matched annotations. A rule is composed of a sequence of rule elements and a rule element essentially consists of four parts: A matching condition", - "an optional quantifier", "an optional quantifier"); + RutaTestUtils.assertAnnotationsEquals(cas, 3, 3, // + "then the actions of the rule are performed on the matched annotations. A rule is composed of a sequence of rule elements and a rule element essentially consists of four parts: A matching condition", + "an optional quantifier", "an optional quantifier"); RutaTestUtils.assertAnnotationsEquals(cas, 4, 2, "A", "A"); RutaTestUtils.assertAnnotationsEquals(cas, 5, 1, "A"); - RutaTestUtils - .assertAnnotationsEquals( - cas, - 6, - 2, // - "A rule is composed of a sequence of rule elements and a rule element essentially consists of four parts: A matching condition, an optional quantifier, a list of conditions and a list of actions", - "A"); + RutaTestUtils.assertAnnotationsEquals(cas, 6, 2, // + "A rule is composed of a sequence of rule elements and a rule element essentially consists of four parts: A matching condition, an optional quantifier, a list of conditions and a list of actions", + "A"); RutaTestUtils.assertAnnotationsEquals(cas, 7, 0); RutaTestUtils.assertAnnotationsEquals(cas, 8, 2, ".", "."); RutaTestUtils.assertAnnotationsEquals(cas, 9, 0); RutaTestUtils.assertAnnotationsEquals(cas, 10, 2, "A", "A"); RutaTestUtils.assertAnnotationsEquals(cas, 11, 0); - RutaTestUtils - .assertAnnotationsEquals( - cas, - 12, - 2, // - "A rule is composed of a sequence of rule elements and a rule element essentially consists of four parts: A matching condition, an optional quantifier, a list of conditions and a list of actions", - "The matching condition is typically a type of an annotation by which the rule element matches on the covered text of one of those annotations"); + RutaTestUtils.assertAnnotationsEquals(cas, 12, 2, // + "A rule is composed of a sequence of rule elements and a rule element essentially consists of four parts: A matching condition, an optional quantifier, a list of conditions and a list of actions", + "The matching condition is typically a type of an annotation by which the rule element matches on the covered text of one of those annotations"); RutaTestUtils.assertAnnotationsEquals(cas, 13, 1, ":"); RutaTestUtils.assertAnnotationsEquals(cas, 14, 4, "A", "A", "matching", "matching"); + } - cas.release(); + @Test + public void testMultipleInlinedRuleBlocks() throws Exception { + String document ="AA 22 bb CC"; + String script = ""; + script += "Document{-> T1};\n"; + // inlined as condition + script += "T1{-> T2} <- {CAP NUM;} <- {SW CAP;};\n"; + script += "T1{-> T5} <- {CAP NUM;} <- {SW SW;};\n"; + // inlined as action + script += "T1 -> {(CAP NUM){->T3};} -> {(SW CAP){->T4};};\n"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "AA 22 bb CC"); + RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "AA 22"); + RutaTestUtils.assertAnnotationsEquals(cas, 4, 1, "bb CC"); + RutaTestUtils.assertAnnotationsEquals(cas, 5, 0); } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/MarkInGreedyComposedTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/MarkInGreedyComposedTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/MarkInGreedyComposedTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/MarkInGreedyComposedTest.java Wed Jan 16 11:45:02 2019 @@ -27,112 +27,76 @@ import org.junit.Test; public class MarkInGreedyComposedTest { @Test - public void testWildCardFollowedByComposedReversed() { + public void testWildCardFollowedByComposedReversed() throws Exception { String document = "1 x f B e d B x c A b a A 1"; String script = ""; script += "( ( (SW{REGEXP(\"x\")} SW ) #) {-> T1} )+ @NUM;"; - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } - RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "x f B e d B", "x c A b a A"); + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); - cas.release(); + RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "x f B e d B", "x c A b a A"); } @Test - public void testSimpleFollowedByComposedReversed() { + public void testSimpleFollowedByComposedReversed() throws Exception { String document = "1 x f B x c A 1"; String script = ""; script += "( ( (SW{REGEXP(\"x\")} SW ) CW) {-> T1} )+ @NUM;"; - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } - RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "x f B", "x c A"); + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); - cas.release(); + RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "x f B", "x c A"); } @Test - public void testWildCardFollowedByComposed() { + public void testWildCardFollowedByComposed() throws Exception { String document = "A c b A c x A c b A c x"; String script = ""; script += "( ( # (SW SW{REGEXP(\"x\")}) ) {-> T1} )+;"; - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } - RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "A c b A c x", "A c b A c x"); + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); - cas.release(); + RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "A c b A c x", "A c b A c x"); } @Test - public void testWildCardFollowedByCondition() { + public void testWildCardFollowedByCondition() throws Exception { String document = "A A b A c X X b X c"; String script = ""; script += "((# SW{REGEXP(\"c\")}){-> T1})+; "; - script += "((# SW{REGEXP(\"c\")}){-> MARKONCE(T2)})+; "; - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } + script += "((# SW{REGEXP(\"c\")}){-> MARKONCE(T2)})+;"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "A A b A c", "X X b X c"); RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "A A b A c", "X X b X c"); - - cas.release(); } @Test - public void testWithWildCard() { + public void testWithWildCard() throws Exception { String document = "1 . 2 ."; String script = ""; script += "((# PERIOD){-> T1})+; "; - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } - RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "1 .", "2 ."); + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); - cas.release(); + RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "1 .", "2 ."); } @Test - public void test() { + public void test() throws Exception { String document = "1 . 2 ."; String script = ""; script += "((NUM PERIOD){-> MARKONCE(T1)})+; "; - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } - RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "1 .", "2 ."); + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); - cas.release(); + RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "1 .", "2 ."); } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RegExpRuleTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RegExpRuleTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RegExpRuleTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RegExpRuleTest.java Wed Jan 16 11:45:02 2019 @@ -36,6 +36,7 @@ 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.Assert; import org.junit.Test; public class RegExpRuleTest { @@ -147,4 +148,23 @@ public class RegExpRuleTest { RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "concept", "a"); } + @Test + public void testPartitioningInSequentialMatching() throws Exception { + String document = "11\n11ab\n1122\n11"; + String script = " "; + + script += "\"11\" -> T1;\r\n"; + script += "\"[0-9]\" -> T2;\r\n"; + script += "ADDRETAINTYPE(WS);\r\n"; + script += "a:(T1 Annotation*{PARTOF({W,T2})}){-> T3};\r\n"; + script += "REMOVERETAINTYPE(WS);"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 4, "11", "11", "11", "11"); + Assert.assertEquals(10, + cas.getAnnotationIndex(cas.getTypeSystem().getType(RutaTestUtils.TYPE + "2")).size()); + RutaTestUtils.assertAnnotationsEquals(cas, 3, 4, "11", "11ab", "1122", "11"); + } } Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RutaOptionalRuleElementTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RutaOptionalRuleElementTest.java?rev=1851430&view=auto ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RutaOptionalRuleElementTest.java (added) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RutaOptionalRuleElementTest.java Wed Jan 16 11:45:02 2019 @@ -0,0 +1,42 @@ +/* + * 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 RutaOptionalRuleElementTest { + + @Test + public void test() throws Exception { + String document = "This is a Test"; + String script = "_{-PARTOF(CW)} @W{-> T1};\n"; + script += "@W{-> T2} _{-PARTOF(CW)};\n"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "This", "a", "Test"); + RutaTestUtils.assertAnnotationsEquals(cas, 2, 3, "This", "is", "Test"); + + } + +} 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=1851430&r1=1851429&r2=1851430&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 Wed Jan 16 11:45:02 2019 @@ -19,28 +19,32 @@ package org.apache.uima.ruta.rule; +import java.io.IOException; +import java.net.URISyntaxException; + +import org.apache.uima.analysis_engine.AnalysisEngineProcessException; import org.apache.uima.cas.CAS; +import org.apache.uima.resource.ResourceConfigurationException; +import org.apache.uima.resource.ResourceInitializationException; import org.apache.uima.ruta.engine.Ruta; import org.apache.uima.ruta.engine.RutaTestUtils; +import org.apache.uima.util.InvalidXMLException; import org.junit.Test; public class SidestepInComposedTest { @Test - public void test() { + public void test() throws ResourceInitializationException, InvalidXMLException, IOException, + AnalysisEngineProcessException, ResourceConfigurationException, URISyntaxException { String document = "15. Mai 2005"; String script = "\"Mai\" -> T1;"; script += "NUM{->T2} PERIOD @T1 NUM;\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, 2, 1, "15"); - + 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=1851430&r1=1851429&r2=1851430&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 Wed Jan 16 11:45:02 2019 @@ -142,7 +142,7 @@ public class WildCard2Test { Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 2, 3, "A", "X 2 B", "B"); - Assert.assertEquals(1008, + Assert.assertEquals(192, cas.getAnnotationIndex(cas.getTypeSystem().getType(RutaTestUtils.TYPE + "3")).size()); cas.release(); } @@ -171,4 +171,58 @@ public class WildCard2Test { cas.release(); } + @Test + public void testWildCardBetweenSameTypeWithAction() throws Exception { + String document = "1 a b c 2 d e f 3"; + String script = "NUM{->T1,T1};"; + script += "T1 # t:T1{-> UNMARK(t)};\n"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "1", "1"); + } + + @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};"; + script += "# t:T1{-> T2};\n"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "1", "1"); + } + + @Test + public void testInlinedRulesAtWildcard() throws Exception { + String document = "1 a a a 1"; + String script = "NUM #{->T1}<-{PERIOD;} NUM;\n"; + script += "NUM #{->T2}<-{SW;} NUM;\n"; + + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 0); + RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "a a a"); + } + + @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"; + script += "INT a;\n"; + script += "INT t;\n"; + script += "(T1 # NUM{PARSE(a), a<100} ANY{REGEXP(\"[/]\")} NUM{PARSE(t),t<200}){ -> T2};\n"; + + CAS cas = RutaTestUtils.getCAS(document, null, null, true); + Ruta.apply(cas, script); + + RutaTestUtils.storeCas(cas, "testFailingConditionWithFailingNextRuleElement"); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "a"); + RutaTestUtils.assertAnnotationsEquals(cas, 2, 0); + } + } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/seed/DefaultSeederTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/seed/DefaultSeederTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/seed/DefaultSeederTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/seed/DefaultSeederTest.java Wed Jan 16 11:45:02 2019 @@ -40,13 +40,12 @@ import org.junit.Test; public class DefaultSeederTest { - - @Test public void test() throws Exception { URL url = RutaEngine.class.getClassLoader().getResource("BasicEngine.xml"); if (url == null) { - url = RutaTestUtils.class.getClassLoader().getResource("org/apache/uima/ruta/engine/BasicEngine.xml"); + url = RutaTestUtils.class.getClassLoader() + .getResource("org/apache/uima/ruta/engine/BasicEngine.xml"); } XMLInputSource in = new XMLInputSource(url); ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in); @@ -113,17 +112,12 @@ public class DefaultSeederTest { public void testMarkup() throws Exception { String document = "<xref ref-type=\"bibr\" rid=\"b35-ehp0113-000220\">" + "<sec sec-type=\"methods\">" + "<sec sectype=\"methods\">" - + "<sec sec-type=\"methods\">" + "<sec sectype=\"methods\">" - + "<sec sectype='methods'>" + "<tag-with-dash value=\"1\">" - + "<-not-a-real-tag value=\"1\">" + "<a_real_tag value=\"1\">"; + + "<sec sec-type=\"methods\">" + "<sec sectype=\"methods\">" + "<sec sectype='methods'>" + + "<tag-with-dash value=\"1\">" + "<-not-a-real-tag value=\"1\">" + + "<a_real_tag value=\"1\">"; String script = "RETAINTYPE(MARKUP);MARKUP{-> T1};"; - 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, 8, "<xref ref-type=\"bibr\" rid=\"b35-ehp0113-000220\">", "<sec sec-type=\"methods\">", @@ -132,7 +126,7 @@ public class DefaultSeederTest { cas.release(); } - + @Test public void testStackedMarkup() throws Exception { StringBuilder sb = new StringBuilder(); @@ -144,20 +138,11 @@ public class DefaultSeederTest { sb.append("</b>"); } - // long start = System.currentTimeMillis(); - String document = sb.toString(); String script = "RETAINTYPE(MARKUP);MARKUP{-> T1};"; - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } - // long end = System.currentTimeMillis(); + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); - // System.out.println("took: " + (end-start)/1000 + "s"); Type t1 = RutaTestUtils.getTestType(cas, 1); AnnotationIndex<AnnotationFS> ai = cas.getAnnotationIndex(t1); Assert.assertEquals(2000, ai.size()); @@ -166,4 +151,15 @@ public class DefaultSeederTest { } + @Test + public void testVerticalTab() throws Exception { + + String document = "Some \u000b text."; + String script = "RETAINTYPE(WS);\nBREAK{->T1};"; + CAS cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + + RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "\u000b"); + } + } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ActionVerbalizerTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ActionVerbalizerTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ActionVerbalizerTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ActionVerbalizerTest.java Wed Jan 16 11:45:02 2019 @@ -247,6 +247,10 @@ public class ActionVerbalizerTest { s = v.verbalize(a); assertEquals("MATCHEDTEXT(anyVar, 4, numVar)", s); + a = new MatchedTextAction(var, null); + s = v.verbalize(a); + assertEquals("MATCHEDTEXT(anyVar)", s); + // MERGE a = new MergeAction(boolExpr1, var, listExprList); s = v.verbalize(a); Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ExpressionVerbalizerTest.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ExpressionVerbalizerTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ExpressionVerbalizerTest.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ExpressionVerbalizerTest.java Wed Jan 16 11:45:02 2019 @@ -24,6 +24,7 @@ import static org.junit.Assert.assertEqu import java.util.ArrayList; import java.util.List; +import org.apache.uima.ruta.expression.MatchReference; import org.apache.uima.ruta.expression.annotation.AnnotationLabelExpression; import org.apache.uima.ruta.expression.annotation.AnnotationVariableExpression; import org.apache.uima.ruta.expression.bool.AbstractBooleanListExpression; @@ -34,6 +35,9 @@ import org.apache.uima.ruta.expression.b import org.apache.uima.ruta.expression.bool.IBooleanExpression; import org.apache.uima.ruta.expression.bool.SimpleBooleanExpression; import org.apache.uima.ruta.expression.bool.SimpleBooleanListExpression; +import org.apache.uima.ruta.expression.feature.FeatureMatchExpression; +import org.apache.uima.ruta.expression.feature.GenericFeatureExpression; +import org.apache.uima.ruta.expression.feature.SimpleFeatureExpression; import org.apache.uima.ruta.expression.number.AbstractNumberListExpression; import org.apache.uima.ruta.expression.number.ComposedNumberExpression; import org.apache.uima.ruta.expression.number.INumberExpression; @@ -219,12 +223,22 @@ public class ExpressionVerbalizerTest { assertEquals("anyVar", s); } - + @Test public void testAnnotationExpression() { RutaVerbalizer v = new RutaVerbalizer(); - assertEquals("l" , v.verbalize(new AnnotationLabelExpression("l"))); - assertEquals("l" , v.verbalize(new AnnotationVariableExpression("l"))); + assertEquals("l", v.verbalize(new AnnotationLabelExpression("l"))); + assertEquals("l", v.verbalize(new AnnotationVariableExpression("l"))); + } + + @Test + public void testGenericFeatureExpression() { + RutaVerbalizer v = new RutaVerbalizer(); + assertEquals("abc.d", v.verbalize(new GenericFeatureExpression( + new SimpleFeatureExpression(new MatchReference("abc.d"))))); + assertEquals("abc.d", v.verbalize(new GenericFeatureExpression(new FeatureMatchExpression( + new MatchReference("abc.d"), "==", new SimpleStringExpression("y"))))); + assertEquals("", v.verbalize(new GenericFeatureExpression(null))); } - + } Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTest.ruta URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTest.ruta?rev=1851430&view=auto ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTest.ruta (added) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTest.ruta Wed Jan 16 11:45:02 2019 @@ -0,0 +1,5 @@ +PACKAGE org.apache.uima.ruta.action; + +ENGINE org.apache.uima.ruta.action.ConfigureTestEngine; + +CONFIGURE(ConfigureTestEngine, "emptyIsInvisible" = false); Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTest.txt URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTest.txt?rev=1851430&view=auto ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTest.txt (added) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTest.txt Wed Jan 16 11:45:02 2019 @@ -0,0 +1 @@ +A B \ No newline at end of file Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTestEngine.xml URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTestEngine.xml?rev=1851430&view=auto ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTestEngine.xml (added) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTestEngine.xml Wed Jan 16 11:45:02 2019 @@ -0,0 +1,374 @@ +<?xml version="1.0" encoding="UTF-8"?> +<analysisEngineDescription xmlns="http://uima.apache.org/resourceSpecifier"> + <frameworkImplementation>org.apache.uima.java</frameworkImplementation> + <primitive>true</primitive> + <annotatorImplementationName>org.apache.uima.ruta.engine.RutaEngine</annotatorImplementationName> + <analysisEngineMetaData> + <name>org.apache.uima.ruta.action.ConfigureTestEngine</name> + <description/> + <version>1.0</version> + <vendor/> + <configurationParameters searchStrategy="language_fallback"> + <configurationParameter> + <name>seeders</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>debug</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>additionalScripts</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>profile</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>debugWithMatches</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>statistics</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>additionalEngines</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>additionalExtensions</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>debugOnlyFor</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>scriptEncoding</name> + <type>String</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>additionalEngineLoaders</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>resourcePaths</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>defaultFilteredTypes</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>mainScript</name> + <type>String</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>scriptPaths</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>descriptorPaths</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>removeBasics</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>dynamicAnchoring</name> + <description>Activates dynamic anchoring (possible speed up).</description> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>greedyRuleElement</name> + <description>Activates greedy anchoring for rule elements.</description> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>greedyRule</name> + <description>Activates greedy anchoring for complete rules.</description> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>lowMemoryProfile</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>createdBy</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>simpleGreedyForComposed</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>additionalUimafitEngines</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>strictImports</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>varNames</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>varValues</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>rules</name> + <type>String</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>dictRemoveWS</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>reindexOnly</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>reindexOnlyMentionedTypes</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>indexOnlyMentionedTypes</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>indexAdditionally</name> + <type>String</type> + <multiValued>true</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>emptyIsInvisible</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + <configurationParameter> + <name>modifyDataPath</name> + <type>Boolean</type> + <multiValued>false</multiValued> + <mandatory>false</mandatory> + </configurationParameter> + </configurationParameters> + <configurationParameterSettings> + <nameValuePair> + <name>debug</name> + <value> + <boolean>false</boolean> + </value> + </nameValuePair> + <nameValuePair> + <name>profile</name> + <value> + <boolean>false</boolean> + </value> + </nameValuePair> + <nameValuePair> + <name>debugWithMatches</name> + <value> + <boolean>true</boolean> + </value> + </nameValuePair> + <nameValuePair> + <name>defaultFilteredTypes</name> + <value> + <array> + <string>org.apache.uima.ruta.type.SPACE</string> + <string>org.apache.uima.ruta.type.BREAK</string> + <string>org.apache.uima.ruta.type.MARKUP</string> + </array> + </value> + </nameValuePair> + <nameValuePair> + <name>removeBasics</name> + <value> + <boolean>false</boolean> + </value> + </nameValuePair> + <nameValuePair> + <name>seeders</name> + <value> + <array> + <string>org.apache.uima.ruta.seed.DefaultSeeder</string> + </array> + </value> + </nameValuePair> + <nameValuePair> + <name>createdBy</name> + <value> + <boolean>false</boolean> + </value> + </nameValuePair> + <nameValuePair> + <name>emptyIsInvisible</name> + <value> + <boolean>true</boolean> + </value> + </nameValuePair> + <nameValuePair> + <name>mainScript</name> + <value> + <string>org.apache.uima.ruta.action.ConfigureTest</string> + </value> + </nameValuePair> + <nameValuePair> + <name>scriptPaths</name> + <value> + <array> + <string>C:/src/ws/ws-uima/RutaTest/script</string> + </array> + </value> + </nameValuePair> + <nameValuePair> + <name>descriptorPaths</name> + <value> + <array> + <string>C:/src/ws/ws-uima/RutaTest/descriptor</string> + </array> + </value> + </nameValuePair> + <nameValuePair> + <name>resourcePaths</name> + <value> + <array> + <string>C:/src/ws/ws-uima/RutaTest/resources</string> + </array> + </value> + </nameValuePair> + <nameValuePair> + <name>additionalScripts</name> + <value> + <array/> + </value> + </nameValuePair> + <nameValuePair> + <name>additionalEngines</name> + <value> + <array> + <string>org.apache.uima.ruta.action.ConfigureTestEngine</string> + </array> + </value> + </nameValuePair> + <nameValuePair> + <name>additionalUimafitEngines</name> + <value> + <array/> + </value> + </nameValuePair> + <nameValuePair> + <name>additionalExtensions</name> + <value> + <array> + <string>org.apache.uima.ruta.action.MarkReloadExtension</string> + <string>org.apache.uima.ruta.string.bool.BooleanOperationsExtension</string> + <string>org.apache.uima.ruta.string.StringOperationsExtension</string> + <string>org.apache.uima.ruta.type.TypeFromStringFunctionExtension</string> + <string>org.apache.uima.ruta.block.DocumentBlockExtension</string> + <string>org.apache.uima.ruta.block.OnlyFirstBlockExtension</string> + <string>org.apache.uima.ruta.block.OnlyOnceBlockExtension</string> + <string>org.apache.uima.ruta.block.fst.FSTBlockExtension</string> + </array> + </value> + </nameValuePair> + </configurationParameterSettings> + <typeSystemDescription> + <imports> + <import location="ConfigureTestTypeSystem.xml"/> + </imports> + </typeSystemDescription> + <typePriorities> + <priorityList> + <type>org.apache.uima.ruta.type.RutaFrame</type> + <type>uima.tcas.Annotation</type> + <type>org.apache.uima.ruta.type.RutaBasic</type> + </priorityList> + </typePriorities> + <fsIndexCollection/> + <capabilities> + <capability> + <inputs/> + <outputs/> + <languagesSupported/> + </capability> + </capabilities> + <operationalProperties> + <modifiesCas>true</modifiesCas> + <multipleDeploymentAllowed>true</multipleDeploymentAllowed> + <outputsNewCASes>true</outputsNewCASes> + </operationalProperties> + </analysisEngineMetaData> + <resourceManagerConfiguration/> +</analysisEngineDescription> Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTestTypeSystem.xml URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTestTypeSystem.xml?rev=1851430&view=auto ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTestTypeSystem.xml (added) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/action/ConfigureTestTypeSystem.xml Wed Jan 16 11:45:02 2019 @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<typeSystemDescription xmlns="http://uima.apache.org/resourceSpecifier"> + <name>org.apache.uima.ruta.action.ConfigureTestTypeSystem</name> + <imports> + <import name="org.apache.uima.ruta.engine.BasicTypeSystem"/> + </imports> +</typeSystemDescription> Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/resource/test_csvfile.csv URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/resource/test_csvfile.csv?rev=1851430&view=auto ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/resource/test_csvfile.csv (added) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/resource/test_csvfile.csv Wed Jan 16 11:45:02 2019 @@ -0,0 +1,5 @@ +this is the first line first column;ONE +this is the second line first column;TWO +this is the a line with custom; non default separator used#|#THREE +line with empty column;;AFTER_EMPTY_COLUMN +line with empty column custom separator#|##|#AFTER_EMPTY_COLUMN2 \ No newline at end of file Modified: uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.language.syntax.xml URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.language.syntax.xml?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.language.syntax.xml (original) +++ uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.language.syntax.xml Wed Jan 16 11:45:02 2019 @@ -125,10 +125,12 @@ RuleElements -> RuleElement+ RuleElement -> (Identifier ":")? "@"? RuleElementType | RuleElementLiteral | RuleElementComposed | RuleElementWildCard + | RuleElementOptional RuleElementType -> AnnotationTypeExpr OptionalRuleElementPart RuleElementWithCA -> AnnotationTypeExpr ("{" Conditions? Actions? "}")? -AnnotationTypeExpr -> (TypeExpression | AnnotationExpression) +AnnotationTypeExpr -> (TypeExpression | AnnotationExpression + TypeListExpression | AnnotationListExpression) (Operator)? Expression ("{" Conditions "}")? FeatureMatchExpression -> TypeExpression ( "." Feature)+ ( Operator (Expression | "null"))? @@ -139,14 +141,16 @@ RuleElementComposed -> "(" RuleElemen OptionalRuleElementPart OptionalRuleElementPart-> QuantifierPart? ("{" Conditions? Actions? "}")? InlinedRules? -InlinedRules -> ("<-" "{" SimpleStatement+ "}")? - ("->" "{" SimpleStatement+ "}")? +InlinedRules -> ("<-" "{" SimpleStatement+ "}")* + ("->" "{" SimpleStatement+ "}")* RuleElementWildCard -> "#"("{" Conditions? Actions? }")? InlinedRules? +RuleElementOptional -> "_"("{" Conditions? Actions? }")? InlinedRules? QuantifierPart -> "*" | "*?" | "+" | "+?" | "?" | "??" | "[" NumberExpression "," NumberExpression "]" | "[" NumberExpression "," NumberExpression "]?" Conditions -> Condition ( "," Condition )* -Actions -> "->" Action ( "," Action)* +Actions -> "->" (Identifier ":")? Action + ( "," (Identifier ":")? Action)* ]]></programlisting> Since each condition and each action has its own syntax, conditions and actions are described in their own section. For conditions see Modified: uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.language.xml URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.language.xml?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.language.xml (original) +++ uima/uv3/ruta-v3/trunk/ruta-docbook/src/docbook/tools.ruta.language.xml Wed Jan 16 11:45:02 2019 @@ -147,7 +147,7 @@ Dr.JoachimBaumeister <programlisting><![CDATA[PERIOD #{-> Sentence} PERIOD;]]></programlisting> - In this example, everything in beteen two periods is annotated with an annotation of the type + In this example, everything in between two periods is annotated with an annotation of the type <code>Sentence</code>. This rule is much more efficient than a rule like <code>PERIOD ANY+{-PARTOF(PERIOD)} PERIOD;</code> since it only navigated in the index of PERIOD annotations and does not match on all tokens. @@ -159,12 +159,12 @@ Dr.JoachimBaumeister This rule creates only annotations after a period. If the wildcard is used as an anchor of the rule, e.g., is the first rule element and no manual anchor is specified, then it starts to match at the beginning - of the doucment or current window. + of the document or current window. <programlisting><![CDATA[(# PERIOD){-> Sentence};]]></programlisting> This rule creates a Sentence annotation starting at the begin of the document ending with the first period. - If the rule lements are swicthed, the result is quite different because of the starting anchor of the rule: + If the rule elements are switched, the result is quite different because of the starting anchor of the rule: <programlisting><![CDATA[(PERIOD #){-> Sentence};]]></programlisting> @@ -175,6 +175,21 @@ Dr.JoachimBaumeister </para> </section> + <section id="ugr.tools.ruta.language.optional"> + <title>Optional match _</title> + <para> + The optional match <code>_</code> is a special matching condition of a rule element, + which does not require any annotations or a textual span in general to match. + The functionality of the optional match is illustrated with following examples: + + <programlisting><![CDATA[PERIOD{-> SentenceEnd} _{-PARTOF(CW)};]]></programlisting> + + In this example, an annotation of the type <code>SentenceEnd</code> is created for each <code>PERIOD</code> annotation, + if it is followed by something that is not part of a <code>CW</code>. This is also fulfilled for the last <code>PERIOD</code> annotation + in a document that ends with a period. + </para> + </section> + <section id="ugr.tools.ruta.language.labels"> <title>Label expressions</title> <para> @@ -182,13 +197,13 @@ Dr.JoachimBaumeister multiple annotations - the annotations matched by the matching condition of the rule element. The name of the variable is the short identifier before the colon in front of the matching condition, e.g., in <code>sw:SW</code>, <code>SW</code> is the matching condition and <code>sw</code> is the name of the local variable. - The variable will be assigned when the rule element tries to match (also when it fails afterall) - and can be utilzed in all other language elements afterwards. + The variable will be assigned when the rule element tries to match (also when it fails after all) + and can be utilized in all other language elements afterwards. The functionality of the label expressions is illustrated with following examples: <programlisting><![CDATA[sw1:SW sw2:SW{sw1.end=sw2.begin};]]></programlisting> - This rule matches on two consecutive small-written words, but matches only if there is no space inbetween them. + This rule matches on two consecutive small-written words, but matches only if there is no space in between them. Label expression can also be used across <xref linkend='ugr.tools.ruta.language.inlined' />. </para> @@ -501,7 +516,8 @@ Document{->CALL(MyScript.countNumberOfTy <quote><-</quote> , then the inlined rules are interpreted as some sort of condition. The surrounding rules will - only match, if one of the inlined rules was successfully applied. + only match, if one of the inlined rules was successfully applied. + A rule element may be extended with several inlined rule blocks of the same type. The functionality introduced by inlined rules is illustrated with a few examples: </para> 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=1851430&r1=1851429&r2=1851430&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 Wed Jan 16 11:45:02 2019 @@ -708,6 +708,14 @@ Document{-> EXEC(MyAnalysisEngine, {MyTy </row> <row> <entry> + <link linkend='ugr.tools.ruta.ae.basic.parameter.rules'>rulesScriptName</link> + </entry> + <entry>This parameter specifies the name of the non-existing script if the parameter 'rules' is used. + </entry> + <entry>Single String</entry> + </row> + <row> + <entry> <link linkend='ugr.tools.ruta.ae.basic.parameter.scriptEncoding'>scriptEncoding</link> </entry> <entry>Encoding of all UIMA Ruta script files.</entry> @@ -956,6 +964,39 @@ Document{-> EXEC(MyAnalysisEngine, {MyTy </entry> <entry>Single Boolean</entry> </row> + <row> + <entry> + <link linkend='ugr.tools.ruta.ae.basic.parameter.csvSeparator'>csvSeparator</link> + </entry> + <entry>String/token to be used to split columns in CSV tables. + </entry> + <entry>Single String</entry> + </row> + <row> + <entry> + <link linkend='ugr.tools.ruta.ae.basic.parameter.inferenceVisitors'>inferenceVisitors</link> + </entry> + <entry>List of factory classes for additional inference visitors. + </entry> + <entry>Multi String</entry> + </row> + <row> + <entry> + <link linkend='ugr.tools.ruta.ae.basic.parameter.maxRuleMatches'>maxRuleMatches</link> + </entry> + <entry>Maximum amount of allowed matches of a single rule. + </entry> + <entry>Single Integer</entry> + </row> + <row> + <entry> + <link linkend='ugr.tools.ruta.ae.basic.parameter.maxRuleMatches'>maxRuleElementMatches</link> + </entry> + <entry>Maximum amount of allowed matches of a single rule element. + </entry> + <entry>Single Integer</entry> + </row> + </tbody> </tgroup> </table> @@ -979,6 +1020,14 @@ Document{-> EXEC(MyAnalysisEngine, {MyTy If set, it replaces the content of file specified by the <link linkend='ugr.tools.ruta.ae.basic.parameter.mainScript'>mainScript</link> parameter. </para> </section> + <section id="ugr.tools.ruta.ae.basic.parameter.rulesScriptName"> + <title>rulesScriptName</title> + <para> + This parameter specifies the name of the non-existing script if the <link linkend='ugr.tools.ruta.ae.basic.parameter.rules'>rules</link> parameter is used. + The default value is 'Anonymous'. + </para> + </section> + <section id="ugr.tools.ruta.ae.basic.parameter.scriptEncoding"> <title>scriptEncoding</title> <para> @@ -1080,7 +1129,7 @@ Document{-> EXEC(MyAnalysisEngine, {MyTy <title>removeBasics</title> <para> This parameter specifies whether the inference annotations created by the analysis engine should be removed after processing the CAS. - The default value is set to true. + The default value is set to false. </para> </section> <section id="ugr.tools.ruta.ae.basic.parameter.reindexOnly"> @@ -1235,6 +1284,33 @@ Document{-> EXEC(MyAnalysisEngine, {MyTy If this parameter is set to true, then whitespaces are removed when dictionaries are loaded. </para> </section> + <section id="ugr.tools.ruta.ae.basic.parameter.csvSeparator"> + <title>csvSeparator</title> + <para> + If this parameter is set to any String value then this String/token is used to split columns in CSV tables. + The default is set to ';'. + </para> + </section> + <section id="ugr.tools.ruta.ae.basic.parameter.inferenceVisitors"> + <title>inferenceVisitors</title> + <para> + This parameter specifies optional class names implementing the interface + <code>org.apache.uima.ruta.visitor.RutaInferenceVisitor</code>, which will be notified during + applying the rules. + </para> + </section> + <section id="ugr.tools.ruta.ae.basic.parameter.maxRuleMatches"> + <title>maxRuleMatches</title> + <para> + Maximum amount of allowed matches of a single rule. + </para> + </section> + <section id="ugr.tools.ruta.ae.basic.parameter.maxRuleElementMatches"> + <title>maxRuleElementMatches</title> + <para> + Maximum amount of allowed matches of a single rule element. + </para> + </section> </section> </section> <section id="ugr.tools.ruta.ae.annotationwriter"> 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=1851430&r1=1851429&r2=1851430&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 Wed Jan 16 11:45:02 2019 @@ -23,13 +23,13 @@ <parent> <groupId>org.apache.uima</groupId> <artifactId>parent-pom</artifactId> - <version>10</version> + <version>12</version> <relativePath /> </parent> <artifactId>ruta-eclipse-update-site</artifactId> <packaging>pom</packaging> - <version>2.6.1</version> + <version>3.0.0</version> <name>Apache UIMA Ruta Eclipse: ${project.artifactId}</name> <description>The UIMA Ruta Eclipse update site</description> @@ -51,8 +51,8 @@ <uimaScmProject>${project.artifactId}</uimaScmProject> <eclipseUpdateSiteComponent>ruta</eclipseUpdateSiteComponent> <eclipseUpdateSubSite>${project.build.directory}/eclipse-update-site/${eclipseUpdateSiteComponent}</eclipseUpdateSubSite> - <item-maven-release-version>2.6.1</item-maven-release-version> - <item-eclipse-release-version>2.6.1</item-eclipse-release-version> + <item-maven-release-version>3.0.0</item-maven-release-version> + <item-eclipse-release-version>3.0.0</item-eclipse-release-version> </properties> <build> <pluginManagement> @@ -115,24 +115,196 @@ </executions> </plugin> <plugin> - <!-- Override v 6 parent pom incorrect use of apacheRelease ant property - See https://issues.apache.org/jira/browse/UIMA-3080 --> <artifactId>maven-antrun-plugin</artifactId> - <executions> + <executions> + + <!-- ==================================================== --> + <!-- --> + <!-- P O S T JAR S I G N I N G by Digicert --> + <!-- --> + <!-- is not here, it was --> + <!-- moved to uima-wide parent pom 10/2018 --> + <!-- ==================================================== --> + <execution> <id>BuildUpdateSite-pack-svnget-buildMetadata-commit-to-dev</id> - <configuration> + <phase>package</phase> + <goals> + <goal>run</goal> + </goals> + <configuration combine.self="override"> <target> - <condition /> <!-- don't add anything to the 1st condition element --> - <condition /> <!-- don't add anything to the 2nd condition element --> - <!-- insert this as the 3rd condition element --> - <condition property="apacheRelease"> - <equals arg1="${isApacheRelease}" arg2="true" /> + <taskdef classname="net.sf.antcontrib.logic.IfTask" name="if" /> + + <condition property="eclipse.home" value="${uima-maven-build-eclipse-home}"> + <not> + <equals arg1="${uima-maven-build-eclipse-home}" arg2="$${uima-maven-build-eclipse-home}" /> + </not> + </condition> + + <property environment="envVar" /> + <condition property="eclipse.home" value="${envVar.ECLIPSE_HOME}"> + <isset property="envVar.ECLIPSE_HOME" /> </condition> + + <fail unless="eclipse.home" message="********** Please set up and use an ant property eclipse.home set to an Eclipse installation at level 3.3 or later, e.g. c:/eclipses/3.3/eclipse" /> + <fail unless="uima-eclipse-jar-processor" message="********** Please add to your settings.xml file the property uima-eclipse-jar-processor, point to this within an Eclipse installation at level 4.2 or later, e.g. \$\{uima-maven-build-eclipse-home\}/plugins/org.eclipse.equinox.p2.jarprocessor_1.0.200.v20110808-1657.jar" /> + <!-- skip this when dropping previous versions --> + <if> + <equals arg1="${dropPrevVersions}" arg2="false" /> + <then> + <if> + <equals arg1="${isApacheRelease}" arg2="true" /> + <then> + + <echo>checking out eclipse update subsite ${eclipseUpdateSiteComponent} from dist ...release...</echo> + <delete dir="${eclipseUpdateSubSite}" quiet="true" /> + <exec executable="svn" failonerror="true"> + <arg value="checkout" /> + <arg value="${distsvnroot}repos/dist/release/uima/eclipse-update-site/${eclipseUpdateSiteComponent}" /> + <arg value="${eclipseUpdateSubSite}" /> + </exec> + + <!-- abandon safety for now + <echo>switching this checkout to ...dev... for safety</echo> + <exec executable="svn"> + <arg value="switch" /> + <arg value="- -force" /> remove space between 2 dashes if uncommented + <arg value="- -accept" /> remove space between 2 dashes if uncommented + <arg value="mine-full" /> + <arg value="${distsvnroot}repos/dist/dev/uima/eclipse-update-site/${eclipseUpdateSiteComponent}" /> + <arg value="${eclipseUpdateSubSite}" /> + </exec> + --> + </then> + <else> + <echo>skipping checkout of current svn dist release (because not apache-release)</echo> + <!-- https://issues.apache.org/jira/browse/UIMA-3501 --> + <delete dir="${eclipseUpdateSubSite}" quiet="true" /> + </else> + </if> + </then> + </if> + + <echo>Compress plugin Jars using pack200 - this may take a minute or 2</echo> + <java fork="true" maxmemory="256m" jar="${uima-eclipse-jar-processor}" failonerror="true"> + <arg line="-processAll" /> + <arg line="-repack" /> + <arg line="-pack" /> + <arg line="-verbose" /> + <arg line="-outputDir ${eusWork}/plugins" /> + <arg line="${toBePacked}" /> + </java> + + <echo>Save conditioned Jars prior to signing, in case of redo</echo> + <echo>-------------------------------------------------------</echo> + <copy todir="${project.build.directory}/saved/features" failonerror="true"> + <fileset dir="${eusWork}/features" includes="*.jar" /> + </copy> + <copy todir="${project.build.directory}/saved/plugins" failonerror="true"> + <fileset dir="${eusWork}/plugins" includes="*.jar" /> + </copy> + + <echo>Generate the p2 metadata and publish new artifacts</echo> + <java fork="true" maxmemory="256m" jar="${eclipse-equinox-launcher}" failonerror="true"> + <arg line="-application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher" /> + <arg line="-metadataRepository file:///${eclipseUpdateSubSite}" /> + <arg line="-artifactRepository file:///${eclipseUpdateSubSite}" /> + <arg line="-source ${eusWork}" /> + <arg line="-configs ANY.ANY.ANY" /> + <arg line="-publishArtifacts" /> + <arg line="-reusePack200Files" /> + <arg line="-compress" /> + <arg line="-append" /> + </java> + <echo>Augment p2 metadata with category information</echo> + <java fork="true" maxmemory="256m" jar="${eclipse-equinox-launcher}" failonerror="true"> + <arg line="-application org.eclipse.equinox.p2.publisher.CategoryPublisher" /> + <arg line="-metadataRepository file:///${eclipseUpdateSubSite}" /> + <arg line="-categoryDefinition file:///${basedir}/category.xml" /> + <arg line="-categoryQualifier apache-uima" /> + <arg line="-compress" /> + </java> + <if> + <equals arg2="true" arg1="${isApacheRelease}" /> + <then> + <echo message="Generating checksums for new features and plugins" /> + <checksum algorithm="SHA-512" fileext=".sha512" format="MD5SUM" forceoverwrite="yes"> + <fileset dir="${eusWork}"> + <include name="**/*.gz" /> + <include name="**/*.jar" /> + </fileset> + </checksum> + + <echo message="Generating gpg signatures for new features and plugins" /> + <apply failonerror="true" dir="${eusWork}" executable="gpg"> + <arg value="--detach-sign" /> + <arg value="--armor" /> + <arg value="--batch" /> + <fileset dir="${eusWork}"> + <include name="**/*.jar" /> + <include name="**/*.jar.pack.gz" /> + </fileset> + </apply> + <echo message="Copying the checksums and signatures to the update subsite" /> + <copy todir="${eclipseUpdateSubSite}" failonerror="true"> + <fileset dir="${eusWork}"> + <include name="**/*.asc" /> + <include name="**/*.sha512" /> + </fileset> + </copy> + <echo message="Clearing previous checksums and signatures for update artifacts.jar and content.jar" /> + <delete dir="${eclipseUpdateSubSite}"> + <include name="*.sha512" /> + <include name="*.asc" /> + </delete> + <echo message="Generating checksums for updated artifacts.jar and content.jar" /> + <checksum algorithm="SHA-512" fileext=".sha512" format="MD5SUM" forceoverwrite="yes"> + <fileset dir="${eclipseUpdateSubSite}"> + <include name="*.jar" /> + </fileset> + </checksum> + <echo message="Generating gpg signatures for artifacts.jar and content.jar" /> + <apply failonerror="true" dir="${eclipseUpdateSubSite}" executable="gpg"> + <arg value="--detach-sign" /> + <arg value="--armor" /> + <arg value="--batch" /> + <fileset dir="${eclipseUpdateSubSite}"> + <include name="*.jar" /> + </fileset> + </apply> + </then> + </if> </target> </configuration> </execution> </executions> + <dependencies> + <dependency> + <groupId>ant-contrib</groupId> + <artifactId>ant-contrib</artifactId> + <version>1.0b3</version> + <scope>runtime</scope> + <exclusions> + <exclusion> + <artifactId>ant</artifactId> + <groupId>ant</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.ant</groupId> + <artifactId>ant-apache-regexp</artifactId> + <version>1.9.2</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>jakarta-regexp</groupId> + <artifactId>jakarta-regexp</artifactId> + <version>1.4</version> + <scope>compile</scope> + </dependency> + </dependencies> </plugin> </plugins> </build> 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=1851430&r1=1851429&r2=1851430&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 Wed Jan 16 11:45:02 2019 @@ -47,6 +47,9 @@ 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(); Modified: uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/XMLUtils.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/XMLUtils.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/XMLUtils.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/check/XMLUtils.java Wed Jan 16 11:45:02 2019 @@ -51,6 +51,9 @@ public class XMLUtils { return new ArrayList<CheckDocument>(); } 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(file); InputSource inputSource = new InputSource(reader); CheckDocumentsContentHandler handler = new CheckDocumentsContentHandler(); 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=1851430&r1=1851429&r2=1851430&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 Wed Jan 16 11:45:02 2019 @@ -69,8 +69,10 @@ public class ExplainConstants { public static final String RULE_ANCHOR = "ruleAnchor"; public static final String TIME = "time"; - + + public static final String TIME_STAMP = "timestamp"; + public static final String ID = "id"; - + public static final String SCRIPT = "script"; } Modified: uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/tree/ExplainTree.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/tree/ExplainTree.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/tree/ExplainTree.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/tree/ExplainTree.java Wed Jan 16 11:45:02 2019 @@ -20,16 +20,18 @@ package org.apache.uima.ruta.explain.tree; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import org.apache.uima.cas.ArrayFS; 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.TypeSystem; import org.apache.uima.cas.text.AnnotationFS; +import org.apache.uima.fit.util.CasUtil; import org.apache.uima.ruta.explain.ExplainConstants; public class ExplainTree { @@ -73,7 +75,7 @@ public class ExplainTree { private void createTree(CAS cas, int offset, boolean onlyRules) { TypeSystem ts = cas.getTypeSystem(); - Type scriptApply = ts.getType(ExplainConstants.SCRIPT_APPLY_TYPE); + Type scriptApplyType = ts.getType(ExplainConstants.SCRIPT_APPLY_TYPE); blockApplyType = ts.getType(ExplainConstants.BLOCK_APPLY_TYPE); ruleApplyType = ts.getType(ExplainConstants.RULE_APPLY_TYPE); @@ -84,20 +86,32 @@ public class ExplainTree { ruleElementMatchesType = ts.getType(ExplainConstants.RULE_ELEMENT_MATCHES_TYPE); evaluatedConditionType = ts.getType(ExplainConstants.EVAL_CONDITION_TYPE); - if (scriptApply == null) + if (scriptApplyType == null) { return; - FSIterator<AnnotationFS> it = cas.getAnnotationIndex(scriptApply).iterator(); - root = new ApplyRootNode(null, ts); + } - if (it.isValid()) { - it.moveToFirst(); - while (it.isValid()) { - AnnotationFS fs = it.get(); - buildTree(fs, root, ts, offset, onlyRules); - it.moveToNext(); + List<AnnotationFS> scriptApplies = new ArrayList<>(CasUtil.select(cas, scriptApplyType)); + // sort by creation time + Collections.sort(scriptApplies, new Comparator<AnnotationFS>() { + + @Override + public int compare(AnnotationFS o1, AnnotationFS o2) { + Feature feature = o1.getType().getFeatureByBaseName(ExplainConstants.TIME_STAMP); + if (feature == null || !o1.getType().equals(o2.getType())) { + return o1.getType().getName().compareTo(o2.getType().getName()); + } + long l1 = o1.getLongValue(feature); + long l2 = o2.getLongValue(feature); + return Long.compare(l1, l2); } - } + }); + + root = new ApplyRootNode(null, ts); + for (AnnotationFS scriptApply : scriptApplies) { + + buildTree(scriptApply, root, ts, offset, onlyRules); + } } private void buildTree(FeatureStructure fs, IExplainTreeNode parent, TypeSystem ts, int offset, @@ -185,8 +199,8 @@ public class ExplainTree { } } - private void processRuleApply(AnnotationFS fs, IExplainTreeNode parent, TypeSystem ts, - int offset, boolean onlyRules) { + private void processRuleApply(AnnotationFS fs, IExplainTreeNode parent, TypeSystem ts, int offset, + boolean onlyRules) { if (offset >= 0 && (fs.getBegin() >= offset || fs.getEnd() <= offset)) { return; } @@ -225,8 +239,8 @@ public class ExplainTree { } } - private void processRuleMatch(AnnotationFS fs, IExplainTreeNode parent, TypeSystem ts, - int offset, boolean onlyRules) { + private void processRuleMatch(AnnotationFS fs, IExplainTreeNode parent, TypeSystem ts, int offset, + boolean onlyRules) { if (offset >= 0 && (fs.getBegin() >= offset || fs.getEnd() <= offset)) { return; } @@ -305,7 +319,7 @@ public class ExplainTree { } private void prune(IExplainTreeNode node) { - if(node == null) { + if (node == null) { return; } List<IExplainTreeNode> children = node.getChildren();