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 2015/04/08 11:19:59 UTC
svn commit: r1672043 - in
/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta:
RutaEnvironment.java descriptor/RutaDescriptorBuilder.java
Author: pkluegl
Date: Wed Apr 8 09:19:59 2015
New Revision: 1672043
URL: http://svn.apache.org/r1672043
Log:
UIMA-3650
- do not load word lists while parsing
- fixed type system of imported script classpath lookup
Modified:
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/descriptor/RutaDescriptorBuilder.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=1672043&r1=1672042&r2=1672043&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 Wed Apr 8 09:19:59 2015
@@ -36,6 +36,7 @@ import java.util.logging.Logger;
import org.antlr.runtime.CommonToken;
import org.apache.uima.UIMAFramework;
+import org.apache.uima.UimaContext;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASException;
import org.apache.uima.cas.Type;
@@ -57,6 +58,8 @@ import org.apache.uima.ruta.expression.l
import org.apache.uima.ruta.expression.number.INumberExpression;
import org.apache.uima.ruta.expression.resource.LiteralWordListExpression;
import org.apache.uima.ruta.expression.resource.LiteralWordTableExpression;
+import org.apache.uima.ruta.expression.resource.WordListExpression;
+import org.apache.uima.ruta.expression.resource.WordTableExpression;
import org.apache.uima.ruta.expression.string.IStringExpression;
import org.apache.uima.ruta.expression.type.SimpleTypeExpression;
import org.apache.uima.ruta.resource.CSVTable;
@@ -147,7 +150,7 @@ public class RutaEnvironment {
private Map<String, Object> initializedVariables;
private ResourceManager resourceManager;
-
+
public RutaEnvironment(RutaBlock owner) {
super();
this.owner = owner;
@@ -563,9 +566,14 @@ public class RutaEnvironment {
public RutaWordList getWordList(String list) {
RutaWordList result = wordLists.get(list);
- Boolean dictRemoveWS = (Boolean) owner.getContext().getConfigParameterValue(RutaEngine.PARAM_DICT_REMOVE_WS);
- if(dictRemoveWS == null) {
- dictRemoveWS = false;
+ UimaContext context = owner.getContext();
+ Boolean dictRemoveWS = false;
+ if (context != null) {
+ dictRemoveWS = (Boolean) context
+ .getConfigParameterValue(RutaEngine.PARAM_DICT_REMOVE_WS);
+ if (dictRemoveWS == null) {
+ dictRemoveWS = false;
+ }
}
if (result == null) {
if (list.endsWith("txt") || list.endsWith("twl") || list.endsWith("mtwl")) {
@@ -587,7 +595,7 @@ public class RutaEnvironment {
}
} else {
try {
- RutaWordList rutaTable = (RutaWordList) owner.getContext().getResourceObject(list);
+ RutaWordList rutaTable = (RutaWordList) context.getResourceObject(list);
wordLists.put(list, rutaTable);
} catch (ResourceAccessException e) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE,
@@ -740,7 +748,17 @@ public class RutaEnvironment {
return type.cast(cas.getAnnotationType());
}
if (result != null) {
- return type.cast(result);
+ if(RutaWordList.class.isAssignableFrom(type) && result instanceof WordListExpression) {
+ WordListExpression wle = (WordListExpression) result;
+ RutaWordList list = wle.getList(owner);
+ return type.cast(list);
+ } else if(RutaTable.class.isAssignableFrom(type) && result instanceof WordTableExpression) {
+ WordTableExpression wte = (WordTableExpression) result;
+ RutaTable table = wte.getTable(owner);
+ return type.cast(table);
+ } else {
+ return type.cast(result);
+ }
} else if (owner.getParent() != null) {
return owner.getParent().getEnvironment().getVariableValue(name, type);
}
@@ -774,23 +792,13 @@ public class RutaEnvironment {
return be.getBooleanValue(owner, null, null);
}
if (clazz.equals(RutaWordList.class) && value instanceof LiteralWordListExpression) {
- LiteralWordListExpression lle = (LiteralWordListExpression) value;
- String path = lle.getText();
- RutaWordList wordList = getWordList(path);
- return wordList;
+ return value;
} else if (clazz.equals(RutaWordList.class) && value instanceof String) {
- // TODO: ExtenralWordListExpression will be ignored
- RutaWordList list = getWordList((String) value);
- return list;
+ return value;
} else if (clazz.equals(RutaTable.class) && value instanceof LiteralWordTableExpression) {
- LiteralWordTableExpression lte = (LiteralWordTableExpression) value;
- String path = lte.getText();
- RutaTable table = getWordTable(path);
- return table;
- } else if (clazz.equals(RutaTable.class) && value instanceof String) {
- // TODO: ExtenralWordTableExpression will be ignored, and add a method like for word lists
- RutaTable table = getWordTable((String) value);
- return table;
+ return value;
+ } else if (clazz.equals(RutaTable.class) && value instanceof String) {
+ return value;
} else if (clazz.equals(List.class) && value instanceof ListExpression) {
List list = getList((ListExpression) value);
return list;
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorBuilder.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorBuilder.java?rev=1672043&r1=1672042&r2=1672043&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorBuilder.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorBuilder.java Wed Apr 8 09:19:59 2015
@@ -145,7 +145,7 @@ public class RutaDescriptorBuilder {
url = file.toURI().toURL();
}
if (url == null) {
- url = checkImportExistence(eachName, "xml", classloader);
+ url = checkImportExistence(eachName, ".xml", classloader);
include = true;
if (url == null) {
throw new FileNotFoundException("Build process can't find " + eachName + " in "
@@ -193,7 +193,7 @@ public class RutaDescriptorBuilder {
url = file.toURI().toURL();
}
if (url == null) {
- url = checkImportExistence(eachName, "xml", classloader);
+ url = checkImportExistence(eachName, "TypeSystem.xml", classloader);
if (url == null) {
throw new FileNotFoundException("Build process can't find " + eachName + " in "
+ desc.getScriptName());
@@ -552,7 +552,7 @@ public class RutaDescriptorBuilder {
public static URL checkImportExistence(String candidate, String extension, ClassLoader classloader)
throws IOException {
String p = candidate.replaceAll("[.]", "/");
- p += "." + extension;
+ p += extension;
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(
classloader);
String prefix = "classpath*:";