Search in sources :

Example 31 with DataTable

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

the class SubgroupMinerModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    DataTable input = (BufferedDataTable) inData[0];
    ExecutionMonitor exec1 = exec.createSubProgress(0.5);
    ExecutionMonitor exec2 = exec.createSubProgress(0.5);
    List<BitVectorValue> transactions = preprocess(input, exec1);
    m_nameMapping = input.getDataTableSpec().getColumnSpec(m_bitVectorColumn.getStringValue()).getElementNames();
    m_apriori = AprioriAlgorithmFactory.getAprioriAlgorithm(AprioriAlgorithmFactory.AlgorithmDataStructure.valueOf(m_underlyingStruct.getStringValue()), m_maxBitsetLength, m_nrOfRows);
    LOGGER.debug("support: " + m_minSupport);
    LOGGER.debug(m_minSupport + " start apriori: " + new Date());
    m_apriori.findFrequentItemSets(transactions, m_minSupport.getDoubleValue(), m_maxItemSetLength.getIntValue(), FrequentItemSet.Type.valueOf(m_itemSetType.getStringValue()), exec2);
    LOGGER.debug("ended apriori: " + new Date());
    m_itemSetTable = createOutputTable(exec);
    return new BufferedDataTable[] { m_itemSetTable };
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) Date(java.util.Date)

Example 32 with DataTable

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

the class PMCCNodeView method modelChanged.

/**
 * {@inheritDoc}
 */
@Override
protected void modelChanged() {
    DataTable table = getNodeModel().getCorrelationTable();
    TableContentModel cntModel = m_tableView.getContentModel();
    cntModel.setDataTable(table);
    changeRenderer(m_currentRendererID);
    // must not call this on cntView as that would not affect the
    // row header column
    m_tableView.setRowHeight(16);
}
Also used : DataTable(org.knime.core.data.DataTable) TableContentModel(org.knime.core.node.tableview.TableContentModel)

Example 33 with DataTable

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

the class MissingValueHandlingTable method createMissingValueHandlingTable.

// getColSetting(DataTableSpec, ColSetting[])
/**
 * Does missing value handling to the argument table given the col settings
 * in an array and also reports progress.
 *
 * @param table the table to do missing value handling on
 * @param colSettings the settings
 * @param exec for progress/cancel and to create the buffered data table
 * @param warningBuffer To which potential warning messages are added.
 * @return a cache table, cleaned up
 * @throws CanceledExecutionException if canceled
 */
public static BufferedDataTable createMissingValueHandlingTable(final DataTable table, final ColSetting[] colSettings, final ExecutionContext exec, final StringBuffer warningBuffer) throws CanceledExecutionException {
    ColSetting[] colSetting;
    try {
        colSetting = getColSetting(table.getDataTableSpec(), colSettings, false);
    } catch (InvalidSettingsException ise) {
        LOGGER.coding("getColSetting method is not supposed to throw " + "an exception, ignoring settings", ise);
        DataTableSpec s = table.getDataTableSpec();
        colSetting = new ColSetting[s.getNumColumns()];
        for (int i = 0; i < s.getNumColumns(); i++) {
            colSetting[i] = new ColSetting(s.getColumnSpec(i));
            colSetting[i].setMethod(ColSetting.METHOD_NO_HANDLING);
        }
    }
    boolean needStatistics = false;
    int mostFrequentColCount = 0;
    for (int i = 0; i < colSetting.length; i++) {
        ColSetting c = colSetting[i];
        switch(c.getMethod()) {
            case ColSetting.METHOD_MOST_FREQUENT:
                mostFrequentColCount++;
            case ColSetting.METHOD_MAX:
            case ColSetting.METHOD_MIN:
            case ColSetting.METHOD_MEAN:
                needStatistics = true;
                break;
            default:
        }
    }
    int[] mostFrequentCols = new int[mostFrequentColCount];
    if (mostFrequentColCount > 0) {
        int index = 0;
        for (int i = 0; i < colSetting.length; i++) {
            ColSetting c = colSetting[i];
            switch(c.getMethod()) {
                case ColSetting.METHOD_MOST_FREQUENT:
                    mostFrequentCols[index++] = i;
                    break;
                default:
            }
        }
    }
    DataTable t;
    ExecutionMonitor e;
    if (needStatistics && !(table instanceof StatisticsTable)) {
        // for creating statistics table
        ExecutionMonitor subExec = exec.createSubProgress(0.5);
        t = new MyStatisticsTable(table, subExec, mostFrequentCols);
        if (((MyStatisticsTable) t).m_warningMessage != null) {
            warningBuffer.append(((MyStatisticsTable) t).m_warningMessage);
        }
        // for the iterator
        e = exec.createSubProgress(0.5);
    } else {
        t = table;
        e = exec;
    }
    MissingValueHandlingTable mvht = new MissingValueHandlingTable(t, colSetting);
    BufferedDataContainer container = exec.createDataContainer(mvht.getDataTableSpec());
    e.setMessage("Adding rows...");
    int count = 0;
    try {
        MissingValueHandlingTableIterator it = new MissingValueHandlingTableIterator(mvht, e);
        while (it.hasNext()) {
            DataRow next;
            next = it.next();
            e.setMessage("Adding row " + (count + 1) + " (\"" + next.getKey() + "\")");
            container.addRowToTable(next);
            count++;
        }
    } catch (MissingValueHandlingTableIterator.RuntimeCanceledExecutionException rcee) {
        throw rcee.getCause();
    } finally {
        container.close();
    }
    return container.getTable();
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) StatisticsTable(org.knime.base.data.statistics.StatisticsTable) DataRow(org.knime.core.data.DataRow) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Example 34 with DataTable

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

the class JoinerNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataContainer dc = exec.createDataContainer(JoinedTable.createSpec(inData[0].getDataTableSpec(), inData[1].getDataTableSpec(), m_method, m_suffix));
    DataTable leftTable = inData[0];
    DataTable rightTable = inData[1];
    // in the output
    if (JoinedTable.METHOD_FILTER.equals(m_method)) {
        DataTableSpec leftTableSpec = leftTable.getDataTableSpec();
        DataTableSpec rightTableSpec = rightTable.getDataTableSpec();
        LinkedHashSet<String> leftHash = new LinkedHashSet<String>();
        for (DataColumnSpec c : leftTableSpec) {
            leftHash.add(c.getName());
        }
        LinkedHashSet<String> rightHash = new LinkedHashSet<String>();
        for (DataColumnSpec c : rightTableSpec) {
            rightHash.add(c.getName());
        }
        rightHash.removeAll(leftHash);
        String[] survivors = rightHash.toArray(new String[rightHash.size()]);
        if (survivors.length < rightTableSpec.getNumColumns()) {
            rightTable = new FilterColumnTable(rightTable, survivors);
        }
    }
    final BitSet rightRows = new BitSet(inData[1].getRowCount());
    final LinkedHashMap<RowKey, SoftReference<Helper>> map = new LinkedHashMap<RowKey, SoftReference<Helper>>(1024);
    m_leftRows = 0;
    m_outputRows = 0;
    m_leftIt = null;
    m_rightIt = null;
    m_firstMapHelper = null;
    m_exec = exec;
    if (m_ignoreMissingRows) {
        m_max = Math.min(inData[0].getRowCount(), inData[1].getRowCount());
    } else {
        m_max = Math.max(inData[0].getRowCount(), inData[1].getRowCount());
    }
    while (true) {
        if (!readLeftChunk(leftTable, map)) {
            if (!m_ignoreMissingRows) {
                processRemainingRightRows(dc, leftTable, rightTable, rightRows);
            }
            break;
        }
        if ((m_rightIt == null) || (!m_rightIt.hasNext()) || (rightRows.nextClearBit(0) <= m_rightIt.getIndex())) {
            m_rightIt = new CounterRowIterator(rightTable.iterator());
        }
        while (m_rightIt.hasNext() && (map.size() > 0)) {
            m_exec.checkCanceled();
            DataRow rightRow = m_rightIt.next();
            SoftReference<Helper> sr = map.get(rightRow.getKey());
            if (sr != null) {
                Helper h = sr.get();
                if (h == null) {
                    map.remove(rightRow.getKey());
                } else {
                    h.m_rightRow = rightRow;
                    h.m_rightIndex = m_rightIt.getIndex();
                    if (h.m_leftIndex == m_leftRows) {
                        // m_firstMapHelper = h;
                        assert h.m_predecessor == null || !map.containsKey(h.m_predecessor.m_leftRow.getKey());
                        h.m_predecessor = null;
                        DataRow joinedRow = new JoinedRow(h.m_leftRow, h.m_rightRow);
                        dc.addRowToTable(joinedRow);
                        map.remove(rightRow.getKey());
                        rightRows.set(m_rightIt.getIndex());
                        m_leftRows++;
                        m_outputRows++;
                        printProgress(rightRow.getKey());
                    }
                }
            }
        }
        processRemainingLeftRowsInMap(dc, rightTable, map, rightRows);
        if (!m_ignoreMissingRows) {
            if (rightRows.cardinality() == inData[1].getRowCount()) {
                processRemainingLeftRowsInTable(dc, leftTable, rightTable);
            }
        } else {
            m_leftRows += map.size();
            map.clear();
            if (rightRows.cardinality() == inData[1].getRowCount()) {
                break;
            }
        }
    }
    m_leftIt = null;
    m_rightIt = null;
    m_exec = null;
    m_firstMapHelper = null;
    dc.close();
    return new BufferedDataTable[] { dc.getTable() };
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) FilterColumnTable(org.knime.base.data.filter.column.FilterColumnTable) BitSet(java.util.BitSet) DataRow(org.knime.core.data.DataRow) LinkedHashMap(java.util.LinkedHashMap) DataColumnSpec(org.knime.core.data.DataColumnSpec) SoftReference(java.lang.ref.SoftReference) BufferedDataTable(org.knime.core.node.BufferedDataTable) JoinedRow(org.knime.core.data.def.JoinedRow)

Example 35 with DataTable

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

the class ReadSysPropertyNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    if (m_config == null) {
        m_config = new ReadSysPropertyConfiguration();
        m_config.loadSettingsNoFail(new NodeSettings("empty"));
        setWarningMessage("Auto-configuration: " + "extracting all available properties");
    }
    Result result = m_config.createResult();
    String message = result.getWarningMessage();
    if (message != null) {
        setWarningMessage(message);
    }
    DataTable table = result.getTable();
    return new DataTableSpec[] { table.getDataTableSpec() };
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeSettings(org.knime.core.node.NodeSettings) DataTableSpec(org.knime.core.data.DataTableSpec) Result(org.knime.base.node.io.extractsysprop.ReadSysPropertyConfiguration.Result)

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