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 2013/08/20 13:20:20 UTC
svn commit: r1515781 - in
/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta:
RutaEnvironment.java resource/CSVTable.java
Author: pkluegl
Date: Tue Aug 20 11:20:20 2013
New Revision: 1515781
URL: http://svn.apache.org/r1515781
Log:
UIMA-3194
- try to load tables from classpath
Modified:
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/CSVTable.java
Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java?rev=1515781&r1=1515780&r2=1515781&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java Tue Aug 20 11:20:20 2013
@@ -258,10 +258,26 @@ public class RutaEnvironment {
continue;
}
found = true;
- tables.put(table, new CSVTable(file.getAbsolutePath()));
+ try {
+ tables.put(table, new CSVTable(file.getAbsolutePath()));
+ } catch (IOException e) {
+ Logger.getLogger(this.getClass().getName()).log(Level.SEVERE,
+ "Error reading csv table " + table, e);
+ found = false;
+ }
break;
}
if (!found) {
+ InputStream stream = ClassLoader.getSystemResourceAsStream(table);
+ try {
+ tables.put(table, new CSVTable(stream));
+ } catch (IOException e) {
+ Logger.getLogger(this.getClass().getName()).log(Level.SEVERE,
+ "Error reading csv table " + table + " from classpath", e);
+ found = false;
+ }
+ }
+ if (!found) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Can't find " + table + "!");
}
}
Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/CSVTable.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/CSVTable.java?rev=1515781&r1=1515780&r2=1515781&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/CSVTable.java (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/CSVTable.java Tue Aug 20 11:20:20 2013
@@ -19,7 +19,11 @@
package org.apache.uima.ruta.resource;
+import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
@@ -33,21 +37,20 @@ public class CSVTable implements RutaTab
private List<List<String>> tableData;
- private Map<Integer, RutaWordList> columnWordLists;
+ private Map<Integer, RutaWordList> columnWordLists = new HashMap<Integer, RutaWordList>(2);
- public CSVTable(String location) {
- super();
- columnWordLists = new HashMap<Integer, RutaWordList>(2);
- try {
- buildTable(location);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ public CSVTable(String location) throws IOException {
+ this(new FileInputStream(new File(location)));
}
- private void buildTable(String location) throws Exception {
- FileInputStream in = new FileInputStream(location);
- Scanner sc = new Scanner(in, Charset.forName("UTF-8").name());
+ public CSVTable(InputStream stream) throws IOException {
+ super();
+ buildTable(stream);
+ }
+
+
+ private void buildTable(InputStream stream) {
+ Scanner sc = new Scanner(stream, Charset.forName("UTF-8").name());
sc.useDelimiter("\\n");
tableData = new ArrayList<List<String>>();
while (sc.hasNext()) {