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 2018/12/20 11:43:39 UTC

svn commit: r1849373 - /uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ImportStatementsTest.java

Author: pkluegl
Date: Thu Dec 20 11:43:39 2018
New Revision: 1849373

URL: http://svn.apache.org/viewvc?rev=1849373&view=rev
Log:
UIMA-5258: added test

Modified:
    uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ImportStatementsTest.java

Modified: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ImportStatementsTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ImportStatementsTest.java?rev=1849373&r1=1849372&r2=1849373&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ImportStatementsTest.java (original)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ImportStatementsTest.java Thu Dec 20 11:43:39 2018
@@ -27,6 +27,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.uima.analysis_engine.AnalysisEngine;
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
@@ -35,10 +36,18 @@ import org.apache.uima.cas.text.Annotati
 import org.apache.uima.fit.factory.AnalysisEngineFactory;
 import org.apache.uima.fit.factory.TypeSystemDescriptionFactory;
 import org.apache.uima.fit.util.CasUtil;
+import org.apache.uima.fit.util.JCasUtil;
 import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.ruta.descriptor.RutaBuildOptions;
+import org.apache.uima.ruta.descriptor.RutaDescriptorFactory;
+import org.apache.uima.ruta.descriptor.RutaDescriptorInformation;
 import org.apache.uima.ruta.engine.RutaEngine;
+import org.apache.uima.ruta.type.FalsePositive;
+import org.apache.uima.ruta.type.TruePositive;
 import org.apache.uima.util.InvalidXMLException;
+import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -46,25 +55,28 @@ import org.junit.Test;
  */
 public class ImportStatementsTest {
   private final String NAME = this.getClass().getSimpleName();
+
   private final String NAMESPACE = this.getClass().getPackage().getName().replaceAll("\\.", "/");
 
   /**
    * Create an analysis engine for a Ruta script.
    *
-   * @param script       Script path.
-   * @param strictImport {@link org.apache.uima.ruta.engine.RutaEngine#PARAM_STRICT_IMPORTS} value.
+   * @param script
+   *          Script path.
+   * @param strictImport
+   *          {@link org.apache.uima.ruta.engine.RutaEngine#PARAM_STRICT_IMPORTS} value.
    * @return Analysis engine.
    */
-  private AnalysisEngine createAE(String script, boolean strictImport) throws ResourceInitializationException, IOException, InvalidXMLException {
+  private AnalysisEngine createAE(String script, boolean strictImport)
+          throws ResourceInitializationException, IOException, InvalidXMLException {
     final TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescription(
-        "org.apache.uima.ruta.engine.BasicTypeSystem",
-        "org.apache.uima.ruta.ImportStatementsTestTypeSystem",
-        "org.apache.uima.ruta.ImportStatementsTestTypeSystemWithAmbiguousShortNames",
-        "org.apache.uima.ruta.ImportStatementsTestTypeSystemWithManyPackages");
+            "org.apache.uima.ruta.engine.BasicTypeSystem",
+            "org.apache.uima.ruta.ImportStatementsTestTypeSystem",
+            "org.apache.uima.ruta.ImportStatementsTestTypeSystemWithAmbiguousShortNames",
+            "org.apache.uima.ruta.ImportStatementsTestTypeSystemWithManyPackages");
     final AnalysisEngineDescription ruta = AnalysisEngineFactory.createEngineDescription(
-        "org.apache.uima.ruta.engine.BasicEngine",
-        RutaEngine.PARAM_MAIN_SCRIPT, script,
-        RutaEngine.PARAM_STRICT_IMPORTS, strictImport);
+            "org.apache.uima.ruta.engine.BasicEngine", RutaEngine.PARAM_MAIN_SCRIPT, script,
+            RutaEngine.PARAM_STRICT_IMPORTS, strictImport);
 
     ruta.getAnalysisEngineMetaData().setTypeSystem(tsd);
 
@@ -241,7 +253,8 @@ public class ImportStatementsTest {
 
   @Test
   public void testImportAllPackagesWithAliasFromTypeSystem() throws Exception {
-    AnalysisEngine ae = createAE(NAMESPACE + "/" + NAME + "ImportAllPackagesWithAliasFromTypeSystem", true);
+    AnalysisEngine ae = createAE(
+            NAMESPACE + "/" + NAME + "ImportAllPackagesWithAliasFromTypeSystem", true);
     try {
       CAS cas = ae.newCAS();
       cas.setDocumentText("First Second");
@@ -256,7 +269,9 @@ public class ImportStatementsTest {
 
   @Test
   public void testImportAllPackagesFromTypeSystemWithAmbiguousShortNames() throws Exception {
-    AnalysisEngine ae = createAE(NAMESPACE + "/" + NAME + "ImportAllPackagesFromTypeSystemWithAmbiguousShortNames", true);
+    AnalysisEngine ae = createAE(
+            NAMESPACE + "/" + NAME + "ImportAllPackagesFromTypeSystemWithAmbiguousShortNames",
+            true);
     try {
       CAS cas = ae.newCAS();
       cas.setDocumentText("First Second");
@@ -274,6 +289,38 @@ public class ImportStatementsTest {
     }
   }
 
+  @Test
+  @Ignore
+  public void testDeclareWithAliasParent() throws Exception {
+
+    String document = "This is a test.";
+    String script = "PACKAGE test.package;\n";
+    script += "IMPORT PACKAGE * FROM org.apache.uima.ruta.engine.PlainTextTypeSystem AS pt;\n";
+    script += "IMPORT org.apache.uima.ruta.type.Paragraph FROM org.apache.uima.ruta.engine.PlainTextTypeSystem AS Para;\n";
+    script += "DECLARE pt.Line SubLine;\n";
+    script += "DECLARE Para SubPara;\n";
+    script += "Document{-> SubLine, SubPara};\n";
+    script += "SubLine{-> TruePositive};";
+    script += "SubPara{-> FalsePositive};";
+
+    RutaDescriptorFactory factory = new RutaDescriptorFactory();
+    RutaDescriptorInformation descriptorInformation = factory.parseDescriptorInformation(script);
+    RutaBuildOptions options = new RutaBuildOptions();
+    Pair<AnalysisEngineDescription, TypeSystemDescription> descriptions = factory
+            .createDescriptions(null, null, descriptorInformation, options, null, null, null);
+
+    AnalysisEngineDescription analysisEngineDescription = descriptions.getKey();
+    AnalysisEngine analysisEngine = AnalysisEngineFactory.createEngine(analysisEngineDescription);
+
+    CAS cas = analysisEngine.newCAS();
+    cas.setDocumentText(document);
+
+    analysisEngine.process(cas);
+
+    Assert.assertEquals(1, JCasUtil.select(cas.getJCas(), TruePositive.class).size());
+    Assert.assertEquals(1, JCasUtil.select(cas.getJCas(), FalsePositive.class).size());
+  }
+
   private List<String> selectText(CAS cas, String type) {
     List<String> values = new ArrayList<String>();
     for (AnnotationFS annotation : CasUtil.select(cas, cas.getTypeSystem().getType(type))) {