Search in sources :

Example 11 with DataTable

use of org.knime.core.data.DataTable 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 12 with DataTable

use of org.knime.core.data.DataTable in project knime-core by knime.

the class TreeDataCreator method readData.

/**
 * Reads the data from <b>learnData</b> into memory.
 * Each column is represented by a TreeColumnData object corresponding to its type
 * and whether it is a attribute or target column.
 *
 * @param learnData
 * @param configuration
 * @param exec
 * @return the TreeData object that holds all data in memory
 * @throws CanceledExecutionException
 */
public TreeData readData(final BufferedDataTable learnData, final TreeEnsembleLearnerConfiguration configuration, final ExecutionMonitor exec) throws CanceledExecutionException {
    if (learnData.size() <= 1) {
        throw new IllegalArgumentException("The input table must contain at least 2 rows!");
    }
    int index = 0;
    final long nrRows = learnData.size();
    final int nrLearnCols = m_attrColCreators.length;
    final boolean[] supportMissings = new boolean[nrLearnCols];
    for (int i = 0; i < nrLearnCols; i++) {
        supportMissings[i] = m_attrColCreators[i].acceptsMissing();
    }
    int rejectedMissings = 0;
    final int nrHilitePatterns = m_configuration.getNrHilitePatterns();
    // sort learnData according to the target column to enable equal size sampling
    final int targetColIdx = learnData.getDataTableSpec().findColumnIndex(m_configuration.getTargetColumn());
    Comparator<DataCell> targetComp = learnData.getDataTableSpec().getColumnSpec(targetColIdx).getType().getComparator();
    DataTableSorter sorter = new DataTableSorter(learnData, learnData.size(), new Comparator<DataRow>() {

        @Override
        public int compare(final DataRow arg0, final DataRow arg1) {
            return targetComp.compare(arg0.getCell(targetColIdx), arg1.getCell(targetColIdx));
        }
    });
    final ExecutionMonitor sortExec = exec.createSubProgress(0.5);
    final DataTable sortedTable = sorter.sort(sortExec);
    final ExecutionMonitor readExec = exec.createSubProgress(0.5);
    for (DataRow r : sortedTable) {
        double progress = index / (double) nrRows;
        readExec.setProgress(progress, "Row " + index + " of " + nrRows + " (\"" + r.getKey() + "\")");
        readExec.checkCanceled();
        boolean shouldReject = false;
        for (int i = 0; i < nrLearnCols; i++) {
            DataCell c = r.getCell(i);
            if (c.isMissing() && !supportMissings[i]) {
                shouldReject = true;
                break;
            }
        }
        DataCell targetCell = r.getCell(nrLearnCols);
        if (targetCell.isMissing()) {
            shouldReject = true;
        }
        if (shouldReject) {
            rejectedMissings += 1;
            continue;
        }
        if (index < nrHilitePatterns) {
            m_dataRowsForHiliteContainer.addRowToTable(r);
        }
        final RowKey key = r.getKey();
        for (int i = 0; i < nrLearnCols; i++) {
            DataCell c = r.getCell(i);
            m_attrColCreators[i].add(key, c);
        }
        m_targetColCreator.add(key, targetCell);
        index++;
    }
    if (nrHilitePatterns > 0 && index > nrHilitePatterns) {
        m_viewMessage = "Hilite (& color graphs) are based on a subset of " + "the data (" + nrHilitePatterns + "/" + index + ")";
    }
    if (rejectedMissings > 0) {
        StringBuffer warnMsgBuilder = new StringBuffer();
        warnMsgBuilder.append(rejectedMissings).append("/");
        warnMsgBuilder.append(learnData.size());
        warnMsgBuilder.append(" row(s) were ignored because they ");
        warnMsgBuilder.append("contain missing values.");
        m_warningMessage = warnMsgBuilder.toString();
    }
    CheckUtils.checkArgument(rejectedMissings < learnData.size(), "No rows left after removing missing values (table has %d row(s))", learnData.size());
    int nrLearnAttributes = 0;
    for (int i = 0; i < m_attrColCreators.length; i++) {
        nrLearnAttributes += m_attrColCreators[i].getNrAttributes();
    }
    TreeAttributeColumnData[] columns = new TreeAttributeColumnData[nrLearnAttributes];
    int learnAttributeIndex = 0;
    for (int i = 0; i < m_attrColCreators.length; i++) {
        TreeAttributeColumnDataCreator creator = m_attrColCreators[i];
        for (int a = 0; a < creator.getNrAttributes(); a++) {
            final TreeAttributeColumnData columnData = creator.createColumnData(a, configuration);
            columnData.getMetaData().setAttributeIndex(learnAttributeIndex);
            columns[learnAttributeIndex++] = columnData;
        }
    }
    TreeTargetColumnData targetCol = m_targetColCreator.createColumnData();
    return new TreeData(columns, targetCol, m_treeType);
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) RowKey(org.knime.core.data.RowKey) DataRow(org.knime.core.data.DataRow) DataTableSorter(org.knime.core.data.sort.DataTableSorter) DataCell(org.knime.core.data.DataCell) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Example 13 with DataTable

use of org.knime.core.data.DataTable in project knime-core by knime.

the class AppendedRowsTableTest method testAppendedRowsTableDataTableArray.

/**
 * Class under test for void AppendedRowsTable(DataTable[]).
 */
public void testAppendedRowsTableDataTableArray() {
    DataTable firstTable = new DefaultTable(DATA, DATA_H, DATA_TYPES);
    DataTable firstTableMissing = new DefaultTable(DATA_MISS_LAST, DATA_MISS_LAST_H, DATA_MISS_LAST_TYPES);
    DataTable firstTableShuffle = new DefaultTable(DATA_SHUFFLE, DATA_SHUFFLE_H, DATA_SHUFFLE_TYPES);
    DataTable secondTable = new DefaultTable(DATA_2, DATA_H, DATA_TYPES);
    new AppendedRowsTable(firstTable, secondTable);
    try {
        new AppendedRowsTable(firstTable, null);
        fail();
    } catch (NullPointerException npe) {
    // do nothing
    }
    try {
        new AppendedRowsTable((DataTable) null, secondTable);
        fail();
    } catch (NullPointerException npe) {
    // do nothing
    }
    new AppendedRowsTable(new DataTable[] { firstTableMissing, secondTable });
    new AppendedRowsTable(new DataTable[] { firstTable, firstTableShuffle });
}
Also used : DataTable(org.knime.core.data.DataTable) DefaultTable(org.knime.core.data.def.DefaultTable)

Example 14 with DataTable

use of org.knime.core.data.DataTable in project knime-core by knime.

the class AppendedRowsTableTest method testGetDataTableSpec.

/**
 * Test method for getDataTableSpec().
 */
public void testGetDataTableSpec() {
    DataTable firstTable = new DefaultTable(DATA, DATA_H, DATA_TYPES);
    DataTable firstTableShuffle = new DefaultTable(DATA_SHUFFLE, DATA_SHUFFLE_H, DATA_SHUFFLE_TYPES);
    DataTable ap = new AppendedRowsTable(new DataTable[] { firstTable, firstTableShuffle });
    assertTrue(ap.getDataTableSpec().equalStructure(firstTable.getDataTableSpec()));
}
Also used : DataTable(org.knime.core.data.DataTable) DefaultTable(org.knime.core.data.def.DefaultTable)

Example 15 with DataTable

use of org.knime.core.data.DataTable in project knime-core by knime.

the class JoinedTableTest method testMergedTable.

/**
 * Test for constructor.
 */
public final void testMergedTable() {
    DataColumnSpec[] leftCols = new DataColumnSpec[3];
    DataColumnSpec[] rightCols = new DataColumnSpec[3];
    System.arraycopy(COLS, 0, leftCols, 0, 3);
    System.arraycopy(COLS, 3, rightCols, 0, 3);
    DataTable leftTable = new DefaultTable(new DataRow[0], new DataTableSpec(leftCols));
    DataTable rightTable = new DefaultTable(new DataRow[0], new DataTableSpec(rightCols));
    new JoinedTable(leftTable, rightTable);
    try {
        new JoinedTable(null, rightTable);
        fail();
    } catch (NullPointerException ne) {
        NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + ne.getClass(), ne);
    }
    try {
        new JoinedTable(leftTable, null);
        fail();
    } catch (NullPointerException ne) {
        NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + ne.getClass(), ne);
    }
    try {
        new JoinedTable(leftTable, leftTable);
        fail();
    } catch (IllegalArgumentException iae) {
        NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + iae.getClass(), iae);
    }
    try {
        new JoinedTable(leftTable, leftTable);
        fail();
    } catch (IllegalArgumentException iae) {
        NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + iae.getClass(), iae);
    }
    rightCols[1] = leftCols[2];
    rightTable = new DefaultTable(new DataRow[0], new DataTableSpec(rightCols));
    try {
        new JoinedTable(leftTable, rightTable);
        fail();
    } catch (IllegalArgumentException iae) {
        NodeLogger.getLogger(JoinedTableTest.class).debug("Got expected exception: " + iae.getClass(), iae);
    }
}
Also used : DataTable(org.knime.core.data.DataTable) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DefaultTable(org.knime.core.data.def.DefaultTable) DataRow(org.knime.core.data.DataRow)

Aggregations

DataTable (org.knime.core.data.DataTable)64 BufferedDataTable (org.knime.core.node.BufferedDataTable)33 DataRow (org.knime.core.data.DataRow)20 DataTableSpec (org.knime.core.data.DataTableSpec)19 RowKey (org.knime.core.data.RowKey)14 DataCell (org.knime.core.data.DataCell)12 DataColumnSpec (org.knime.core.data.DataColumnSpec)12 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)11 DefaultTable (org.knime.core.data.def.DefaultTable)10 DefaultRow (org.knime.core.data.def.DefaultRow)8 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)7 DefaultDataArray (org.knime.base.node.util.DefaultDataArray)6 DataType (org.knime.core.data.DataType)6 PortObject (org.knime.core.node.port.PortObject)6 RowIterator (org.knime.core.data.RowIterator)5 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)5 ContainerTable (org.knime.core.data.container.ContainerTable)5 DataContainer (org.knime.core.data.container.DataContainer)5 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)5 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)5