You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2019/01/16 11:45:04 UTC
svn commit: r1851430 [7/9] - in /uima/uv3/ruta-v3/trunk:
ruta-basic-type/src/main/java/org/apache/uima/ruta/type/
ruta-core-ext/src/main/java/org/apache/uima/ruta/action/
ruta-core-ext/src/main/java/org/apache/uima/ruta/string/bool/
ruta-core-ext/src/t...
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=1851430&r1=1851429&r2=1851430&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 Wed Jan 16 11:45:02 2019
@@ -22,11 +22,14 @@ package org.apache.uima.ruta.action;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.IOException;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.FSIterator;
import org.apache.uima.cas.Feature;
@@ -34,16 +37,21 @@ import org.apache.uima.cas.FeatureStruct
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.cas.text.AnnotationIndex;
+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.RutaEngine;
import org.apache.uima.ruta.engine.RutaTestUtils;
import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature;
+import org.apache.uima.util.InvalidXMLException;
import org.junit.Test;
public class CreateTest {
@Test
- public void test() {
+ public void test() throws AnalysisEngineProcessException, InvalidXMLException,
+ ResourceInitializationException, ResourceConfigurationException, URISyntaxException,
+ IOException {
String name = this.getClass().getSimpleName();
String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
@@ -61,15 +69,9 @@ public class CreateTest {
String fn3 = "count";
list.add(new TestFeature(fn3, "", "uima.cas.Integer"));
- 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;
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/ImplicitActionTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/ImplicitActionTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/ImplicitActionTest.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/ImplicitActionTest.java Wed Jan 16 11:45:02 2019
@@ -42,10 +42,12 @@ import org.junit.Test;
public class ImplicitActionTest {
@Test
- public void test() {
+ public void test() throws AnalysisEngineProcessException, InvalidXMLException,
+ ResourceInitializationException, ResourceConfigurationException, URISyntaxException,
+ IOException {
String name = this.getClass().getSimpleName();
String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
- CAS cas = null;
+
Map<String, String> complexTypes = new HashMap<String, String>();
Map<String, List<TestFeature>> features = new TreeMap<String, List<TestFeature>>();
String typeNameA = "org.apache.uima.ruta.FeatureMatchTest.A";
@@ -77,25 +79,23 @@ public class ImplicitActionTest {
String fnds = "ds";
listD.add(new TestFeature(fnds, "", "uima.cas.String"));
- try {
- cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION,
- FeatureMatch1Test.class.getName().replaceAll("\\.", "/") +".txt", 50, false, false, complexTypes, features, null);
- } catch (Exception e) {
- e.printStackTrace();
- assert (false);
- }
-
- RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "Peter Kluegl", "Joern Kottmann", "Marshall Schor");
+ CAS cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION,
+ FeatureMatch1Test.class.getName().replaceAll("\\.", "/") + ".txt", 50, false, false,
+ complexTypes, features, null);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "Peter Kluegl", "Joern Kottmann",
+ "Marshall Schor");
RutaTestUtils.assertAnnotationsEquals(cas, 2, 3, "Peter", "Joern", "Marshall");
RutaTestUtils.assertAnnotationsEquals(cas, 3, 3, "Peter", "Joern", "Marshall");
RutaTestUtils.assertAnnotationsEquals(cas, 4, 3, "Peter", "Joern", "Marshall");
-
+
cas.release();
}
-
-
+
@Test
- public void testChangeOffsets() throws ResourceInitializationException, InvalidXMLException, IOException, AnalysisEngineProcessException, ResourceConfigurationException, URISyntaxException {
+ public void testChangeOffsets()
+ throws ResourceInitializationException, InvalidXMLException, IOException,
+ AnalysisEngineProcessException, ResourceConfigurationException, URISyntaxException {
String text = "text 2 3 x 4 1";
String script = "";
script += "NUM{->T1};";
@@ -106,7 +106,5 @@ public class ImplicitActionTest {
RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "4 1");
cas.release();
}
-
-
-
+
}
Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/LabelAtActionTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/LabelAtActionTest.java?rev=1851430&view=auto
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/LabelAtActionTest.java (added)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/LabelAtActionTest.java Wed Jan 16 11:45:02 2019
@@ -0,0 +1,57 @@
+/*
+ * 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.action;
+
+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 LabelAtActionTest {
+
+ @Test
+ public void test() throws ResourceInitializationException, InvalidXMLException, IOException,
+ AnalysisEngineProcessException, ResourceConfigurationException, URISyntaxException {
+
+ String document = "This is a test.";
+ String script = "CW{-> t:T1}->{t{->T2};};";
+ script += "SW.ct == \"is\"{-> t:MARK(T3)}->{t{->T4};};";
+ script += "SW.ct == \"a\"{-> t:CREATE(T5)}->{t{->T6};};";
+ script += "SW.ct == \"test\"{-> t:GATHER(T7)}->{t{->T8};};";
+ script += "Document{-> t:MARKFIRST(T9)}->{t{->T10};};";
+ script += "Document{-> t:MARKLAST(T11)}->{t{->T12};};";
+
+ CAS cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "This");
+ RutaTestUtils.assertAnnotationsEquals(cas, 4, 1, "is");
+ RutaTestUtils.assertAnnotationsEquals(cas, 6, 1, "a");
+ RutaTestUtils.assertAnnotationsEquals(cas, 8, 1, "test");
+
+ }
+
+}
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/SplitTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/SplitTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/SplitTest.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/SplitTest.java Wed Jan 16 11:45:02 2019
@@ -341,8 +341,8 @@ public class SplitTest {
@Test
public void testBoundary() throws Exception {
String document = "Some text. More text , with 1 , and more. even more text.";
- String script = "PERIOD #{-> T1} PERIOD;";
- script += "#{-> T1} PERIOD;";
+ String script = "PERIOD (# PERIOD){-> T1};";
+ script += "(# PERIOD){-> T1};";
script += "T1{-> SPLIT(PERIOD, true, false, true)};";
CAS cas = RutaTestUtils.getCAS(document);
@@ -366,9 +366,7 @@ public class SplitTest {
next = iterator.next();
assertEquals("even more text.", next.getCoveredText());
- if (cas != null) {
- cas.release();
- }
+ cas.release();
}
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContainsTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContainsTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContainsTest.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContainsTest.java Wed Jan 16 11:45:02 2019
@@ -72,5 +72,23 @@ public class ContainsTest {
}
+ @Test
+ public void testContainsOverlappingAnnotations() throws ResourceInitializationException,
+ InvalidXMLException, IOException, AnalysisEngineProcessException,
+ ResourceConfigurationException, URISyntaxException {
+ String document = "1 2 3 4 5 6 7 8";
+
+ String script = "(\"1\" # \"5\") {-> T1};";
+ script += "(\"3\" # \"8\") {-> T1};";
+ script += "(\"3\" # \"4\") {-> T1};";
+ script += "(\"3\" # \"5\") {-> T2};";
+ script += "T2{CONTAINS(T1,1,1)-> T3};";
+
+ CAS cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 3, 1);
+
+ }
}
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/CountTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/CountTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/CountTest.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/CountTest.java Wed Jan 16 11:45:02 2019
@@ -19,8 +19,16 @@
package org.apache.uima.ruta.condition;
+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 CountTest {
@@ -37,4 +45,18 @@ public class CountTest {
cas.release();
}
+
+ @Test
+ public void testCountWithPeriodPostfix() throws ResourceInitializationException, InvalidXMLException,
+ IOException, AnalysisEngineProcessException, ResourceConfigurationException, URISyntaxException {
+
+ String document = "Some text.";
+ String script = "(CW SW) {-> T1};";
+ script +="INT i = 0;";
+ script +="T1{COUNT(PERIOD, i)};";
+ script +="Document{(i>0)-> T2};";
+ CAS cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 0);
+ }
}
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/FeatureTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/FeatureTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/FeatureTest.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/FeatureTest.java Wed Jan 16 11:45:02 2019
@@ -19,28 +19,36 @@
package org.apache.uima.ruta.condition;
+import java.io.IOException;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+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.RutaEngine;
import org.apache.uima.ruta.engine.RutaTestUtils;
import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature;
+import org.apache.uima.util.InvalidXMLException;
import org.junit.Test;
public class FeatureTest {
@Test
- public void test() {
+ public void test() throws AnalysisEngineProcessException, InvalidXMLException,
+ ResourceInitializationException, ResourceConfigurationException, URISyntaxException,
+ IOException {
String name = this.getClass().getSimpleName();
String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
-
+
Map<String, String> complexTypes = new TreeMap<String, String>();
String typeName = "org.apache.uima.FS";
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);
@@ -52,15 +60,10 @@ public class FeatureTest {
list.add(new TestFeature(fn3, "", "uima.cas.Integer"));
String fn4 = "boolean";
list.add(new TestFeature(fn4, "", "uima.cas.Boolean"));
-
- 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 + "/");
RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Testing FEATURE condition.");
RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "Testing FEATURE condition.");
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition1Test.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition1Test.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition1Test.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition1Test.java Wed Jan 16 11:45:02 2019
@@ -19,26 +19,34 @@
package org.apache.uima.ruta.condition;
+import java.io.IOException;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+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.FeatureMatch1Test;
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.util.InvalidXMLException;
import org.junit.Test;
public class ImplicitCondition1Test {
@Test
- public void test() {
+ public void test() throws AnalysisEngineProcessException, InvalidXMLException,
+ ResourceInitializationException, ResourceConfigurationException, URISyntaxException,
+ IOException {
String name = this.getClass().getSimpleName();
String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
- CAS cas = null;
+
Map<String, String> complexTypes = new HashMap<String, String>();
Map<String, List<TestFeature>> features = new TreeMap<String, List<TestFeature>>();
String typeNameA = "org.apache.uima.ruta.FeatureMatchTest.A";
@@ -70,19 +78,18 @@ public class ImplicitCondition1Test {
String fnds = "ds";
listD.add(new TestFeature(fnds, "", "uima.cas.String"));
- try {
- cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION,
- FeatureMatch1Test.class.getName().replaceAll("\\.", "/") +".txt", 50, false, false, complexTypes, features, null);
- } catch (Exception e) {
- e.printStackTrace();
- assert (false);
- }
+ CAS cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION,
+ FeatureMatch1Test.class.getName().replaceAll("\\.", "/") + ".txt", 50, false, false,
+ complexTypes, features, null);
RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Marshall Schor");
- RutaTestUtils.assertAnnotationsEquals(cas, 2, 3, "Peter Kluegl", "Joern Kottmann", "Marshall Schor");
- RutaTestUtils.assertAnnotationsEquals(cas, 3, 3, "Peter Kluegl", "Joern Kottmann", "Marshall Schor");
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 3, "Peter Kluegl", "Joern Kottmann",
+ "Marshall Schor");
+ RutaTestUtils.assertAnnotationsEquals(cas, 3, 3, "Peter Kluegl", "Joern Kottmann",
+ "Marshall Schor");
RutaTestUtils.assertAnnotationsEquals(cas, 4, 1, "Joern Kottmann");
- RutaTestUtils.assertAnnotationsEquals(cas, 5, 3, "Peter Kluegl", "Joern Kottmann", "Marshall Schor");
+ RutaTestUtils.assertAnnotationsEquals(cas, 5, 3, "Peter Kluegl", "Joern Kottmann",
+ "Marshall Schor");
cas.release();
}
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition2Test.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition2Test.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition2Test.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ImplicitCondition2Test.java Wed Jan 16 11:45:02 2019
@@ -54,15 +54,17 @@ public class ImplicitCondition2Test {
RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "Peter", "Kluegl", "Joern");
RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "Peter", "Kluegl");
RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "Peter");
- RutaTestUtils.assertAnnotationsEquals(cas, 4, 5, "Kluegl", "Joern", "Kottmann", "Marshall", "Schor");
+ RutaTestUtils.assertAnnotationsEquals(cas, 4, 5, "Kluegl", "Joern", "Kottmann", "Marshall",
+ "Schor");
RutaTestUtils.assertAnnotationsEquals(cas, 5, 3, "Kottmann", "Marshall", "Schor");
RutaTestUtils.assertAnnotationsEquals(cas, 6, 2, "Marshall", "Schor");
cas.release();
}
-
+
@Test
- public void testStringCompare() throws ResourceInitializationException, InvalidXMLException, IOException, AnalysisEngineProcessException, CASException {
+ public void testStringCompare() throws ResourceInitializationException, InvalidXMLException,
+ IOException, AnalysisEngineProcessException, CASException {
String document = "a b. a b.";
CAS cas = RutaTestUtils.getCAS(document);
Assert.assertTrue(Ruta.matches(cas.getJCas(), "(w:W # W{W.ct==w.ct}){->T1};"));
@@ -70,21 +72,21 @@ public class ImplicitCondition2Test {
RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "a b. a", "b. a b");
RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "a b", "a b");
}
-
+
@Test
- public void testStringCompareNull() throws ResourceInitializationException, InvalidXMLException, IOException, AnalysisEngineProcessException, CASException {
+ public void testStringCompareNull() throws ResourceInitializationException, InvalidXMLException,
+ IOException, AnalysisEngineProcessException, CASException {
String document = "a b. a b.";
CAS cas = RutaTestUtils.getCAS(document);
-
+
String rules = "STRING s2;\n";
rules += "Document{s2 == \"\" -> T10};\n";
rules += "Document{s2 == null -> T11};\n";
Assert.assertTrue(Ruta.matches(cas.getJCas(), rules));
-
- RutaTestUtils.assertAnnotationsEquals(cas, 10, 1, document);
- RutaTestUtils.assertAnnotationsEquals(cas, 11, 0);
-
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 10, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 11, 1, document);
+
}
-
-
+
}
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=1851430&r1=1851429&r2=1851430&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 Wed Jan 16 11:45:02 2019
@@ -19,10 +19,6 @@
package org.apache.uima.ruta.descriptor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
@@ -47,10 +43,10 @@ import org.apache.uima.resource.metadata
import org.apache.uima.ruta.engine.HtmlAnnotator;
import org.apache.uima.ruta.engine.RutaEngine;
import org.apache.uima.util.InvalidXMLException;
+import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-
public class GenerateDescriptorTest {
private static URL basicAEUrl;
@@ -59,29 +55,34 @@ public class GenerateDescriptorTest {
@BeforeClass
public static void setUpClass() {
- basicAEUrl = GenerateDescriptorTest.class.getClassLoader().getResource("BasicEngine.xml");
- if (basicAEUrl == null) {
- basicAEUrl = HtmlAnnotator.class.getClassLoader().getResource(
- "org/apache/uima/ruta/engine/BasicEngine.xml");
+
+ GenerateDescriptorTest.basicAEUrl = GenerateDescriptorTest.class.getClassLoader()
+ .getResource("BasicEngine.xml");
+ if (GenerateDescriptorTest.basicAEUrl == null) {
+ GenerateDescriptorTest.basicAEUrl = HtmlAnnotator.class.getClassLoader()
+ .getResource("org/apache/uima/ruta/engine/BasicEngine.xml");
}
- basicTSUrl = GenerateDescriptorTest.class.getClassLoader().getResource("BasicTypeSystem.xml");
- if (basicTSUrl == null) {
- basicTSUrl = HtmlAnnotator.class.getClassLoader().getResource(
- "org/apache/uima/ruta/engine/BasicTypeSystem.xml");
+ GenerateDescriptorTest.basicTSUrl = GenerateDescriptorTest.class.getClassLoader()
+ .getResource("BasicTypeSystem.xml");
+ if (GenerateDescriptorTest.basicTSUrl == null) {
+ GenerateDescriptorTest.basicTSUrl = HtmlAnnotator.class.getClassLoader()
+ .getResource("org/apache/uima/ruta/engine/BasicTypeSystem.xml");
}
}
@Test
- public void testCreateAnalysisEngineDescription() throws InvalidXMLException, IOException,
- RecognitionException, URISyntaxException {
+ public void testCreateAnalysisEngineDescription()
+ throws InvalidXMLException, IOException, RecognitionException, URISyntaxException {
+
String script = "";
script += "PACKAGE test.package;\n";
script += "ENGINE org.apache.uima.ruta.engine.HtmlAnnotator;\n";
script += "UIMAFIT org.apache.uima.ruta.engine.PlainTextAnnotator;\n";
script += "SCRIPT org.apache.uiima.ruta.Additional;\n";
- RutaDescriptorFactory rdf = new RutaDescriptorFactory(basicTSUrl, basicAEUrl);
+ RutaDescriptorFactory rdf = new RutaDescriptorFactory(GenerateDescriptorTest.basicTSUrl,
+ GenerateDescriptorTest.basicAEUrl);
RutaDescriptorInformation descriptorInformation = rdf.parseDescriptorInformation(script);
RutaBuildOptions options = new RutaBuildOptions();
String typeSystemOutput = "target/temp/testCreateAnalysisEngineDescription_TypeSystem.xml";
@@ -94,26 +95,31 @@ public class GenerateDescriptorTest {
String mainScript = (String) cps.getParameterValue(RutaEngine.PARAM_MAIN_SCRIPT);
String rules = (String) cps.getParameterValue(RutaEngine.PARAM_RULES);
- assertNull("mainScript param should be null", mainScript);
- assertNotNull("rules param should not null", rules);
-
- String[] additionalEngines = (String[]) cps.getParameterValue(RutaEngine.PARAM_ADDITIONAL_ENGINES);
- assertNotNull(additionalEngines);
- assertEquals("org.apache.uima.ruta.engine.HtmlAnnotator", additionalEngines[0]);
-
- String[] additionalUimafitEngines = (String[]) cps.getParameterValue(RutaEngine.PARAM_ADDITIONAL_UIMAFIT_ENGINES);
- assertNotNull(additionalUimafitEngines);
- assertEquals("org.apache.uima.ruta.engine.PlainTextAnnotator", additionalUimafitEngines[0]);
-
- String[] additionalScripts = (String[]) cps.getParameterValue(RutaEngine.PARAM_ADDITIONAL_SCRIPTS);
- assertNotNull(additionalScripts);
- assertEquals("org.apache.uiima.ruta.Additional", additionalScripts[0]);
-
+ Assert.assertNull("mainScript param should be null", mainScript);
+ Assert.assertNotNull("rules param should not null", rules);
+
+ String[] additionalEngines = (String[]) cps
+ .getParameterValue(RutaEngine.PARAM_ADDITIONAL_ENGINES);
+ Assert.assertNotNull(additionalEngines);
+ Assert.assertEquals("org.apache.uima.ruta.engine.HtmlAnnotator", additionalEngines[0]);
+
+ String[] additionalUimafitEngines = (String[]) cps
+ .getParameterValue(RutaEngine.PARAM_ADDITIONAL_UIMAFIT_ENGINES);
+ Assert.assertNotNull(additionalUimafitEngines);
+ Assert.assertEquals("org.apache.uima.ruta.engine.PlainTextAnnotator",
+ additionalUimafitEngines[0]);
+
+ String[] additionalScripts = (String[]) cps
+ .getParameterValue(RutaEngine.PARAM_ADDITIONAL_SCRIPTS);
+ Assert.assertNotNull(additionalScripts);
+ Assert.assertEquals("org.apache.uiima.ruta.Additional", additionalScripts[0]);
+
}
@Test
public void testCreateTypeSystemDescription() throws URISyntaxException, IOException,
RecognitionException, InvalidXMLException, ResourceInitializationException {
+
String script = "";
script += "PACKAGE test.package;\n";
script += "TYPESYSTEM org.apache.uima.ruta.engine.HtmlTypeSystem;\n";
@@ -124,7 +130,8 @@ public class GenerateDescriptorTest {
script += "DECLARE InnerType;\n";
script += "}\n";
- RutaDescriptorFactory rdf = new RutaDescriptorFactory(basicTSUrl, basicAEUrl);
+ RutaDescriptorFactory rdf = new RutaDescriptorFactory(GenerateDescriptorTest.basicTSUrl,
+ GenerateDescriptorTest.basicAEUrl);
RutaDescriptorInformation descriptorInformation = rdf.parseDescriptorInformation(script);
RutaBuildOptions options = new RutaBuildOptions();
String typeSystemOutput = "target/temp/testCreateTypeSystemDescription_TypeSystem.xml";
@@ -135,67 +142,97 @@ public class GenerateDescriptorTest {
tsd.resolveImports(rm);
TypeDescription tagType = tsd.getType("org.apache.uima.ruta.type.html.TAG");
- assertNotNull(tagType);
+ Assert.assertNotNull(tagType);
TypeDescription simpleType = tsd.getType("test.package.Anonymous.SimpleType");
- assertNotNull(simpleType);
- assertEquals("uima.tcas.Annotation", simpleType.getSupertypeName());
+ Assert.assertNotNull(simpleType);
+ Assert.assertEquals("uima.tcas.Annotation", simpleType.getSupertypeName());
TypeDescription complexType = tsd.getType("test.package.Anonymous.ComplexType");
- assertNotNull(complexType);
- assertEquals("Type defined in test.package.Anonymous", complexType.getDescription());
- assertEquals("test.package.Anonymous.SimpleType", complexType.getSupertypeName());
+ Assert.assertNotNull(complexType);
+ Assert.assertEquals("Type defined in test.package.Anonymous", complexType.getDescription());
+ Assert.assertEquals("test.package.Anonymous.SimpleType", complexType.getSupertypeName());
FeatureDescription[] features = complexType.getFeatures();
Map<String, String> featureMap = new HashMap<>();
featureMap.put("fs", "test.package.Anonymous.SimpleType");
featureMap.put("s", "uima.cas.String");
featureMap.put("b", "uima.cas.Boolean");
featureMap.put("i", "uima.cas.Integer");
- assertEquals(4, features.length);
+ Assert.assertEquals(4, features.length);
for (FeatureDescription each : features) {
String f = featureMap.get(each.getName());
- assertNotNull(f);
+ Assert.assertNotNull(f);
}
-
+
TypeDescription complexType2 = tsd.getType("test.package.Anonymous.ComplexType2");
- assertNotNull(complexType2);
- assertEquals("Type defined in test.package.Anonymous", complexType2.getDescription());
- assertEquals("uima.tcas.Annotation", complexType2.getSupertypeName());
+ Assert.assertNotNull(complexType2);
+ Assert.assertEquals("Type defined in test.package.Anonymous", complexType2.getDescription());
+ Assert.assertEquals("uima.tcas.Annotation", complexType2.getSupertypeName());
FeatureDescription[] features2 = complexType2.getFeatures();
Map<String, String> featureMap2 = new HashMap<>();
featureMap2.put("fs", "test.package.Anonymous.SimpleType");
featureMap2.put("s", "uima.cas.String");
featureMap2.put("b", "uima.cas.Boolean");
featureMap2.put("i", "uima.cas.Integer");
- assertEquals(4, features2.length);
+ Assert.assertEquals(4, features2.length);
for (FeatureDescription each : features2) {
String f = featureMap2.get(each.getName());
- assertNotNull(f);
+ Assert.assertNotNull(f);
}
TypeDescription innerType = tsd.getType("test.package.Anonymous.sub.InnerType");
- assertNotNull(innerType);
- assertEquals("uima.tcas.Annotation", innerType.getSupertypeName());
+ Assert.assertNotNull(innerType);
+ Assert.assertEquals("uima.tcas.Annotation", innerType.getSupertypeName());
+
+ }
+
+ @Test
+ public void testRuleScriptName() throws URISyntaxException, IOException, RecognitionException,
+ InvalidXMLException, ResourceInitializationException {
+
+ String script = "";
+ script += "PACKAGE test.package;\n";
+ 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/testRuleScriptName_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("test.package.SimpleType");
+ Assert.assertNotNull(tagType);
}
@Test
public void testScriptOnly() throws Exception {
+
String script = "DECLARE Type; CW{-> Type};";
-
- RutaDescriptorFactory rdf = new RutaDescriptorFactory(basicTSUrl, basicAEUrl);
+
+ RutaDescriptorFactory rdf = new RutaDescriptorFactory(GenerateDescriptorTest.basicTSUrl,
+ GenerateDescriptorTest.basicAEUrl);
RutaDescriptorInformation descriptorInformation = rdf.parseDescriptorInformation(script);
RutaBuildOptions options = new RutaBuildOptions();
- Pair<AnalysisEngineDescription, TypeSystemDescription> descriptions = rdf.createDescriptions(null, null, descriptorInformation, options, null, null, null);
- assertNotNull("Typesystem does not contain declaredtype!", descriptions.getValue().getType("Anonymous.Type"));
- assertNotNull("AE typesystem does not contain declared type!", descriptions.getKey().getAnalysisEngineMetaData().getTypeSystem().getType("Anonymous.Type"));
+ Pair<AnalysisEngineDescription, TypeSystemDescription> descriptions = rdf
+ .createDescriptions(null, null, descriptorInformation, options, null, null, null);
+ Assert.assertNotNull("Typesystem does not contain declaredtype!",
+ descriptions.getValue().getType("Anonymous.Type"));
+ Assert.assertNotNull("AE typesystem does not contain declared type!", descriptions.getKey()
+ .getAnalysisEngineMetaData().getTypeSystem().getType("Anonymous.Type"));
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(descriptions.getKey());
CAS cas = ae.newCAS();
cas.setDocumentText("This is a test.");
ae.process(cas);
Type type = cas.getTypeSystem().getType("Anonymous.Type");
- assertEquals(1, CasUtil.select(cas, type).size());
+ Assert.assertEquals(1, CasUtil.select(cas, type).size());
cas.release();
}
-
+
}
Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DummyAnnotator.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DummyAnnotator.java?rev=1851430&view=auto
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DummyAnnotator.java (added)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DummyAnnotator.java Wed Jan 16 11:45:02 2019
@@ -0,0 +1,32 @@
+/*
+ * 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.engine;
+
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
+import org.apache.uima.jcas.JCas;
+
+public class DummyAnnotator extends JCasAnnotator_ImplBase {
+
+ @Override
+ public void process(JCas jcas) throws AnalysisEngineProcessException {
+
+ }
+
+}
Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DummySeeder.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DummySeeder.java?rev=1851430&view=auto
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DummySeeder.java (added)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DummySeeder.java Wed Jan 16 11:45:02 2019
@@ -0,0 +1,37 @@
+/*
+ * 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.engine;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.ruta.seed.RutaAnnotationSeeder;
+import org.apache.uima.ruta.seed.TextSeeder;
+
+public class DummySeeder implements RutaAnnotationSeeder{
+
+ @Override
+ public Type seed(String text, CAS cas) {
+ Type type = cas.getTypeSystem().getType(TextSeeder.seedType);
+ AnnotationFS annotation = cas.createAnnotation(type, 0, text.length());
+ cas.addFsToIndexes(annotation);
+ return type;
+ }
+
+}
Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/MultipleSeedersTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/MultipleSeedersTest.java?rev=1851430&view=auto
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/MultipleSeedersTest.java (added)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/MultipleSeedersTest.java Wed Jan 16 11:45:02 2019
@@ -0,0 +1,50 @@
+/*
+ * 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.engine;
+
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.fit.factory.AnalysisEngineFactory;
+import org.apache.uima.fit.util.JCasUtil;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.ruta.type.ALL;
+import org.apache.uima.ruta.type.TruePositive;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class MultipleSeedersTest {
+
+ @Test
+ public void test() throws ResourceInitializationException, AnalysisEngineProcessException {
+
+ AnalysisEngine ae = AnalysisEngineFactory.createEngine(RutaEngine.class,
+ RutaEngine.PARAM_RULES, "TokenSeed{-> TruePositive};",
+ RutaEngine.PARAM_SEEDERS, new String[] {DummySeeder.class.getName(),DummySeeder.class.getName()});
+
+ JCas jcas = ae.newJCas();
+ jcas.setDocumentText("Dummy text.");
+ ae.process(jcas);
+
+ Assert.assertEquals(2, JCasUtil.select(jcas, TruePositive.class).size());
+ Assert.assertEquals(0, JCasUtil.select(jcas, ALL.class).size());
+
+ }
+
+}
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ParamVarTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ParamVarTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ParamVarTest.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ParamVarTest.java Wed Jan 16 11:45:02 2019
@@ -92,10 +92,10 @@ public class ParamVarTest {
Ruta.apply(cas, script, params);
RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "Some", "text");
-
+
cas.release();
}
-
+
@Test(expected = AnalysisEngineProcessException.class)
public void testWithStrictImport() throws Exception {
String document = "Some text.";
@@ -109,15 +109,44 @@ public class ParamVarTest {
Map<String, Object> params = new HashMap<String, Object>();
params.put(RutaEngine.PARAM_STRICT_IMPORTS, true);
params.put(RutaEngine.PARAM_VAR_NAMES, new String[] { "t1", "t2", "tl" });
- params.put(RutaEngine.PARAM_VAR_VALUES, new String[] {"org.apache.uima.T1", "org.apache.uima.T2",
- "org.apache.uima.T1,org.apache.uima.T2" });
+ params.put(RutaEngine.PARAM_VAR_VALUES, new String[] { "org.apache.uima.T1",
+ "org.apache.uima.T2", "org.apache.uima.T1,org.apache.uima.T2" });
CAS cas = RutaTestUtils.getCAS(document);
Ruta.apply(cas, script, params);
RutaTestUtils.assertAnnotationsEquals(cas, 3, 2, "Some", "text");
-
+
cas.release();
}
-
+
+ @Test
+ public void testKnownVariableValue() throws Exception {
+ String document = "Some text.";
+ String script = "";
+ script += "TYPE tvar;";
+ script += "tvar{ -> T1};";
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put(RutaEngine.PARAM_VAR_NAMES, new String[] { "tvar" });
+ params.put(RutaEngine.PARAM_VAR_VALUES, new String[] { "some.UnknownType" });
+
+ CAS cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script, params);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 0);
+ }
+
+ @Test
+ public void testMissingVariableValue() throws Exception {
+ String document = "Some text.";
+ String script = "";
+ script += "TYPE tvar;";
+ script += "tvar{ -> T1};";
+ Map<String, Object> params = new HashMap<String, Object>();
+
+ CAS cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script, params);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 0);
+ }
}
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=1851430&r1=1851429&r2=1851430&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 Wed Jan 16 11:45:02 2019
@@ -24,11 +24,18 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.cas.CAS;
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.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.ruta.RutaProcessRuntimeException;
import org.apache.uima.ruta.TypeUsageInformation;
import org.junit.Assert;
import org.junit.Test;
@@ -49,8 +56,8 @@ public class RutaEngineTest {
AnalysisEngine ae = AnalysisEngineFactory.createEngine(RutaEngine.class,
RutaEngine.PARAM_VAR_NAMES, new String[] { "typeVar" }, RutaEngine.PARAM_VAR_VALUES,
new String[] { "TruePositive" }, RutaEngine.PARAM_RULES, script,
- RutaEngine.PARAM_INDEX_ONLY_MENTIONED_TYPES, true, RutaEngine.PARAM_INDEX_ADDITONALLY,
- new String[] { "COMMA" });
+ RutaEngine.PARAM_INDEX_ONLY_MENTIONED_TYPES, Boolean.valueOf(true),
+ RutaEngine.PARAM_INDEX_ADDITONALLY, new String[] { "COMMA" });
RutaEngine engine = (RutaEngine) FieldUtils.readField(ae, "mAnalysisComponent", true);
TypeUsageInformation typeUsageInformation = (TypeUsageInformation) FieldUtils.readField(engine,
@@ -82,4 +89,94 @@ public class RutaEngineTest {
}
+ @Test(expected = NotImplementedException.class)
+ public void testInferenceVisitors() throws Throwable {
+
+ String document = "Some text.";
+ String script = "CW;";
+
+ AnalysisEngine ae = AnalysisEngineFactory.createEngine(RutaEngine.class, RutaEngine.PARAM_RULES,
+ script, RutaEngine.PARAM_INFERENCE_VISITORS,
+ new String[] { TestRutaInferenceVisitor.class.getName() });
+
+ CAS cas = RutaTestUtils.getCAS(document);
+
+ try {
+ ae.process(cas);
+ } catch (AnalysisEngineProcessException e) {
+ Throwable cause = e.getCause();
+ throw cause;
+ }
+ }
+
+ @Test
+ public void testMaxRuleMatches() throws Throwable {
+
+ String document = "This is some text.";
+ String script = "W;";
+
+ AnalysisEngine ae = AnalysisEngineFactory.createEngine(RutaEngine.class, RutaEngine.PARAM_RULES,
+ script, RutaEngine.PARAM_MAX_RULE_MATCHES, Integer.valueOf(2));
+
+ CAS cas = RutaTestUtils.getCAS(document);
+
+ try {
+ ae.process(cas);
+ } catch (AnalysisEngineProcessException e) {
+ Throwable cause = e.getCause();
+ Assert.assertTrue(cause instanceof RutaProcessRuntimeException);
+ String message = cause.getMessage();
+ Assert.assertTrue(message.startsWith("Rule exceeded the allowed amount of matches"));
+ return;
+ }
+ Assert.fail("expected RutaProcessRuntimeException");
+ }
+
+ @Test
+ public void testMaxRuleElementMatches() throws Throwable {
+
+ String document = "This is some text.";
+ String script = "W+;";
+
+ AnalysisEngine ae = AnalysisEngineFactory.createEngine(RutaEngine.class, RutaEngine.PARAM_RULES,
+ script, RutaEngine.PARAM_MAX_RULE_ELEMENT_MATCHES, Integer.valueOf(2));
+
+ CAS cas = RutaTestUtils.getCAS(document);
+
+ try {
+ ae.process(cas);
+ } catch (AnalysisEngineProcessException e) {
+ Throwable cause = e.getCause();
+ Assert.assertTrue(cause instanceof RutaProcessRuntimeException);
+ String message = cause.getMessage();
+ Assert.assertTrue(message.startsWith("Rule element exceeded the allowed amount of matches"));
+ return;
+ }
+ Assert.fail("expected RutaProcessRuntimeException");
+ }
+
+ @Test
+ public void testResourceManagerWithUimaFITInEXEC() throws Throwable {
+
+ final ResourceManager resourceManager = ResourceManagerFactory.newResourceManager();
+ ResourceManagerFactory.setResourceManagerCreator(new ResourceManagerCreator() {
+
+ @Override
+ public ResourceManager newResourceManager() throws ResourceInitializationException {
+ return resourceManager;
+ }
+ });
+
+ String document = "This is some text.";
+ String script = "UIMAFIT org.apache.uima.ruta.engine.DummyAnnotator;";
+ script += "EXEC(DummyAnnotator);";
+
+ AnalysisEngine ae = AnalysisEngineFactory.createEngine(RutaEngine.class, RutaEngine.PARAM_RULES,
+ script, RutaEngine.PARAM_ADDITIONAL_UIMAFIT_ENGINES,
+ new String[] { DummyAnnotator.class.getName() });
+
+ CAS cas = RutaTestUtils.getCAS(document);
+ ae.process(cas);
+ }
+
}
Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/TestRutaInferenceVisitor.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/TestRutaInferenceVisitor.java?rev=1851430&view=auto
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/TestRutaInferenceVisitor.java (added)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/TestRutaInferenceVisitor.java Wed Jan 16 11:45:02 2019
@@ -0,0 +1,55 @@
+/*
+ * 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.engine;
+
+import java.util.List;
+
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.ruta.RutaElement;
+import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.ScriptApply;
+import org.apache.uima.ruta.rule.AbstractRule;
+import org.apache.uima.ruta.rule.AbstractRuleMatch;
+import org.apache.uima.ruta.visitor.RutaInferenceVisitor;
+
+public class TestRutaInferenceVisitor implements RutaInferenceVisitor {
+
+ @Override
+ public void beginVisit(RutaElement element, ScriptApply result) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void endVisit(RutaElement element, ScriptApply result) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void finished(RutaStream stream, List<RutaInferenceVisitor> visitors) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void annotationAdded(AnnotationFS annotation,
+ AbstractRuleMatch<? extends AbstractRule> creator) {
+ throw new NotImplementedException();
+ }
+
+}
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/ThreeStackedScriptsVariableResetTest.java Wed Jan 16 11:45:02 2019
@@ -52,25 +52,27 @@ public class ThreeStackedScriptsVariable
RutaBuildOptions options = new RutaBuildOptions();
RutaDescriptorInformation rdi = factory
.parseDescriptorInformation(new File(path + "script1.ruta"), options);
- Pair<AnalysisEngineDescription, TypeSystemDescription> descriptions = factory.createDescriptions(null, Paths.get(path).toFile().getAbsolutePath(), rdi, options, new String[] { path }, new String[] { path }, null);
+ Pair<AnalysisEngineDescription, TypeSystemDescription> descriptions = factory
+ .createDescriptions(null, Paths.get(path).toFile().getAbsolutePath(), rdi, options,
+ new String[] { path }, new String[] { path }, null);
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(descriptions.getKey());
JCas jcas = JCasFactory.createJCas(descriptions.getValue());
-
+
jcas.setDocumentText(input1);
ae.process(jcas);
checkFeatureValue(jcas);
-
+
jcas.reset();
jcas.setDocumentText(input2);
ae.process(jcas);
checkFeatureValue(jcas);
-
+
jcas.reset();
jcas.setDocumentText(input3);
ae.process(jcas);
checkFeatureValue(jcas);
-
+
}
private void checkFeatureValue(JCas jcas) {
@@ -79,7 +81,7 @@ public class ThreeStackedScriptsVariable
Feature feature = type.getFeatureByBaseName("value");
FeatureStructure fs = CasUtil.selectSingle(cas, type);
String stringValue = fs.getStringValue(feature);
- Assert.assertEquals("", stringValue);
+ Assert.assertNull(stringValue);
}
}
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/AnnotationTypeExpressionTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/AnnotationTypeExpressionTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/AnnotationTypeExpressionTest.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/AnnotationTypeExpressionTest.java Wed Jan 16 11:45:02 2019
@@ -38,7 +38,7 @@ public class AnnotationTypeExpressionTes
String script = "";
script += "Document{-> CREATE(Struct1, \"as\" = COMMA)};\n";
script += "Struct1.as{-> T1};\n";
-
+
Map<String, String> complexTypes = new TreeMap<String, String>();
complexTypes.put("Struct1", "uima.tcas.Annotation");
complexTypes.put("Struct2", "uima.tcas.Annotation");
@@ -48,11 +48,27 @@ public class AnnotationTypeExpressionTes
features.put("Struct2", list);
list.add(new TestFeature("a", "", "uima.tcas.Annotation"));
list.add(new TestFeature("as", "", "uima.cas.FSArray"));
-
+
CAS cas = RutaTestUtils.getCAS(document, complexTypes, features);
- Ruta.apply(cas, script);
-
+ Ruta.apply(cas, script);
+
RutaTestUtils.assertAnnotationsEquals(cas, 1, 0);
}
+ @Test
+ public void testTypeList() throws Exception {
+ String document = "This is a test.";
+ String script = "TYPELIST tl = {CW,PERIOD};\n";
+ script += "tl{-> T1};\n";
+ script += "SW tl{-> T2};\n";
+ script += "tl{-> T3} @SW;\n";
+
+ CAS cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 2, "This", ".");
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, ".");
+ RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "This");
+ }
+
}
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpressionTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpressionTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpressionTest.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpressionTest.java Wed Jan 16 11:45:02 2019
@@ -217,14 +217,14 @@ public class AnnotationFeatureExpression
RutaTestUtils.assertAnnotationsEquals(cas, 10, 1, "Some");
}
-
+
@Test
public void testFeatureMatch() throws Exception {
String document = "This is a test.";
String script = "";
script += "Document{-> CREATE(Struct1, \"a\" = SW.begin == 8)};\n";
script += "Struct1.a{-> T1};\n";
-
+
Map<String, String> complexTypes = new TreeMap<String, String>();
complexTypes.put("Struct1", "uima.tcas.Annotation");
Map<String, List<TestFeature>> features = new TreeMap<String, List<TestFeature>>();
@@ -232,11 +232,103 @@ public class AnnotationFeatureExpression
features.put("Struct1", list);
list.add(new TestFeature("a", "", "uima.tcas.Annotation"));
list.add(new TestFeature("as", "", "uima.cas.FSArray"));
-
+
CAS cas = RutaTestUtils.getCAS(document, complexTypes, features);
- Ruta.apply(cas, script);
-
+ Ruta.apply(cas, script);
+
RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "a");
}
+ @Test
+ public void testPartofOnNullMatch() throws Exception {
+ String document = "Some text.";
+ String script = "";
+ script += "W{-> CREATE(Struct)};\n";
+ script += "Struct.a{PARTOF(CW)-> T1};\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 = "a";
+ list.add(new TestFeature(fn1, "", "uima.tcas.Annotation"));
+
+ CAS cas = RutaTestUtils.getCAS(document, typeMap, featureMap);
+ Ruta.apply(cas, script);
+
+ }
+
+ @Test
+ public void testAnnotationComparison() throws Exception {
+ String document = "Some text for testing.";
+ String t40String = "for testing.";
+
+ String script = "ANNOTATION a;\n";
+ script += "ANNOTATIONLIST as;\n";
+ script += "ANNOTATION a2;\n";
+ script += "ANNOTATIONLIST as2;\n";
+ script += "Document{-> a = CW};\n";
+ script += "Document{-> as = SW};\n";
+ script += "(W W @PERIOD){-> T40};\n";
+ script += "T40{-> a2 = PERIOD};\n";
+ script += "T40{-> as2 = SW};\n";
+ script += "Document{-> CREATE(Struct1, \"a\" = CW, \"as\" = SW )};\n";
+ script += "T40{-> CREATE(Struct2, \"a\" = PERIOD, \"as\" = SW )};\n";
+
+ script += "Document{Struct1.a == a -> T1};\n";
+ script += "Document{Struct1.as == as -> T2};\n";
+ script += "Document{Struct1.a != a -> T3};\n";
+ script += "Document{Struct1.as != as -> T4};\n";
+ script += "Struct1.a == a { -> T5};\n";
+ script += "Struct1.as == as { -> T6};\n";
+
+ script += "T40{Struct2.a == a2 -> T7};\n";
+ script += "T40{Struct2.as == as2 -> T8};\n";
+ script += "T40{Struct2.a != a2 -> T9};\n";
+ script += "T40{Struct2.as != as2 -> T10};\n";
+ script += "Struct2.a == a2 { -> T11};\n";
+ script += "Struct2.as == as2 { -> T12};\n";
+
+ script += "Document{a != a2 -> T13};\n";
+ script += "Document{as != as2 -> T14};\n";
+
+ Map<String, String> typeMap = new TreeMap<String, String>();
+ String typeName1 = "Struct1";
+ typeMap.put(typeName1, "uima.tcas.Annotation");
+ String typeName2 = "Struct2";
+ typeMap.put(typeName2, "uima.tcas.Annotation");
+
+ Map<String, List<TestFeature>> featureMap = new TreeMap<String, List<TestFeature>>();
+ List<TestFeature> list = new ArrayList<RutaTestUtils.TestFeature>();
+ featureMap.put(typeName1, list);
+ featureMap.put(typeName2, list);
+ String fn1 = "a";
+ list.add(new TestFeature(fn1, "", "uima.tcas.Annotation"));
+ String fn2 = "as";
+ list.add(new TestFeature(fn2, "", "uima.cas.FSArray"));
+
+ CAS cas = RutaTestUtils.getCAS(document, typeMap, featureMap);
+ Ruta.apply(cas, script);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, document);
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, document);
+ RutaTestUtils.assertAnnotationsEquals(cas, 3, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 4, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 5, 1, document);
+ RutaTestUtils.assertAnnotationsEquals(cas, 6, 1, document);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 7, 1, t40String);
+ RutaTestUtils.assertAnnotationsEquals(cas, 8, 1, t40String);
+ RutaTestUtils.assertAnnotationsEquals(cas, 9, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 10, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 11, 1, t40String);
+ RutaTestUtils.assertAnnotationsEquals(cas, 12, 1, t40String);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 13, 1, document);
+ RutaTestUtils.assertAnnotationsEquals(cas, 14, 1, document);
+ }
+
}
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=1851430&r1=1851429&r2=1851430&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 Wed Jan 16 11:45:02 2019
@@ -654,6 +654,9 @@ public class AnnotationLabelExpressionTe
script += "s1:Struct{IS(PERIOD), s1.a.b -> T8};";
CAS cas = RutaTestUtils.getCAS(document, typeMap, featureMap);
Ruta.apply(cas, script);
+
+ RutaTestUtils.storeCas(cas, "testStackedReinitLazyFeature");
+
RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Some");
RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "Some");
RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "Some");
@@ -709,4 +712,62 @@ public class AnnotationLabelExpressionTe
return cas;
}
+ @Test
+ public void testLabelAssignmentInFailedQuantifier() throws Exception {
+
+ String document = "a 1 a a 1 a a 1 a";
+
+ String script = "NUM{-> T1, T2, T3, T4, T7, T8};\n";
+ script += "SW{-> T5, T6};\n";
+
+ script += "ps:T1{-> ps.end = a.end} a:ANY[1,10]{-PARTOF(T1)};\n";
+ script += "a:ANY[1,10]{-PARTOF(T2)} ps:@T2{-> ps.begin = a.begin};\n";
+
+ script += "ps:T3{-> ps.end = a.end} a:ANY+{-PARTOF(T3)};\n";
+ script += "a:ANY+{-PARTOF(T4)} ps:@T4{-> ps.begin = a.begin};\n";
+
+// script += "ps:T5{-> ps.end = a.end} a:ANY?{-PARTOF(T5)};\n";
+// script += "a:ANY?{-PARTOF(T6)} ps:@T6{-> ps.begin = a.begin};\n";
+
+// script += "ps:T7{-> ps.end = a.end} a:ANY*?{-PARTOF(T7)};\n";
+// script += "a:ANY*?{-PARTOF(T8)} ps:@T8{-> ps.begin = a.begin};\n";
+
+ CAS cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "1 a a", "1 a a", "1 a");
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 3, "a 1", "a a 1", "a a 1");
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 3, 3, "1 a a", "1 a a", "1 a");
+ RutaTestUtils.assertAnnotationsEquals(cas, 4, 3, "a 1", "a a 1", "a a 1");
+
+// RutaTestUtils.assertAnnotationsEquals(cas, 5, 6, "a 1", "a", "a 1", "a", "a 1", "a");
+// RutaTestUtils.assertAnnotationsEquals(cas, 6, 6, "a", "1 a", "a", "1 a", "a", "1 a");
+
+// RutaTestUtils.assertAnnotationsEquals(cas, 7, 3, "1 a a", "1 a a", "1 a");
+// RutaTestUtils.assertAnnotationsEquals(cas, 8, 3, "a 1", "a a 1", "a a 1");
+ }
+
+ @Test
+ public void testRemoveFailedMatch() throws Exception {
+
+ String document = "a b c d";
+
+ String script = "";
+ script += "W.begin==0{-> T1};\n";
+ script += "T1 a:ANY{REGEXP(\"c\")}->{a{-> T2};};\n";
+ script += "T1 a:ANY{REGEXP(\"c\")}<-{a{-> T3};};\n";
+ script += "d:Document{-> T4}<-{a:d{STARTSWITH(CW)};b:d{STARTSWITH(W)};}->{a{->T5};};\n";
+
+ CAS cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "a");
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 3, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 4, 1, document);
+ RutaTestUtils.assertAnnotationsEquals(cas, 5, 0);
+
+ }
+
}
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationVariableExpressionTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationVariableExpressionTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationVariableExpressionTest.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationVariableExpressionTest.java Wed Jan 16 11:45:02 2019
@@ -22,27 +22,38 @@ package org.apache.uima.ruta.expression.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.IOException;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+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.FSIterator;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.fit.factory.AnalysisEngineFactory;
import org.apache.uima.jcas.cas.FSArray;
+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.RutaEngine;
import org.apache.uima.ruta.engine.RutaTestUtils;
import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature;
+import org.apache.uima.util.InvalidXMLException;
import org.junit.Test;
public class AnnotationVariableExpressionTest {
@Test
- public void test() {
+ public void test() throws ResourceInitializationException, InvalidXMLException, IOException,
+ AnalysisEngineProcessException, ResourceConfigurationException, URISyntaxException {
String document = "Some text.";
String script = "ANNOTATION a;";
script += "CW{-> ASSIGN(a, CW)};";
@@ -59,13 +70,8 @@ public class AnnotationVariableExpressio
String fn = "a";
list.add(new TestFeature(fn, "", "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;
@@ -86,9 +92,11 @@ public class AnnotationVariableExpressio
assertNotNull("Feature value is null!", a);
assertEquals("Some", a.getCoveredText());
}
-
+
@Test
- public void testImplicitAssignment() {
+ public void testImplicitAssignment()
+ throws ResourceInitializationException, InvalidXMLException, IOException,
+ AnalysisEngineProcessException, ResourceConfigurationException, URISyntaxException {
String document = "Some text.";
String script = "ANNOTATION a;";
script += "CW{-> a = CW};";
@@ -105,13 +113,8 @@ public class AnnotationVariableExpressio
String fn = "a";
list.add(new TestFeature(fn, "", "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;
@@ -134,7 +137,9 @@ public class AnnotationVariableExpressio
}
@Test
- public void testListImplicitAssignment() {
+ public void testListImplicitAssignment()
+ throws ResourceInitializationException, InvalidXMLException, IOException,
+ AnalysisEngineProcessException, ResourceConfigurationException, URISyntaxException {
String document = "Some text.";
String script = "ANNOTATIONLIST as;";
script += "Document{-> as = W};";
@@ -151,13 +156,8 @@ public class AnnotationVariableExpressio
String fn = "as";
list.add(new TestFeature(fn, "", "uima.cas.FSArray"));
- 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;
@@ -178,9 +178,10 @@ public class AnnotationVariableExpressio
assertNotNull("Feature value is null!", array);
assertEquals(2, array.size());
}
-
+
@Test
- public void testList() {
+ public void testList() throws ResourceInitializationException, InvalidXMLException, IOException,
+ AnalysisEngineProcessException, ResourceConfigurationException, URISyntaxException {
String document = "Some text.";
String script = "ANNOTATIONLIST as;";
script += "Document{-> ASSIGN(as, W)};";
@@ -197,13 +198,8 @@ public class AnnotationVariableExpressio
String fn = "as";
list.add(new TestFeature(fn, "", "uima.cas.FSArray"));
- 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;
@@ -224,4 +220,70 @@ public class AnnotationVariableExpressio
assertNotNull("Feature value is null!", array);
assertEquals(2, array.size());
}
+
+ @Test
+ public void testResetVariableBetweenCases()
+ throws ResourceInitializationException, InvalidXMLException, IOException,
+ AnalysisEngineProcessException, ResourceConfigurationException, URISyntaxException {
+
+ String document = "Some text.";
+ String script = "ANNOTATIONLIST as;\n";
+ script += "ANNOTATION a;\n";
+ script += "WORDLIST wl = 'org/apache/uima/ruta/WSDictionaryTestList.txt';\n";
+ script += "WORDTABLE wt = 'org/apache/uima/ruta/table2.csv';\n";
+ script += "a{-> T1};\n";
+ script += "as{-> T2};\n";
+ script += "Document{-> a = CW};\n";
+ script += "Document{-> as = W};\n";
+ script += "a{-> T3};\n";
+ script += "as{-> T4};";
+
+ AnalysisEngineDescription description = AnalysisEngineFactory
+ .createEngineDescription(RutaEngine.class, RutaEngine.PARAM_RULES, script);
+ AnalysisEngine engine = AnalysisEngineFactory.createEngine(description);
+
+ CAS cas = RutaTestUtils.getCAS(document);
+
+ cas.reset();
+ cas.setDocumentText(document);
+ engine.process(cas);
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "Some");
+ RutaTestUtils.assertAnnotationsEquals(cas, 4, 2, "Some", "text");
+
+ cas.reset();
+ cas.setDocumentText(document);
+ engine.process(cas);
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "Some");
+ RutaTestUtils.assertAnnotationsEquals(cas, 4, 2, "Some", "text");
+
+ }
+
+ @Test
+ public void testNullValueWithFeatureMatch()
+ throws ResourceInitializationException, InvalidXMLException, IOException,
+ AnalysisEngineProcessException, ResourceConfigurationException, URISyntaxException {
+
+ String document = "Some text.";
+ String script = "";
+ script += "ANNOTATION a;\n";
+ script += "INT i;\n";
+ script += "STRING s;\n";
+ script += "a.begin == 0{-> T1};\n";
+ script += "a.ct == \"text\"{-> T2};\n";
+ script += "a.ff == \"text\"{-> T3};\n"; // !!!
+ script += "Document{-> i = a.begin};\n";
+ script += "Document{-> s = a.ct};\n";
+
+ CAS cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 0);
+
+ }
+
}
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/resource/WordTableStringExpressionTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/resource/WordTableStringExpressionTest.java?rev=1851430&r1=1851429&r2=1851430&view=diff
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/resource/WordTableStringExpressionTest.java (original)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/resource/WordTableStringExpressionTest.java Wed Jan 16 11:45:02 2019
@@ -22,6 +22,7 @@ package org.apache.uima.ruta.expression.
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -33,25 +34,25 @@ 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.RutaEngine;
import org.apache.uima.ruta.engine.RutaTestUtils;
import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature;
import org.junit.Test;
public class WordTableStringExpressionTest {
-
@Test
public void test() throws Exception {
String document = "Kluegl Schor Kottmann";
- String script="STRING s = \"org/apache/uima/ruta/action/\";\n";
- script +="WORDTABLE table = s + \"table.csv\";\n";
- script +="MARKTABLE(Person, 1, table, true, 0, \"-.,\", 10, \"firstname\" = 2, \"system\" = 3);\n";
-
+ String script = "STRING s = \"org/apache/uima/ruta/action/\";\n";
+ script += "WORDTABLE table = s + \"table.csv\";\n";
+ script += "MARKTABLE(Person, 1, table, true, 0, \"-.,\", 10, \"firstname\" = 2, \"system\" = 3);\n";
+
Map<String, String> complexTypes = new TreeMap<String, String>();
String typeName = "org.apache.uima.Person";
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);
@@ -59,10 +60,13 @@ public class WordTableStringExpressionTe
list.add(new TestFeature(fn1, "", "uima.cas.String"));
String fn2 = "system";
list.add(new TestFeature(fn2, "", "uima.cas.String"));
-
+
+ Map<String, Object> map = new HashMap<>();
+ map.put(RutaEngine.PARAM_DICT_REMOVE_WS, true);
+
CAS cas = RutaTestUtils.getCAS(document, complexTypes, features);
- Ruta.apply(cas, script);
-
+ Ruta.apply(cas, script, map);
+
Type t = null;
AnnotationIndex<AnnotationFS> ai = null;
FSIterator<AnnotationFS> iterator = null;
@@ -73,46 +77,46 @@ public class WordTableStringExpressionTe
Feature f1 = t.getFeatureByBaseName(fn1);
Feature f2 = t.getFeatureByBaseName(fn2);
ai = cas.getAnnotationIndex(t);
-
+
assertEquals(3, ai.size());
iterator = ai.iterator();
-
+
next = iterator.next();
v1 = next.getStringValue(f1);
v2 = next.getStringValue(f2);
assertEquals("Peter", v1);
assertEquals("Ruta", v2);
-
+
next = iterator.next();
v1 = next.getStringValue(f1);
v2 = next.getStringValue(f2);
assertEquals("Marshall", v1);
assertEquals("UIMA", v2);
-
+
next = iterator.next();
v1 = next.getStringValue(f1);
v2 = next.getStringValue(f2);
assertEquals("Joern", v1);
assertEquals("CAS Editor", v2);
-
- cas.release();
+
+ cas.release();
}
-
+
@Test
public void testInBlock() throws Exception {
String document = "Kluegl Schor Kottmann";
- String script="STRING s = \"org/apache/uima/ruta/action/\";\n";
- script +="BLOCK(block) Document{}{\n";
- script +="WORDTABLE table = s + \"table.csv\";\n";
- script +="MARKTABLE(Person, 1, table, true, 0, \"-.,\", 10, \"firstname\" = 2, \"system\" = 3);\n";
- script +="}\n";
-
+ String script = "STRING s = \"org/apache/uima/ruta/action/\";\n";
+ script += "BLOCK(block) Document{}{\n";
+ script += "WORDTABLE table = s + \"table.csv\";\n";
+ script += "MARKTABLE(Person, 1, table, true, 0, \"-.,\", 10, \"firstname\" = 2, \"system\" = 3);\n";
+ script += "}\n";
+
Map<String, String> complexTypes = new TreeMap<String, String>();
String typeName = "org.apache.uima.Person";
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);
@@ -120,10 +124,13 @@ public class WordTableStringExpressionTe
list.add(new TestFeature(fn1, "", "uima.cas.String"));
String fn2 = "system";
list.add(new TestFeature(fn2, "", "uima.cas.String"));
-
+
+ Map<String, Object> map = new HashMap<>();
+ map.put(RutaEngine.PARAM_DICT_REMOVE_WS, true);
+
CAS cas = RutaTestUtils.getCAS(document, complexTypes, features);
- Ruta.apply(cas, script);
-
+ Ruta.apply(cas, script, map);
+
Type t = null;
AnnotationIndex<AnnotationFS> ai = null;
FSIterator<AnnotationFS> iterator = null;
@@ -134,30 +141,30 @@ public class WordTableStringExpressionTe
Feature f1 = t.getFeatureByBaseName(fn1);
Feature f2 = t.getFeatureByBaseName(fn2);
ai = cas.getAnnotationIndex(t);
-
+
assertEquals(3, ai.size());
iterator = ai.iterator();
-
+
next = iterator.next();
v1 = next.getStringValue(f1);
v2 = next.getStringValue(f2);
assertEquals("Peter", v1);
assertEquals("Ruta", v2);
-
+
next = iterator.next();
v1 = next.getStringValue(f1);
v2 = next.getStringValue(f2);
assertEquals("Marshall", v1);
assertEquals("UIMA", v2);
-
+
next = iterator.next();
v1 = next.getStringValue(f1);
v2 = next.getStringValue(f2);
assertEquals("Joern", v1);
assertEquals("CAS Editor", v2);
-
- cas.release();
+
+ cas.release();
}
-
+
}
Added: uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/string/StringSubtypeAllowedValuesTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/string/StringSubtypeAllowedValuesTest.java?rev=1851430&view=auto
==============================================================================
--- uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/string/StringSubtypeAllowedValuesTest.java (added)
+++ uima/uv3/ruta-v3/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/string/StringSubtypeAllowedValuesTest.java Wed Jan 16 11:45:02 2019
@@ -0,0 +1,111 @@
+/*
+ * 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.string;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.CASException;
+import org.apache.uima.fit.factory.TypeSystemDescriptionFactory;
+import org.apache.uima.fit.util.JCasUtil;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceConfigurationException;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.metadata.AllowedValue;
+import org.apache.uima.resource.metadata.FsIndexDescription;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.resource.metadata.impl.AllowedValue_impl;
+import org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl;
+import org.apache.uima.ruta.engine.Ruta;
+import org.apache.uima.ruta.type.FalseNegative;
+import org.apache.uima.ruta.type.FalsePositive;
+import org.apache.uima.ruta.type.TruePositive;
+import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class StringSubtypeAllowedValuesTest {
+
+ @Test
+ public void testValidValue() throws ResourceInitializationException,
+ AnalysisEngineProcessException, InvalidXMLException, ResourceConfigurationException,
+ IOException, URISyntaxException, CASException {
+ CAS cas = createCAS();
+
+ String script = "Document{-> CREATE(Test, \"allowed\" = \"A\")};";
+ script += "Document{-> CREATE(Test, \"allowed\" = \"B\")};";
+ // using eval types just as helper types
+ script += "Test.allowed == \"A\"{-> TruePositive};";
+ script += "Test.allowed == \"B\"{-> TruePositive};";
+ script += "t:Test{t.allowed == \"A\" -> TruePositive};";
+ script += "t:Test{t.allowed == \"B\" -> TruePositive};";
+ script += "Test.allowed == \"\"{-> FalseNegative};";
+ script += "Test.allowed == \"C\"{-> FalsePositive};";
+
+ Ruta.apply(cas, script);
+
+ JCas jcas = cas.getJCas();
+ Assert.assertEquals(4, JCasUtil.select(jcas, TruePositive.class).size());
+ Assert.assertEquals(0, JCasUtil.select(jcas, FalseNegative.class).size());
+ Assert.assertEquals(0, JCasUtil.select(jcas, FalsePositive.class).size());
+
+ }
+
+ @Test(expected = AnalysisEngineProcessException.class)
+ public void testInvalidValue() throws ResourceInitializationException,
+ AnalysisEngineProcessException, InvalidXMLException, ResourceConfigurationException,
+ IOException, URISyntaxException, CASException {
+
+ CAS cas = createCAS();
+
+ String script = "Document{-> CREATE(Test, \"allowed\" = \"D\")};";
+
+ Ruta.apply(cas, script);
+ }
+
+ private CAS createCAS() throws ResourceInitializationException {
+ TypeSystemDescription typeSystemDescription = new TypeSystemDescription_impl();
+ String subStringTypeName = "ruta.SubString";
+ TypeDescription stringTypeDescription = typeSystemDescription.addType(subStringTypeName,
+ "for testing", CAS.TYPE_NAME_STRING);
+ stringTypeDescription.setAllowedValues(new AllowedValue[] { new AllowedValue_impl("A", "A"),
+ new AllowedValue_impl("B", "B"), new AllowedValue_impl("C", "C") });
+ TypeDescription testTypeDescription = typeSystemDescription.addType("ruta.Test", "for testing",
+ CAS.TYPE_NAME_ANNOTATION);
+ testTypeDescription.addFeature("allowed", "for testing", subStringTypeName);
+
+ TypeSystemDescription typeSystemDescription2 = TypeSystemDescriptionFactory
+ .createTypeSystemDescription();
+
+ Collection<TypeSystemDescription> typeSystems = new ArrayList<>();
+ typeSystems.add(typeSystemDescription);
+ typeSystems.add(typeSystemDescription2);
+ TypeSystemDescription mergedTypeSystem = CasCreationUtils.mergeTypeSystems(typeSystems);
+ CAS cas = CasCreationUtils.createCas(mergedTypeSystem, null, new FsIndexDescription[0]);
+ cas.setDocumentText("Some text.");
+ return cas;
+ }
+
+}