Search in sources :

Example 16 with CanceledExecutionException

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);
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 17 with CanceledExecutionException

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
    }
}
Also used : CanceledExecutionException(org.knime.core.node.CanceledExecutionException) FileWriter(java.io.FileWriter) RowIterator(org.knime.core.data.RowIterator) File(java.io.File) DataRow(org.knime.core.data.DataRow) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Example 18 with CanceledExecutionException

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.
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) StringCell(org.knime.core.data.def.StringCell) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) FileWriter(java.io.FileWriter) DataCell(org.knime.core.data.DataCell) File(java.io.File) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Example 19 with CanceledExecutionException

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);
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) Test(org.junit.Test)

Example 20 with CanceledExecutionException

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);
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) Test(org.junit.Test)

Aggregations

CanceledExecutionException (org.knime.core.node.CanceledExecutionException)82 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)34 IOException (java.io.IOException)32 File (java.io.File)21 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)21 DataRow (org.knime.core.data.DataRow)20 DataTableSpec (org.knime.core.data.DataTableSpec)20 BufferedDataTable (org.knime.core.node.BufferedDataTable)20 DataCell (org.knime.core.data.DataCell)19 ArrayList (java.util.ArrayList)11 DataColumnSpec (org.knime.core.data.DataColumnSpec)11 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)10 LinkedHashMap (java.util.LinkedHashMap)9 ExecutionException (java.util.concurrent.ExecutionException)9 DefaultRow (org.knime.core.data.def.DefaultRow)9 RowKey (org.knime.core.data.RowKey)8 BufferedWriter (java.io.BufferedWriter)7 FileInputStream (java.io.FileInputStream)7 Map (java.util.Map)7 Future (java.util.concurrent.Future)7