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);
}
}
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);
}
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();
}
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.");
}
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);
}
Aggregations