Search in sources :

Example 26 with RowIterator

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

the class MDSProjectionManager method preprocFixedDataPoints.

/**
 * Initializes for each of the fixed data points a point in the
 * target space. Which of the columns of the data table containing the
 * fixed points have to be considered (according to the non fixed points)
 * is specified by the given array of indices.
 *
 * @param fixedDataMdsIndices The indices specifying the columns of
 * the data table containing the fixed data points, to consider.
 * @throws CanceledExecutionException If the process is canceled.
 */
protected void preprocFixedDataPoints(final int[] fixedDataMdsIndices) throws CanceledExecutionException {
    m_exec.setMessage("Preprocessing fixed data points");
    // sort indices
    Arrays.sort(fixedDataMdsIndices);
    RowIterator it = m_fixedDataPoints.iterator();
    while (it.hasNext()) {
        m_exec.checkCanceled();
        DataRow row = it.next();
        DataPoint p = new DataPoint(m_dimension);
        for (int i = 0; i < m_dimension; i++) {
            final DataCell cell = row.getCell(fixedDataMdsIndices[i]);
            if (!cell.isMissing()) {
                final Double d = ((DoubleValue) cell).getDoubleValue();
                p.setElementAt(i, d);
            }
        }
        m_fixedPoints.put(row.getKey(), p);
    }
}
Also used : DataPoint(org.knime.base.node.mine.mds.DataPoint) DoubleValue(org.knime.core.data.DoubleValue) RowIterator(org.knime.core.data.RowIterator) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow) DataPoint(org.knime.base.node.mine.mds.DataPoint)

Example 27 with RowIterator

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

the class CAIMDiscretizationNodeModel method createAllIntervalBoundaries2.

/**
 * Sorts the data table in ascending order on the given column, then all
 * distinct values are determined and finally a new table is created that
 * holds the minimum, the maximum value and the midpoints of all adjacent
 * values. These represent all possible boundaries.
 *
 * @param table the table with the data
 * @param columnIndex the column of interest
 * @param exec the execution context to set the progress
 */
private BoundaryScheme createAllIntervalBoundaries2(final BufferedDataTable table, final int columnIndex, final ExecutionContext exec) throws Exception {
    // sort the data accordint to the column index
    List<String> sortColumn = new ArrayList<String>();
    sortColumn.add(table.getDataTableSpec().getColumnSpec(columnIndex).getName());
    boolean[] sortOrder = new boolean[1];
    // in ascending order
    sortOrder[0] = true;
    SortedTable sortedTable = new SortedTable(table, sortColumn, sortOrder, true, exec);
    // the first different value is the minimum value of the sorted list
    RowIterator rowIterator = sortedTable.iterator();
    double lastDifferentValue = ((DoubleValue) rowIterator.next().getCell(columnIndex)).getDoubleValue();
    // create the head of the linked double list
    // marked by NaN
    LinkedDouble head = new LinkedDouble(Double.NEGATIVE_INFINITY);
    // set the last added element
    LinkedDouble lastAdded = head;
    // count the number of boundaries
    int numBoundaries = 0;
    while (rowIterator.hasNext()) {
        DataRow row = rowIterator.next();
        DataCell cell = row.getCell(columnIndex);
        double value = ((DoubleValue) cell).getDoubleValue();
        if (value != lastDifferentValue) {
            // a new boundary is the midpoint
            double newBoundary = (value + lastDifferentValue) / 2.0D;
            lastDifferentValue = value;
            // add the new midpoint boundary to the linked list
            lastAdded.m_next = new LinkedDouble(newBoundary);
            numBoundaries++;
            lastAdded.m_next.m_previous = lastAdded;
            lastAdded = lastAdded.m_next;
        }
    }
    return new BoundaryScheme(head, numBoundaries);
}
Also used : ArrayList(java.util.ArrayList) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataRow(org.knime.core.data.DataRow) DoubleValue(org.knime.core.data.DoubleValue) SortedTable(org.knime.base.data.sort.SortedTable) RowIterator(org.knime.core.data.RowIterator) DataCell(org.knime.core.data.DataCell)

Example 28 with RowIterator

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

the class FileTable method toString.

// addTableSpecStatusOfSettings(SettingsStatus, DataTableSpec)
/**
 * Returns a string summary for this table which is the entire table
 * content. Note, this call might be time consuming since this method
 * iterates over the table to retrieve all data.
 *
 * {@inheritDoc}
 */
@Override
public String toString() {
    // maximum number of chars to print
    final int colLength = 15;
    RowIterator rowIterator = iterator();
    DataRow row;
    StringBuffer result = new StringBuffer();
    // Create a column header
    // Cell (0,0)
    result.append(sprintDataCell(" ", colLength));
    // "<ColName>[Type]"
    for (int i = 0; i < m_tableSpec.getNumColumns(); i++) {
        if (m_tableSpec.getColumnSpec(i).getType().equals(StringCell.TYPE)) {
            result.append(sprintDataCell(m_tableSpec.getColumnSpec(i).getName().toString() + "[Str]", colLength));
        } else if (m_tableSpec.getColumnSpec(i).getType().equals(IntCell.TYPE)) {
            result.append(sprintDataCell(m_tableSpec.getColumnSpec(i).getName().toString() + "[Int]", colLength));
        } else if (m_tableSpec.getColumnSpec(i).getType().equals(DoubleCell.TYPE)) {
            result.append(sprintDataCell(m_tableSpec.getColumnSpec(i).getName().toString() + "[Dbl]", colLength));
        } else {
            result.append(sprintDataCell(m_tableSpec.getColumnSpec(i).getName().toString() + "[UNKNOWN!!]", colLength));
        }
    }
    result.append("\n");
    while (rowIterator.hasNext()) {
        row = rowIterator.next();
        result.append(sprintDataCell(row.getKey().getString(), colLength));
        for (int i = 0; i < row.getNumCells(); i++) {
            result.append(sprintDataCell(row.getCell(i).toString(), colLength));
        }
        result.append("\n");
    }
    return result.toString();
}
Also used : RowIterator(org.knime.core.data.RowIterator) DataRow(org.knime.core.data.DataRow)

Example 29 with RowIterator

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

the class ConcatenateTableFactory method copyTablesIntoOneTable.

/**
 * Copies all tables, except the last still not-closed table, into an entire new table
 */
private void copyTablesIntoOneTable(final ExecutionContext exec) throws CanceledExecutionException {
    BufferedDataTable[] tables = new BufferedDataTable[m_tables.size() - 1];
    for (int i = 0; i < tables.length; i++) {
        tables[i] = m_tables.get(i).getTable();
    }
    AppendedRowsTable wrapper = new AppendedRowsTable(org.knime.core.data.append.AppendedRowsTable.DuplicatePolicy.Fail, null, tables);
    BufferedDataContainer con = exec.createDataContainer(wrapper.getDataTableSpec());
    RowIterator rowIt = wrapper.iterator();
    exec.setProgress("Too many tables. Copy tables into one table.");
    while (rowIt.hasNext()) {
        exec.checkCanceled();
        con.addRowToTable(rowIt.next());
    }
    con.close();
    BufferedDataContainer last = m_tables.get(m_tables.size() - 1);
    m_tables.clear();
    m_tables.add(con);
    m_tables.add(last);
    exec.setProgress("Tables copied into one.");
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) AppendedRowsTable(org.knime.core.data.append.AppendedRowsTable) RowIterator(org.knime.core.data.RowIterator) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 30 with RowIterator

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

the class ReplacedColumnsTable method iterator.

/**
 * {@inheritDoc}
 */
public RowIterator iterator() {
    RowIterator origIt = m_table.iterator();
    DataType[] validateTypes = new DataType[m_columns.length];
    for (int column = 0; column < m_columns.length; column++) {
        validateTypes[column] = getDataTableSpec().getColumnSpec(m_columns[column]).getType();
    }
    return new ReplacedColumnsRowIterator(origIt, m_cellFactory, validateTypes, m_columns);
}
Also used : RowIterator(org.knime.core.data.RowIterator) DataType(org.knime.core.data.DataType)

Aggregations

RowIterator (org.knime.core.data.RowIterator)77 DataRow (org.knime.core.data.DataRow)62 DataCell (org.knime.core.data.DataCell)28 DataTableSpec (org.knime.core.data.DataTableSpec)20 RowKey (org.knime.core.data.RowKey)16 DoubleValue (org.knime.core.data.DoubleValue)14 BufferedDataTable (org.knime.core.node.BufferedDataTable)13 DataColumnSpec (org.knime.core.data.DataColumnSpec)11 ArrayList (java.util.ArrayList)9 DefaultRow (org.knime.core.data.def.DefaultRow)8 PreparedStatement (java.sql.PreparedStatement)7 DataType (org.knime.core.data.DataType)6 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)6 HashSet (java.util.HashSet)5 Random (java.util.Random)5 TimeZone (java.util.TimeZone)5 DataTable (org.knime.core.data.DataTable)5 DoubleCell (org.knime.core.data.def.DoubleCell)5 StringCell (org.knime.core.data.def.StringCell)5 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)5