use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.
the class TableSorterWorker method done.
/**
* {@inheritDoc}
*/
@Override
protected void done() {
m_progBar.dispose();
if (isCancelled()) {
return;
}
DataTable sortedTable;
try {
sortedTable = get();
} catch (InterruptedException e) {
LOGGER.debug("Interactive table sorting cancelled");
return;
// cancelled, ignore
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof CanceledExecutionException) {
LOGGER.debug("Interactive table sorting cancelled");
return;
}
if (cause == null) {
cause = e;
}
String error = "Error sorting table: " + cause.getMessage();
LOGGER.error(error, e);
JOptionPane.showMessageDialog(m_parentComponent.getRootPane(), error + "\nSee log files for details", "Sort error", JOptionPane.ERROR_MESSAGE);
return;
}
m_cntModel.setDataTableOnSort(sortedTable, m_sortOrder);
}
use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.
the class ARFFTableTest method testARFFTableMissVals.
/**
* tests stuff like '?' the ARFF missing value, comment lines and empty
* lines in the file.
*
* @throws IOException some time.
* @throws InvalidSettingsException sometimes.
*/
public void testARFFTableMissVals() throws IOException, InvalidSettingsException {
// "% Comment\n"
// + "% comment line 2\n"
// + "@attribute col1 string\n"
// + "@attribute col2 string\n"
// + "\n\n"
// + "@data\n\n"
// + "foo, poo\n"
// + "foo, ?\n"
// + "?, foo\n"
// + "%\n"
// + "%\n"
// + "\n";
File tempFile = File.createTempFile("ARFFReaderUnitTest", "table");
tempFile.deleteOnExit();
Writer out = new BufferedWriter(new FileWriter(tempFile));
out.write(ARFF_FIES);
out.close();
try {
ARFFTable table = new ARFFTable(tempFile.toURI().toURL(), ARFFTable.createDataTableSpecFromARFFfile(tempFile.toURI().toURL(), null), "Row");
assertEquals(table.getDataTableSpec().getNumColumns(), 2);
assertEquals(table.getDataTableSpec().getColumnSpec(0).getType(), StringCell.TYPE);
assertEquals(table.getDataTableSpec().getColumnSpec(1).getType(), StringCell.TYPE);
assertNull(table.getDataTableSpec().getColumnSpec(0).getDomain().getValues());
assertNull(table.getDataTableSpec().getColumnSpec(1).getDomain().getValues());
DataRow row;
RowIterator rIter = table.iterator();
assertTrue(rIter.hasNext());
row = rIter.next();
assertEquals(row.getKey().toString(), "Row0");
assertEquals(row.getCell(0).toString(), "foo");
assertEquals(row.getCell(1).toString(), "poo");
assertTrue(rIter.hasNext());
row = rIter.next();
assertEquals(row.getKey().toString(), "Row1");
assertEquals(row.getCell(0).toString(), "foo");
assertTrue(row.getCell(1).isMissing());
assertTrue(rIter.hasNext());
row = rIter.next();
assertEquals(row.getKey().toString(), "Row2");
assertTrue(row.getCell(0).isMissing());
assertEquals(row.getCell(1).toString(), "foo");
assertFalse(rIter.hasNext());
} catch (CanceledExecutionException cee) {
// no exec monitor, no cancel
}
}
use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.
the class ARFFTableTest method testCreateDataTableSpecFromARFFfileIRIS.
/**
* 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.
*/
public void testCreateDataTableSpecFromARFFfileIRIS() throws IOException, InvalidSettingsException {
File tempFile = File.createTempFile("ARFFReaderUnitTest", "mini");
tempFile.deleteOnExit();
Writer out = new BufferedWriter(new FileWriter(tempFile));
out.write(ARFF_IRISFULL);
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 LearnerTest method testPerformLowBirthWeightData.
/**
* Test method for {@link org.knime.base.node.mine.regression.logistic.learner.Learner#perform(BufferedDataTable, org.knime.core.node.ExecutionContext)}.
* @throws CanceledExecutionException
*/
@Test
public final void testPerformLowBirthWeightData() throws Exception {
final BufferedDataTable data = m_exec.createBufferedDataTable(new LowBirthWeightData(), m_exec);
PMMLPortObjectSpecCreator specCreator = new PMMLPortObjectSpecCreator(data.getDataTableSpec());
specCreator.setLearningColsNames(Arrays.asList(new String[] { "AGE", "LWT", "RACE", "FTV" }));
specCreator.setTargetColName("LOW");
final PMMLPortObjectSpec spec = specCreator.createSpec();
// done in KNIME thread pool, expected by code
Future<LogisticRegressionContent> callable = KNIMEConstants.GLOBAL_THREAD_POOL.enqueue(new Callable<LogisticRegressionContent>() {
@Override
public LogisticRegressionContent call() throws Exception {
final Learner learner = new Learner(spec, null, true, true);
return learner.perform(data, m_exec);
}
});
LogisticRegressionContent content = callable.get();
// Reference results are published in the book:
// Applied Logistic Regression,
// David W. Hosmer and Stanley Lemeshow
// Wiley, 2000 (2nd. ed)
// The table of results are found on page 36
Assert.assertEquals(-111.286, content.getEstimatedLikelihood(), 0.001);
}
use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.
the class LearnerTest method testPerformChdAgeData.
/**
* Test method for {@link org.knime.base.node.mine.regression.logistic.learner.Learner#perform(BufferedDataTable, org.knime.core.node.ExecutionContext)}.
* @throws CanceledExecutionException
*/
@Test
public final void testPerformChdAgeData() throws Exception {
final BufferedDataTable data = m_exec.createBufferedDataTable(new ChdAgeData(), m_exec);
PMMLPortObjectSpecCreator specCreator = new PMMLPortObjectSpecCreator(data.getDataTableSpec());
specCreator.setLearningColsNames(Arrays.asList(new String[] { "Age" }));
specCreator.setTargetColName("Evidence of Coronary Heart Disease");
final PMMLPortObjectSpec spec = specCreator.createSpec();
// done in KNIME thread pool, expected by code
Future<LogisticRegressionContent> callable = KNIMEConstants.GLOBAL_THREAD_POOL.enqueue(new Callable<LogisticRegressionContent>() {
@Override
public LogisticRegressionContent call() throws Exception {
final Learner learner = new Learner(spec, null, true, true);
return learner.perform(data, m_exec);
}
});
LogisticRegressionContent content = callable.get();
// Reference results are published in the book:
// Applied Logistic Regression,
// David W. Hosmer and Stanley Lemeshow
// Wiley, 2000 (2nd. ed)
// The table of results are found on page 10
Assert.assertEquals(-53.67656, content.getEstimatedLikelihood(), 0.001);
}
Aggregations