You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ap...@apache.org on 2014/02/02 02:21:58 UTC

svn commit: r1563536 - in /uima/ruta/trunk/ruta-core/src: main/java/org/apache/uima/ruta/RutaEnvironment.java test/java/org/apache/uima/ruta/ImportStatementsTest.java test/resources/org/apache/uima/ruta/ImportStatementsTestImportPackageAs.ruta

Author: apatry
Date: Sun Feb  2 01:21:58 2014
New Revision: 1563536

URL: http://svn.apache.org/r1563536
Log:
UIMA-3303 Import package aliases when strictMode is off

Added:
    uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ImportStatementsTestImportPackageAs.ruta
Modified:
    uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
    uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ImportStatementsTest.java

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java?rev=1563536&r1=1563535&r2=1563536&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java Sun Feb  2 01:21:58 2014
@@ -182,11 +182,12 @@ public class RutaEnvironment {
     try {
       if (strictImport) {
         importDeclaredTypes(cas.getTypeSystem());
-        importDeclaredPackages(cas.getTypeSystem());
+        importPackageAliases(cas.getTypeSystem());
       } else {
         // import all types known to the cas
         importAllTypes(cas.getTypeSystem());
         importTypeAliases(cas.getTypeSystem());
+        importPackageAliases(cas.getTypeSystem());
       }
 
       // "Document" can be resolved to "uima.tcas.DocumentAnnotation" or "org.apache.uima.ruta.type.Document",
@@ -228,17 +229,13 @@ public class RutaEnvironment {
    * @param casTS Cas type system.
    */
   private void importTypeAliases(TypeSystem casTS) {
-    // Add types that are imported explicitly
     for (List<Alias> aliases : typeImports.values()) {
       for (Alias alias : aliases) {
-        if (!alias.shortName.equals(alias.longName)) {
-          // we only import aliases
-          Type type = casTS.getType(alias.longName);
-          if (type == null) {
-            throw new RuntimeException("Type '" + alias.longName + "' not found");
-          }
-          addType(alias.shortName, casTS.getType(alias.longName));
+        Type type = casTS.getType(alias.longName);
+        if (type == null) {
+          throw new RuntimeException("Type '" + alias.longName + "' not found");
         }
+        addType(alias.shortName, casTS.getType(alias.longName));
       }
     }
   }
@@ -264,15 +261,7 @@ public class RutaEnvironment {
     }
 
     // Add types that are imported explicitly
-    for (List<Alias> aliases : typeImports.values()) {
-      for (Alias alias : aliases) {
-        Type type = casTS.getType(alias.longName);
-        if (type == null) {
-          throw new RuntimeException("Type '" + alias.longName + "' not found");
-        }
-        addType(alias.shortName, casTS.getType(alias.longName));
-      }
-    }
+    importTypeAliases(casTS);
 
     // Add declared types
     for (String name : declaredAnnotationTypes) {
@@ -290,7 +279,7 @@ public class RutaEnvironment {
    *
    * @param casTS Type system containing all known types.
    */
-  private void importDeclaredPackages(TypeSystem casTS) {
+  private void importPackageAliases(TypeSystem casTS) {
     Iterator<Type> iter = casTS.getTypeIterator();
     while(iter.hasNext()) {
       Type type = iter.next();

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=1563536&r1=1563535&r2=1563536&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 Sun Feb  2 01:21:58 2014
@@ -195,6 +195,21 @@ public class ImportStatementsTest {
   }
 
   @Test
+  public void testImportPackageAsWhenStrictModeIsOff() throws Exception {
+    AnalysisEngine ae = createAE(NAMESPACE + "/" + NAME + "ImportPackageAs", false);
+    try {
+      CAS cas = ae.newCAS();
+      cas.setDocumentText("First Second");
+      ae.process(cas);
+
+      assertEquals(Arrays.asList("First"), selectText(cas, "org.apache.uima.ruta.Type1"));
+      assertEquals(Arrays.asList("Second"), selectText(cas, "org.apache.uima.ruta.Type2"));
+    } finally {
+      ae.destroy();
+    }
+  }
+
+  @Test
   public void testImportPackageFromCasTypeSystem() throws Exception {
     AnalysisEngine ae = createAE(NAMESPACE + "/" + NAME + "ImportPackageFromCasTypeSystem", true);
     try {

Added: uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ImportStatementsTestImportPackageAs.ruta
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ImportStatementsTestImportPackageAs.ruta?rev=1563536&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ImportStatementsTestImportPackageAs.ruta (added)
+++ uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ImportStatementsTestImportPackageAs.ruta Sun Feb  2 01:21:58 2014
@@ -0,0 +1,6 @@
+PACKAGE org.apache.uima.ruta;
+
+IMPORT PACKAGE org.apache.uima.ruta AS pkg;
+
+W{REGEXP("First") -> MARK(pkg.Type1)};
+W{REGEXP("Second") -> MARK(pkg.Type2)};
\ No newline at end of file