use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.
the class ARFFTableTest method testCreateDataTableSpecFromARFFfileIRIS_BAR.
/**
* test the creation of a table spec from the IRIS data in an ARFF file.
* (With the nominal value list not separated with a space)
* @throws IOException if it wants to.
* @throws InvalidSettingsException if it feels like.
*/
public void testCreateDataTableSpecFromARFFfileIRIS_BAR() throws IOException, InvalidSettingsException {
File tempFile = File.createTempFile("ARFFReaderUnitTest", "mini");
tempFile.deleteOnExit();
Writer out = new BufferedWriter(new FileWriter(tempFile));
out.write(ARFF_IRISFULL_BAR);
out.close();
try {
DataTableSpec tSpec = ARFFTable.createDataTableSpecFromARFFfile(tempFile.toURI().toURL(), null);
// + "% The lovely Iris data set - as we all know it\n"
// + "\n"
// + "@RELATION iris\n"
// + "\n"
// + "@ATTRIBUTE sepallength REAL\n"
// + "@ATTRIBUTE sepalwidth REAL\n"
// + "@ATTRIBUTE petallength REAL\n"
// + "@ATTRIBUTE petalwidth REAL\n"
// + "@ATTRIBUTE class{Iris-setosa,Iris-versicolor,Iris-virginica}\n"
// + "\n"
assertEquals(tSpec.getNumColumns(), 5);
assertEquals(tSpec.getColumnSpec(0).getName().toString(), "sepallength");
assertEquals(tSpec.getColumnSpec(1).getName().toString(), "sepalwidth");
assertEquals(tSpec.getColumnSpec(2).getName().toString(), "petallength");
assertEquals(tSpec.getColumnSpec(3).getName().toString(), "petalwidth");
assertEquals(tSpec.getColumnSpec(4).getName().toString(), "class");
assertEquals(tSpec.getColumnSpec(0).getType(), DoubleCell.TYPE);
assertEquals(tSpec.getColumnSpec(1).getType(), DoubleCell.TYPE);
assertEquals(tSpec.getColumnSpec(2).getType(), DoubleCell.TYPE);
assertEquals(tSpec.getColumnSpec(3).getType(), DoubleCell.TYPE);
assertEquals(tSpec.getColumnSpec(4).getType(), StringCell.TYPE);
assertNull(tSpec.getColumnSpec(0).getDomain().getValues());
assertNull(tSpec.getColumnSpec(1).getDomain().getValues());
assertNull(tSpec.getColumnSpec(2).getDomain().getValues());
assertNull(tSpec.getColumnSpec(3).getDomain().getValues());
assertEquals(tSpec.getColumnSpec(4).getDomain().getValues().size(), 3);
Set<DataCell> vals = tSpec.getColumnSpec(4).getDomain().getValues();
assertTrue(vals.contains(new StringCell("Iris-setosa")));
assertTrue(vals.contains(new StringCell("Iris-versicolor")));
assertTrue(vals.contains(new StringCell("Iris-virginica")));
} catch (CanceledExecutionException cee) {
// no chance to end up here.
}
}
use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.
the class ARFFTableTest method DISABLEDtestCreateDataTableSpecFromARFFfileIRISCMT.
/**
* test the creation of a table spec from the IRIS data in an ARFF file.
*
* @throws IOException if it wants to.
* @throws InvalidSettingsException if it feels like.
*/
// disabled as part of bug 3235
public void DISABLEDtestCreateDataTableSpecFromARFFfileIRISCMT() throws IOException, InvalidSettingsException {
File tempFile = File.createTempFile("ARFFReaderUnitTest", "mini");
tempFile.deleteOnExit();
Writer out = new BufferedWriter(new FileWriter(tempFile));
out.write(ARFF_IRISFULL_CMT);
out.close();
try {
DataTableSpec tSpec = ARFFTable.createDataTableSpecFromARFFfile(tempFile.toURI().toURL(), null);
// + "% The lovely Iris data set - as we all know it\n"
// + "\n"
// + "@RELATION iris\n"
// + "\n"
// + "@ATTRIBUTE sepallength REAL % !comment\n"
// + "@ATTRIBUTE sepalwidth REAL\n"
// + "@ATTRIBUTE petallength REAL % =Type0\n"
// + "@ATTRIBUTE petalwidth REAL\n"
// + "@ATTRIBUTE class{Iris-setosa,Iris-versicolor,Iris-virginica}\n"
// + "\n"
assertEquals(tSpec.getNumColumns(), 5);
assertEquals(tSpec.getColumnSpec(0).getName().toString(), "sepallength");
assertEquals(tSpec.getColumnSpec(1).getName().toString(), "sepalwidth");
assertEquals(tSpec.getColumnSpec(2).getName().toString(), "petallength");
assertEquals(tSpec.getColumnSpec(3).getName().toString(), "petalwidth");
assertEquals(tSpec.getColumnSpec(4).getName().toString(), "class");
assertEquals(tSpec.getColumnSpec(0).getType(), DoubleCell.TYPE);
assertEquals(tSpec.getColumnSpec(1).getType(), DoubleCell.TYPE);
assertEquals(tSpec.getColumnSpec(2).getType(), DoubleCell.TYPE);
assertEquals(tSpec.getColumnSpec(3).getType(), DoubleCell.TYPE);
assertEquals(tSpec.getColumnSpec(4).getType(), StringCell.TYPE);
assertNull(tSpec.getColumnSpec(0).getDomain().getValues());
assertNull(tSpec.getColumnSpec(1).getDomain().getValues());
assertNull(tSpec.getColumnSpec(2).getDomain().getValues());
assertNull(tSpec.getColumnSpec(3).getDomain().getValues());
assertEquals(tSpec.getColumnSpec(4).getDomain().getValues().size(), 3);
Set<DataCell> vals = tSpec.getColumnSpec(4).getDomain().getValues();
assertTrue(vals.contains(new StringCell("Iris-setosa")));
assertTrue(vals.contains(new StringCell("Iris-versicolor")));
assertTrue(vals.contains(new StringCell("Iris-virginica")));
} catch (CanceledExecutionException cee) {
// no chance to end up here.
}
}
use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.
the class ConditionalBoxPlotNodeModel method loadInternals.
/**
* {@inheritDoc}
*/
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
try {
File f = new File(nodeInternDir, "conditionalBoxPlotInternals");
FileInputStream fis = new FileInputStream(f);
NodeSettingsRO settings = NodeSettings.loadFromXML(fis);
fis.close();
m_statistics = new LinkedHashMap<DataColumnSpec, double[]>();
m_mildOutliers = new LinkedHashMap<String, Map<Double, Set<RowKey>>>();
m_extremeOutliers = new LinkedHashMap<String, Map<Double, Set<RowKey>>>();
/* Load the numerical column spec if available.*/
if (settings.containsKey("numColSpec")) {
m_numColSpec = DataColumnSpec.load(settings.getConfig("numColSpec"));
}
int nrOfCols = settings.getInt("nrOfCols");
for (int i = 0; i < nrOfCols; i++) {
DataColumnSpec spec = DataColumnSpec.load(settings.getConfig("col" + i));
String colName = spec.getName();
double[] stats = settings.getDoubleArray("stats" + colName);
m_statistics.put(spec, stats);
double[] mild = settings.getDoubleArray("mild" + colName);
Map<Double, Set<RowKey>> mildmap = new LinkedHashMap<Double, Set<RowKey>>();
for (int j = 0; j < mild.length; j++) {
Set<RowKey> set = new HashSet<RowKey>();
String[] mildKeys = settings.getStringArray("mildKeys" + colName + j);
for (int k = 0; k < mildKeys.length; k++) {
set.add(new RowKey(mildKeys[k]));
}
mildmap.put(mild[j], set);
}
m_mildOutliers.put(colName, mildmap);
double[] extr = settings.getDoubleArray("extreme" + colName);
Map<Double, Set<RowKey>> extrmap = new LinkedHashMap<Double, Set<RowKey>>();
for (int j = 0; j < extr.length; j++) {
Set<RowKey> set = new HashSet<RowKey>();
String[] extrKeys = settings.getStringArray("extremeKeys" + colName + j);
for (int k = 0; k < extrKeys.length; k++) {
set.add(new RowKey(extrKeys[k]));
}
extrmap.put(extr[j], set);
}
m_extremeOutliers.put(colName, extrmap);
}
File dataFile = new File(nodeInternDir, "conditionalBoxPlotDataFile");
ContainerTable table = DataContainer.readFromZip(dataFile);
m_dataArray = new DefaultDataArray(table, 1, 2, exec);
} catch (Exception e) {
throw new IOException("Unable to load internals: " + e.getMessage(), e);
}
}
use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.
the class ConditionalBoxPlotNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
try {
NodeSettings settings = new NodeSettings("conditionalBoxPlotInternals");
settings.addInt("nrOfCols", m_statistics.size());
int i = 0;
for (DataColumnSpec spec : m_statistics.keySet()) {
NodeSettings colSetting = (NodeSettings) settings.addConfig("col" + (i++));
spec.save(colSetting);
}
if (m_numColSpec != null) {
m_numColSpec.save(settings.addConfig("numColSpec"));
}
for (Map.Entry<DataColumnSpec, double[]> entry : m_statistics.entrySet()) {
String colName = entry.getKey().getName();
settings.addDoubleArray("stats" + colName, entry.getValue());
Map<Double, Set<RowKey>> mildOutliers = m_mildOutliers.get(colName);
double[] mild = new double[mildOutliers.size()];
int mildIndex = 0;
for (Map.Entry<Double, Set<RowKey>> mEnt : mildOutliers.entrySet()) {
RowKey[] keys = mEnt.getValue().toArray(new RowKey[mEnt.getValue().size()]);
String[] mildKeys = new String[keys.length];
mild[mildIndex] = mEnt.getKey();
for (int j = 0; j < keys.length; j++) {
mildKeys[j] = keys[j].getString();
}
settings.addStringArray("mildKeys" + colName + mildIndex, mildKeys);
mildIndex++;
}
settings.addDoubleArray("mild" + colName, mild);
Map<Double, Set<RowKey>> extremeOutliers = m_extremeOutliers.get(colName);
double[] extr = new double[extremeOutliers.size()];
int extrIndex = 0;
for (Map.Entry<Double, Set<RowKey>> eEnt : extremeOutliers.entrySet()) {
RowKey[] keys = eEnt.getValue().toArray(new RowKey[eEnt.getValue().size()]);
String[] extrKeys = new String[keys.length];
extr[extrIndex] = eEnt.getKey();
for (int j = 0; j < keys.length; j++) {
extrKeys[j] = keys[j].getString();
}
settings.addStringArray("extremeKeys" + colName + extrIndex, extrKeys);
extrIndex++;
}
settings.addDoubleArray("extreme" + colName, extr);
}
File f = new File(nodeInternDir, "conditionalBoxPlotInternals");
FileOutputStream fos = new FileOutputStream(f);
settings.saveToXML(fos);
File dataFile = new File(nodeInternDir, "conditionalBoxPlotDataFile");
DataContainer.writeToZip(m_dataArray, dataFile, exec);
} catch (Exception e) {
throw new IOException("Unable to save internals: " + e.getMessage(), e);
}
}
use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.
the class FixedHistogramDataModel method loadFromFile.
/**
* @param directory the directory to write to
* @param exec the {@link ExecutionMonitor} to provide progress messages; must not be <code>null</code>
* @return the histogram data model
* @throws InvalidSettingsException if the x column specification
* wasn't valid
* @throws IOException if a file exception occurs
* @throws CanceledExecutionException if the operation is canceled
*/
public static FixedHistogramDataModel loadFromFile(final File directory, final ExecutionMonitor exec) throws InvalidSettingsException, IOException, CanceledExecutionException {
exec.setProgress(0.0, "Start reading data from file");
final ConfigRO config;
final FileInputStream is;
final GZIPInputStream inData;
try {
final File settingsFile = new File(directory, CFG_DATA_FILE);
is = new FileInputStream(settingsFile);
inData = new GZIPInputStream(is);
config = NodeSettings.loadFromXML(inData);
} catch (final FileNotFoundException e) {
throw e;
} catch (final IOException e) {
LOGGER.error("Unable to load histogram data: " + e.getMessage());
throw new IOException("Please reexecute the histogram node. " + "(For details see log file)");
}
final Config xConfig = config.getConfig(CFG_X_COL_SPEC);
final DataColumnSpec xColSpec = DataColumnSpec.load(xConfig);
final boolean binNominal = config.getBoolean(CFG_NOMINAL);
AggregationMethod aggrMethod = AggregationMethod.getDefaultMethod();
try {
aggrMethod = AggregationMethod.getMethod4Command(config.getString(CFG_AGGR_METHOD));
} catch (final Exception e) {
// Take the default method
}
exec.setProgress(0.1, "Binning column specification loaded");
exec.setProgress("Loading aggregation columns...");
final Config aggrConf = config.getConfig(CFG_AGGR_COLS);
final int aggrColCounter = aggrConf.getInt(CFG_AGGR_COL_COUNTER);
final ArrayList<ColorColumn> aggrCols = new ArrayList<ColorColumn>(aggrColCounter);
for (int i = 0; i < aggrColCounter; i++) {
final Config aggrColConf = aggrConf.getConfig(CFG_COLOR_COL + i);
aggrCols.add(ColorColumn.loadFromFile(aggrColConf, exec));
}
exec.setProgress(0.3, "Loading bins...");
final ConfigRO binsConf = config.getConfig(CFG_BINS);
final int binCounter = binsConf.getInt(CFG_BIN_COUNTER);
final List<BinDataModel> bins = new ArrayList<BinDataModel>(binCounter);
for (int i = 0; i < binCounter; i++) {
final Config binConf = binsConf.getConfig(CFG_BIN + i);
bins.add(BinDataModel.loadFromFile(binConf, exec));
}
final Config missingConfig = binsConf.getConfig(CFG_MISSING_BIN);
final BinDataModel missingBin = BinDataModel.loadFromFile(missingConfig, exec);
BinDataModel invalidBin = null;
if (binsConf.containsKey(CFG_INVALID_BIN)) {
final Config invalidConfig = binsConf.getConfig(CFG_INVALID_BIN);
invalidBin = BinDataModel.loadFromFile(invalidConfig, exec);
}
exec.setProgress(0.9, "Loading element colors...");
final ConfigRO colorColsConf = config.getConfig(CFG_COLOR_COLS);
final int counter = colorColsConf.getInt(CFG_ROW_COLOR_COUNTER);
final SortedSet<Color> rowColors = new TreeSet<Color>(HSBColorComparator.getInstance());
for (int i = 0; i < counter; i++) {
rowColors.add(new Color(colorColsConf.getInt(CFG_ROW_COLOR + i)));
}
exec.setProgress(1.0, "Histogram data model loaded ");
// close the stream
inData.close();
is.close();
return new FixedHistogramDataModel(xColSpec, aggrMethod, aggrCols, binNominal, bins, missingBin, invalidBin, rowColors);
}
Aggregations