Author: pkluegl
Date: Tue Jun  7 13:42:54 2016
New Revision: 1747233

URL: http://svn.apache.org/viewvc?rev=1747233&view=rev
Log:
UIMA-4833
- import type namespaces of imported script
- added test

Added:
    
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/StrictScript1.ruta
    
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/StrictScript2.ruta
Modified:
    
uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
    
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/StrictImportTest.java

Modified: 
uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g?rev=1747233&r1=1747232&r2=1747233&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
 Tue Jun  7 13:42:54 2016
@@ -265,6 +265,7 @@ public void setExternalFactory(RutaExter
        }
        public void addImportScript(RutaBlock parent, String namespace) {
                parent.getScript().addScript(namespace, null);
+               parent.getEnvironment().addScript(namespace);
                if(descInfo != null) {
                  descInfo.addScript(namespace);
                }

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=1747233&r1=1747232&r2=1747233&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
 Tue Jun  7 13:42:54 2016
@@ -35,6 +35,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.antlr.runtime.CommonToken;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.ImmutableTriple;
 import org.apache.commons.lang3.tuple.Triple;
 import org.apache.uima.UIMAFramework;
@@ -80,6 +81,8 @@ import org.springframework.core.io.Resou
 
 public class RutaEnvironment {
 
+  private static final String DOCUMENT = "Document";
+
   private final Object annotationTypeDummy = new Object();
 
   private Map<String, Type> types;
@@ -107,6 +110,11 @@ public class RutaEnvironment {
   private Set<String> typesystems;
 
   /**
+   * Set of imported scripts.
+   */
+  private Set<String> scripts;
+
+  /**
    * An alias from a long to a short name.
    */
   private static class Alias {
@@ -163,9 +171,8 @@ public class RutaEnvironment {
 
   private Map<String, String> variableAliases;
 
-  
   private RutaVerbalizer verbalizer = new RutaVerbalizer();
-  
+
   public RutaEnvironment(RutaBlock owner) {
     super();
     this.owner = owner;
@@ -174,6 +181,7 @@ public class RutaEnvironment {
     namespaces = new HashMap<String, String>();
     ambiguousTypeAlias = new HashMap<String, Set<String>>();
     typesystems = new HashSet<String>();
+    scripts = new HashSet<String>();
     typeImports = new HashMap<String, List<Alias>>();
     packageImports = new HashMap<String, List<String>>();
     declaredAnnotationTypes = new HashSet<String>();
@@ -214,7 +222,7 @@ public class RutaEnvironment {
     resourcePaths = getResourcePaths();
     initializedVariables = new HashMap<String, Object>();
     variableAliases = new HashMap<>();
-    
+
     // Always import BasicTypeSystem
     addTypeSystem("org.apache.uima.ruta.engine.BasicTypeSystem");
   }
@@ -235,6 +243,7 @@ public class RutaEnvironment {
         importDeclaredTypesystems(cas.getTypeSystem());
         importTypeAliases(cas.getTypeSystem());
         importPackageAliases(cas.getTypeSystem());
+        importDeclaredScripts(cas.getTypeSystem());
       } else {
         // import all types known to the cas
         importAllTypes(cas.getTypeSystem());
@@ -245,10 +254,10 @@ public class RutaEnvironment {
       // "Document" can be resolved to "uima.tcas.DocumentAnnotation" or
       // "org.apache.uima.ruta.type.Document",
       // we force it to the former
-      ambiguousTypeAlias.remove("Document");
-      namespaces.remove("Document");
+      ambiguousTypeAlias.remove(DOCUMENT);
+      namespaces.remove(DOCUMENT);
       Type documentType = 
cas.getTypeSystem().getType(UIMAConstants.TYPE_DOCUMENT);
-      addType("Document", documentType);
+      addType(DOCUMENT, documentType);
 
       Type annotationType = 
cas.getJCas().getCasType(org.apache.uima.jcas.tcas.Annotation.type);
       addType("Annotation", annotationType);
@@ -320,6 +329,33 @@ public class RutaEnvironment {
   }
 
   /**
+   * Import all already initialized types of imported scripts.
+   *
+   * @param casTS
+   *          Type system containing all known types.
+   * @throws InvalidXMLException
+   *           When import cannot be resolved.
+   */
+  private void importDeclaredScripts(TypeSystem casTS) throws 
InvalidXMLException {
+
+    RutaModule script = owner.getScript();
+    for (String eachImportedScript : scripts) {
+      RutaModule importedModule = script.getScript(eachImportedScript);
+      RutaEnvironment importedEnvironment = 
importedModule.getRootBlock().getEnvironment();
+      Map<String, Type> importedTypeMap = importedEnvironment.getTypes();
+      Map<String, String> importedNamespaces = 
importedEnvironment.getNamespaces();
+      Set<Entry<String, String>> entrySet = importedNamespaces.entrySet();
+      for (Entry<String, String> entry : entrySet) {
+        if (!ownsType(entry.getValue()) && !StringUtils.equals(entry.getKey(), 
DOCUMENT)) {
+          Type type = importedTypeMap.get(entry.getValue());
+          addType(entry.getKey(), type);
+        }
+      }
+      // TODO import also wordlists and variables?
+    }
+  }
+
+  /**
    * Imports all type aliases.
    *
    * @param casTS
@@ -391,9 +427,6 @@ public class RutaEnvironment {
         }
       } else {
         complete = string;
-        String[] split = complete.split("\\p{Punct}");
-        String name = split[split.length - 1];
-        importType(complete, name);
       }
     }
     return complete;
@@ -456,6 +489,16 @@ public class RutaEnvironment {
   }
 
   /**
+   * Add a script to the script.
+   *
+   * @param script
+   *          the script's full name.
+   */
+  public void addScript(String script) {
+    scripts.add(script);
+  }
+
+  /**
    * Import a type in the current namespace.
    *
    * @param longName
@@ -544,8 +587,8 @@ public class RutaEnvironment {
 
     for (TypeDescription td : tsd.getTypes()) {
       String qname = td.getName();
-      if (packageName == null
-              || (qname.startsWith(packageName) && qname.indexOf('.', 
packageName.length() + 1) == -1)) {
+      if (packageName == null || (qname.startsWith(packageName)
+              && qname.indexOf('.', packageName.length() + 1) == -1)) {
         // td is in packageName
         if (alias != null) {
           String shortName = alias + "." + 
qname.substring(qname.lastIndexOf('.') + 1);
@@ -643,8 +686,8 @@ public class RutaEnvironment {
                     "Error reading csv table " + table, e);
           }
         } else {
-          Logger.getLogger(this.getClass().getName())
-                  .log(Level.SEVERE, "Can't find " + table + "!");
+          Logger.getLogger(this.getClass().getName()).log(Level.SEVERE,
+                  "Can't find " + table + "!");
         }
       } else {
         try {
@@ -704,7 +747,7 @@ public class RutaEnvironment {
   public void addVariable(String name, String type) {
     addVariable(name, availableTypes.get(type), availableListTypes.get(type));
   }
-  
+
   public void removeVariable(String name) {
     variableTypes.remove(name);
     variableGenericTypes.remove(name);
@@ -716,7 +759,7 @@ public class RutaEnvironment {
   }
 
   public boolean ownsVariableOfType(String name, String type) {
-    if(variableAliases.containsKey(name)) {
+    if (variableAliases.containsKey(name)) {
       name = variableAliases.get(name);
     }
     Class<?> varclass = variableTypes.get(name);
@@ -731,7 +774,7 @@ public class RutaEnvironment {
   }
 
   public boolean isVariable(String name) {
-    if(variableAliases.containsKey(name)) {
+    if (variableAliases.containsKey(name)) {
       name = variableAliases.get(name);
     }
     if (ownsVariable(name)) {
@@ -744,13 +787,12 @@ public class RutaEnvironment {
   }
 
   public boolean isVariableOfType(String name, String type) {
-    return ownsVariableOfType(name, type)
-            || (owner.getParent() != null && owner.getParent().getEnvironment()
-                    .isVariableOfType(name, type));
+    return ownsVariableOfType(name, type) || (owner.getParent() != null
+            && owner.getParent().getEnvironment().isVariableOfType(name, 
type));
   }
 
   public Class<?> getVariableType(String name) {
-    if(variableAliases.containsKey(name)) {
+    if (variableAliases.containsKey(name)) {
       name = variableAliases.get(name);
     }
     Class<?> result = variableTypes.get(name);
@@ -773,7 +815,7 @@ public class RutaEnvironment {
   }
 
   public <T> T getVariableValue(String name, Class<T> type) {
-    if(variableAliases.containsKey(name)) {
+    if (variableAliases.containsKey(name)) {
       name = variableAliases.get(name);
     }
     boolean containsKey = variableValues.containsKey(name);
@@ -881,7 +923,7 @@ public class RutaEnvironment {
   }
 
   public void setVariableValue(String name, Object value) {
-    if(variableAliases.containsKey(name)) {
+    if (variableAliases.containsKey(name)) {
       name = variableAliases.get(name);
     }
     if (ownsVariable(name)) {
@@ -943,15 +985,18 @@ public class RutaEnvironment {
     this.resourceManager = resourceManager;
   }
 
-  public void addMacroAction(String name, Map<String, String> def, Set<String> 
vars, List<AbstractRutaAction> actions) {
-    macroActions.put(name, new ImmutableTriple<Map<String, String>, 
List<AbstractRutaAction>, Set<String>>(def,
-            actions, vars));
+  public void addMacroAction(String name, Map<String, String> def, Set<String> 
vars,
+          List<AbstractRutaAction> actions) {
+    macroActions.put(name,
+            new ImmutableTriple<Map<String, String>, List<AbstractRutaAction>, 
Set<String>>(def,
+                    actions, vars));
   }
 
-  public void addMacroCondition(String name, Map<String, String> def,
-          Set<String> vars, List<AbstractRutaCondition> conditions) {
-    macroConditions.put(name, new ImmutableTriple<Map<String, String>, 
List<AbstractRutaCondition>, Set<String>>(
-            def, conditions, vars));
+  public void addMacroCondition(String name, Map<String, String> def, 
Set<String> vars,
+          List<AbstractRutaCondition> conditions) {
+    macroConditions.put(name,
+            new ImmutableTriple<Map<String, String>, 
List<AbstractRutaCondition>, Set<String>>(def,
+                    conditions, vars));
   }
 
   public boolean isMacroAction(String name) {
@@ -962,11 +1007,13 @@ public class RutaEnvironment {
     return macroConditions.keySet().contains(name);
   }
 
-  public Triple<Map<String, String>, List<AbstractRutaAction>, Set<String>> 
getMacroAction(String name) {
+  public Triple<Map<String, String>, List<AbstractRutaAction>, Set<String>> 
getMacroAction(
+          String name) {
     return macroActions.get(name);
   }
 
-  public Triple<Map<String, String>, List<AbstractRutaCondition>, Set<String>> 
getMacroCondition(String name) {
+  public Triple<Map<String, String>, List<AbstractRutaCondition>, Set<String>> 
getMacroCondition(
+          String name) {
     return macroConditions.get(name);
   }
 
@@ -982,4 +1029,21 @@ public class RutaEnvironment {
     String verbalize = verbalizer.verbalize(expression);
     return verbalize;
   }
+
+  public Map<String, Type> getTypes() {
+    return types;
+  }
+
+  public Set<String> getDeclaredAnnotationTypes() {
+    return declaredAnnotationTypes;
+  }
+
+  public Set<String> getTypesystems() {
+    return typesystems;
+  }
+
+  public Map<String, String> getNamespaces() {
+    return namespaces;
+  }
+
 }

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java?rev=1747233&r1=1747232&r2=1747233&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
 Tue Jun  7 13:42:54 2016
@@ -31,6 +31,7 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 
 import org.antlr.runtime.ANTLRFileStream;
@@ -231,7 +232,8 @@ public class RutaEngine extends JCasAnno
    */
   public static final String PARAM_SEEDERS = "seeders";
 
-  @ConfigurationParameter(name = PARAM_SEEDERS, mandatory = false, 
defaultValue = { "org.apache.uima.ruta.seed.DefaultSeeder" })
+  @ConfigurationParameter(name = PARAM_SEEDERS, mandatory = false, 
defaultValue = {
+      "org.apache.uima.ruta.seed.DefaultSeeder" })
   private String[] seeders;
 
   /**
@@ -407,17 +409,17 @@ public class RutaEngine extends JCasAnno
   private String[] varValues;
 
   /**
-   * This parameter specifies the annotation types which should be reindex for 
ruta's internal annotations
-   * All annotation types that changed since the last call of a ruta script 
need to be listed here. 
-   * The value of this parameter needs only be adapted for performance 
optimization in pipelines that 
-   * contains several ruta analysis engines.
-   * Default value is uima.tcas.Annotation
+   * This parameter specifies the annotation types which should be reindex for 
ruta's internal
+   * annotations All annotation types that changed since the last call of a 
ruta script need to be
+   * listed here. The value of this parameter needs only be adapted for 
performance optimization in
+   * pipelines that contains several ruta analysis engines. Default value is 
uima.tcas.Annotation
    */
   public static final String PARAM_REINDEX_ONLY = "reindexOnly";
 
-  @ConfigurationParameter(name = PARAM_REINDEX_ONLY, mandatory = false, 
defaultValue = {"uima.tcas.Annotation"})
+  @ConfigurationParameter(name = PARAM_REINDEX_ONLY, mandatory = false, 
defaultValue = {
+      "uima.tcas.Annotation" })
   private String[] reindexOnly;
-  
+
   private UimaContext context;
 
   private RutaModule script;
@@ -438,7 +440,6 @@ public class RutaEngine extends JCasAnno
 
   private ResourceManager resourceManager = null;
 
-
   @Override
   public void initialize(UimaContext aContext) throws 
ResourceInitializationException {
     super.initialize(aContext);
@@ -512,7 +513,7 @@ public class RutaEngine extends JCasAnno
 
       // reinitialize analysis engines if this one is configured
       analysisEnginesAlreadyInitialized = false;
-      
+
       resourceManager = UIMAFramework.newDefaultResourceManager();
       String dataPath = "";
       if (descriptorPaths != null) {
@@ -554,7 +555,7 @@ public class RutaEngine extends JCasAnno
     }
     boolean typeSystemChanged = lastTypeSystem != cas.getTypeSystem();
     if (!initialized || reloadScript || typeSystemChanged) {
-      initializeTypes(script, cas);
+      initializeTypes(script, cas, new ArrayList<String>());
       initialized = true;
       lastTypeSystem = cas.getTypeSystem();
     }
@@ -607,15 +608,21 @@ public class RutaEngine extends JCasAnno
     }
   }
 
-  private void initializeTypes(RutaModule script, CAS cas) {
+  private void initializeTypes(RutaModule script, CAS cas, List<String> 
initialized) {
     // TODO find a better solution for telling everyone about the types!
     RutaBlock mainRootBlock = script.getBlock(null);
-    mainRootBlock.getEnvironment().initializeTypes(cas, strictImports);
-    Collection<RutaModule> values = script.getScripts().values();
-    for (RutaModule eachModule : values) {
-      relinkEnvironments(eachModule, mainRootBlock, new 
ArrayList<RutaModule>());
-      initializeTypes(eachModule, cas);
+    Collection<Entry<String, RutaModule>> values = 
script.getScripts().entrySet();
+    for (Entry<String, RutaModule> eachImport : values) {
+      String name = eachImport.getKey();
+      if (!initialized.contains(name)) {
+        RutaModule eachModule = eachImport.getValue();
+        relinkEnvironments(eachModule, mainRootBlock, new 
ArrayList<RutaModule>());
+        initializeTypes(eachModule, cas, initialized);
+        initialized.add(name);
+      }
     }
+    mainRootBlock.getEnvironment().initializeTypes(cas, strictImports);
+
   }
 
   private void relinkEnvironments(RutaModule script, RutaBlock mainRootBlock,
@@ -673,8 +680,8 @@ public class RutaEngine extends JCasAnno
   private InferenceCrowd initializeCrowd() {
     List<RutaInferenceVisitor> visitors = new 
ArrayList<RutaInferenceVisitor>();
     if (debug) {
-      visitors.add(new DebugInfoCollectorVisitor(debug, debugWithMatches, 
Arrays
-              .asList(debugOnlyFor), verbalizer));
+      visitors.add(new DebugInfoCollectorVisitor(debug, debugWithMatches,
+              Arrays.asList(debugOnlyFor), verbalizer));
     }
     if (profile) {
       visitors.add(new TimeProfilerVisitor());
@@ -749,12 +756,12 @@ public class RutaEngine extends JCasAnno
           String mainScriptPath = mainScript.replaceAll("\\.", "/") + 
SCRIPT_FILE_EXTENSION;
           script = loadScriptIS(mainScriptPath);
         } catch (IOException e) {
-          throw new AnalysisEngineProcessException(new 
FileNotFoundException("Script ["
-                  + mainScript + "] cannot be found at [" + 
collectionToString(scriptPaths)
+          throw new AnalysisEngineProcessException(new 
FileNotFoundException("Script [" + mainScript
+                  + "] cannot be found at [" + collectionToString(scriptPaths)
                   + "] or classpath with extension .ruta"));
         } catch (RecognitionException e) {
-          throw new AnalysisEngineProcessException(new 
FileNotFoundException("Script ["
-                  + mainScript + "] cannot be found at [" + 
collectionToString(scriptPaths)
+          throw new AnalysisEngineProcessException(new 
FileNotFoundException("Script [" + mainScript
+                  + "] cannot be found at [" + collectionToString(scriptPaths)
                   + "] or classpath  with extension .ruta"));
         }
       } else {
@@ -799,7 +806,8 @@ public class RutaEngine extends JCasAnno
           additionalEnginesMap.put(classString, eachEngine);
           String[] eachEngineLocationPartArray = classString.split("\\.");
           if (eachEngineLocationPartArray.length > 1) {
-            String shortEachEngineLocation = 
eachEngineLocationPartArray[eachEngineLocationPartArray.length - 1];
+            String shortEachEngineLocation = 
eachEngineLocationPartArray[eachEngineLocationPartArray.length
+                    - 1];
             additionalEnginesMap.put(shortEachEngineLocation, eachEngine);
           }
         } catch (Exception e) {
@@ -816,23 +824,23 @@ public class RutaEngine extends JCasAnno
           try {
             eachEngine = engineLoader.loadEngineIS(locationIS, viewName);
           } catch (InvalidXMLException e) {
-            throw new AnalysisEngineProcessException(new 
FileNotFoundException("Engine at ["
-                    + eachEngineLocation + "] cannot be found in ["
-                    + collectionToString(descriptorPaths)
-                    + "] with extension .xml (from mainScript=" + mainScript + 
" in "
-                    + collectionToString(scriptPaths)));
+            throw new AnalysisEngineProcessException(
+                    new FileNotFoundException("Engine at [" + 
eachEngineLocation
+                            + "] cannot be found in [" + 
collectionToString(descriptorPaths)
+                            + "] with extension .xml (from mainScript=" + 
mainScript + " in "
+                            + collectionToString(scriptPaths)));
           } catch (ResourceInitializationException e) {
-            throw new AnalysisEngineProcessException(new 
FileNotFoundException("Engine at ["
-                    + eachEngineLocation + "] cannot be found in ["
-                    + collectionToString(descriptorPaths)
-                    + "] with extension .xml (from mainScript=" + mainScript + 
" in "
-                    + collectionToString(scriptPaths)));
+            throw new AnalysisEngineProcessException(
+                    new FileNotFoundException("Engine at [" + 
eachEngineLocation
+                            + "] cannot be found in [" + 
collectionToString(descriptorPaths)
+                            + "] with extension .xml (from mainScript=" + 
mainScript + " in "
+                            + collectionToString(scriptPaths)));
           } catch (IOException e) {
-            throw new AnalysisEngineProcessException(new 
FileNotFoundException("Engine at ["
-                    + eachEngineLocation + "] cannot be found in ["
-                    + collectionToString(descriptorPaths)
-                    + "] with extension .xml (from mainScript=" + mainScript + 
" in "
-                    + collectionToString(scriptPaths)));
+            throw new AnalysisEngineProcessException(
+                    new FileNotFoundException("Engine at [" + 
eachEngineLocation
+                            + "] cannot be found in [" + 
collectionToString(descriptorPaths)
+                            + "] with extension .xml (from mainScript=" + 
mainScript + " in "
+                            + collectionToString(scriptPaths)));
           } catch (ResourceConfigurationException e) {
             throw new AnalysisEngineProcessException(e);
           } catch (URISyntaxException e) {
@@ -849,7 +857,8 @@ public class RutaEngine extends JCasAnno
           additionalEnginesMap.put(eachEngineLocation, eachEngine);
           String[] eachEngineLocationPartArray = 
eachEngineLocation.split("\\.");
           if (eachEngineLocationPartArray.length > 1) {
-            String shortEachEngineLocation = 
eachEngineLocationPartArray[eachEngineLocationPartArray.length - 1];
+            String shortEachEngineLocation = 
eachEngineLocationPartArray[eachEngineLocationPartArray.length
+                    - 1];
             additionalEnginesMap.put(shortEachEngineLocation, eachEngine);
           }
         } catch (Exception e) {
@@ -865,7 +874,7 @@ public class RutaEngine extends JCasAnno
     }
 
     analysisEnginesAlreadyInitialized = true;
-    
+
     for (RutaModule each : additionalScriptsMap.values()) {
       each.setScriptDependencies(additionalScriptsMap);
     }
@@ -1000,25 +1009,25 @@ public class RutaEngine extends JCasAnno
         String scriptPath = toLoad.replaceAll("\\.", "/") + 
SCRIPT_FILE_EXTENSION;
         eachScript = loadScriptIS(scriptPath);
       } catch (IOException e) {
-        throw new AnalysisEngineProcessException(new 
FileNotFoundException("Script [" + toLoad
-                + "] cannot be found at [" + collectionToString(scriptPaths)
-                + "] with extension .ruta"));
+        throw new AnalysisEngineProcessException(
+                new FileNotFoundException("Script [" + toLoad + "] cannot be 
found at ["
+                        + collectionToString(scriptPaths) + "] with extension 
.ruta"));
       } catch (RecognitionException e) {
-        throw new AnalysisEngineProcessException(new 
FileNotFoundException("Script [" + toLoad
-                + "] cannot be found at [" + collectionToString(scriptPaths)
-                + "] with extension .ruta"));
+        throw new AnalysisEngineProcessException(
+                new FileNotFoundException("Script [" + toLoad + "] cannot be 
found at ["
+                        + collectionToString(scriptPaths) + "] with extension 
.ruta"));
       }
     } else {
       try {
         eachScript = loadScript(location);
       } catch (IOException e) {
-        throw new AnalysisEngineProcessException(new 
FileNotFoundException("Script [" + toLoad
-                + "] cannot be found at [" + collectionToString(scriptPaths)
-                + "] with extension .ruta"));
+        throw new AnalysisEngineProcessException(
+                new FileNotFoundException("Script [" + toLoad + "] cannot be 
found at ["
+                        + collectionToString(scriptPaths) + "] with extension 
.ruta"));
       } catch (RecognitionException e) {
-        throw new AnalysisEngineProcessException(new 
FileNotFoundException("Script [" + toLoad
-                + "] cannot be found at [" + collectionToString(scriptPaths)
-                + "] with extension .ruta"));
+        throw new AnalysisEngineProcessException(
+                new FileNotFoundException("Script [" + toLoad + "] cannot be 
found at ["
+                        + collectionToString(scriptPaths) + "] with extension 
.ruta"));
       }
     }
     additionalScripts.put(toLoad, eachScript);

Modified: 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/StrictImportTest.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/StrictImportTest.java?rev=1747233&r1=1747232&r2=1747233&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/StrictImportTest.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/StrictImportTest.java
 Tue Jun  7 13:42:54 2016
@@ -25,12 +25,15 @@ import static org.junit.Assert.fail;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.uima.analysis_engine.AnalysisEngine;
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.fit.factory.AnalysisEngineFactory;
 import org.apache.uima.fit.factory.TypeSystemDescriptionFactory;
@@ -38,9 +41,12 @@ import org.apache.uima.fit.util.CasUtil;
 import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.resource.metadata.TypeSystemDescription;
 import org.apache.uima.ruta.engine.RutaEngine;
+import org.apache.uima.ruta.engine.RutaTestUtils;
 import org.apache.uima.util.InvalidXMLException;
+import org.junit.Assert;
 import org.junit.Test;
 
+
 /**
  * Test the strict import option of {@link 
org.apache.uima.ruta.engine.RutaEngine}.
  */
@@ -134,4 +140,32 @@ public class StrictImportTest {
 
     return values;
   }
+  
+  @Test
+  public void testStrictScriptImport() throws ResourceInitializationException, 
InvalidXMLException, IOException, AnalysisEngineProcessException {
+    Map<String, String> complexTypes = new HashMap<>();
+    String s1 = "org.apache.uima.ruta.StrictScript2.Type1";
+    String s2 = "org.apache.uima.ruta.other.Type1";
+    complexTypes.put(s1, "uima.tcas.Annotation");
+    complexTypes.put(s2, "uima.tcas.Annotation");
+    
+    CAS cas = RutaTestUtils.getCAS("Some text.", complexTypes, null);
+    
+    AnalysisEngine ae = AnalysisEngineFactory.createEngine(RutaEngine.class, 
+            RutaEngine.PARAM_MAIN_SCRIPT, "org.apache.uima.ruta.StrictScript1",
+            RutaEngine.PARAM_ADDITIONAL_SCRIPTS, 
"org.apache.uima.ruta.StrictScript2",
+            RutaEngine.PARAM_STRICT_IMPORTS, true
+            );
+    ae.process(cas);
+    
+    Type t1 = cas.getTypeSystem().getType(s1);
+    Type t2 = cas.getTypeSystem().getType(s2);
+    
+    Assert.assertEquals(1, cas.getAnnotationIndex(t1).size());
+    Assert.assertEquals(1, cas.getAnnotationIndex(t2).size());
+    
+    cas.release();
+  }
+  
+  
 }
\ No newline at end of file

Added: 
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/StrictScript1.ruta
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/StrictScript1.ruta?rev=1747233&view=auto
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/StrictScript1.ruta
 (added)
+++ 
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/StrictScript1.ruta
 Tue Jun  7 13:42:54 2016
@@ -0,0 +1,8 @@
+PACKAGE org.apache.uima.ruta;
+SCRIPT org.apache.uima.ruta.StrictScript2;
+
+CW{-> Type1};
+CW{-> OtherType};
+
+
+

Added: 
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/StrictScript2.ruta
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/StrictScript2.ruta?rev=1747233&view=auto
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/StrictScript2.ruta
 (added)
+++ 
uima/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/StrictScript2.ruta
 Tue Jun  7 13:42:54 2016
@@ -0,0 +1,5 @@
+PACKAGE org.apache.uima.ruta;
+
+IMPORT org.apache.uima.ruta.other.Type1 FROM 
org.apache.uima.ruta.ImportStatementsTestTypeSystem AS OtherType;
+
+DECLARE Type1;
\ No newline at end of file


Reply via email to