use of org.knime.core.data.RowIterator in project knime-core by knime.
the class SubgroupMinerModel method preprocess.
private List<BitVectorValue> preprocess(final DataTable inData, final ExecutionMonitor exec) throws CanceledExecutionException {
// TODO: check in configure that only Double values are in the table
m_tidRowKeyMapping = new HashMap<Integer, RowKey>();
m_nrOfRows = 0;
int totalNrRows = ((BufferedDataTable) inData).getRowCount();
m_maxBitsetLength = 0;
List<BitVectorValue> bitSets = new ArrayList<BitVectorValue>();
int bitVectorIndex = inData.getDataTableSpec().findColumnIndex(m_bitVectorColumn.getStringValue());
if (bitVectorIndex < 0) {
return new ArrayList<BitVectorValue>();
}
for (RowIterator itr = inData.iterator(); itr.hasNext(); ) {
exec.checkCanceled();
DataRow currRow = itr.next();
DataCell dc = currRow.getCell(bitVectorIndex);
if (dc.isMissing()) {
continue;
}
BitVectorValue currCell = ((BitVectorValue) currRow.getCell(bitVectorIndex));
if (currCell.length() > Integer.MAX_VALUE) {
throw new IllegalArgumentException("bit vector in row " + currRow.getKey().getString() + " is too long: " + currCell.length() + ". Only bit vectors up to " + Integer.MAX_VALUE + " are supported by this node.");
}
m_maxBitsetLength = Math.max(m_maxBitsetLength, (int) currCell.length());
bitSets.add(currCell);
m_tidRowKeyMapping.put(m_nrOfRows, currRow.getKey());
m_nrOfRows++;
exec.setProgress((double) m_nrOfRows / (double) totalNrRows, "preprocessing......." + m_nrOfRows);
}
LOGGER.debug("max length: " + m_maxBitsetLength);
return bitSets;
}
use of org.knime.core.data.RowIterator in project knime-core by knime.
the class Rule2DDrawingPane method paintRules.
private synchronized void paintRules(final Graphics g) {
if (m_normRules == null || !m_normRules.iterator().hasNext()) {
return;
}
m_coreRegions = new HashMap<RowKey, Rectangle>();
Graphics2D g2 = (Graphics2D) g;
RowIterator orgItr = m_orgData.iterator();
for (Iterator<DataRow> it = m_normRules.iterator(); it.hasNext(); ) {
DataRow row = it.next();
DataRow orgRow = orgItr.next();
// or if rule is hilited
if (!m_hideUnhilitedRules || m_hiLiteHandler.isHiLit(row.getKey())) {
// check whether the rule is selected or hilited
boolean selected = m_selectedRules.contains(row.getKey());
boolean hilite = false;
if (m_hiLiteHandler != null) {
hilite = m_hiLiteHandler.isHiLit(row.getKey());
}
Color currColor = m_orgData.getDataTableSpec().getRowColor(orgRow).getColor(selected, hilite);
FuzzyIntervalValue x = (FuzzyIntervalValue) row.getCell(0);
FuzzyIntervalValue y = (FuzzyIntervalValue) row.getCell(1);
// fuzzy rule
if (x.getMinSupport() != x.getMinCore() || x.getMaxCore() != x.getMaxSupport() || y.getMinSupport() != y.getMinCore() || y.getMaxCore() != y.getMaxSupport()) {
paintSupportArea(g2, row, currColor);
}
paintCoreArea(g2, row, currColor);
}
// end is unhiliting?
}
// end for
}
use of org.knime.core.data.RowIterator in project knime-core by knime.
the class Rule2DPlotter method updatePaintModel.
/**
* {@inheritDoc}
*/
@Override
protected void updatePaintModel() {
super.updatePaintModel();
if (m_rules != null) {
Rule2DDrawingPane drawingPane = getDrawingPane();
drawingPane.setOriginalRuleTable(m_rules);
String xName = getXColName();
String yName = getYColName();
int xIdx = -1;
int yIdx = -1;
if (xName != null && yName != null) {
xIdx = m_rules.getDataTableSpec().findColumnIndex(xName);
yIdx = m_rules.getDataTableSpec().findColumnIndex(yName);
}
if (xIdx >= 0 && yIdx >= 0) {
Coordinate x = getColHeader().getCoordinate();
Coordinate y = getRowHeader().getCoordinate();
// check if the coordinates are valid
if (x == null || y == null) {
return;
}
// calculate the coordinates of the rules here
// List<DataRow> rows = new ArrayList<DataRow>();
DataColumnSpecCreator creator = new DataColumnSpecCreator("xValues", FuzzyIntervalCell.TYPE);
DataColumnSpec col1 = creator.createSpec();
creator = new DataColumnSpecCreator("yValues", FuzzyIntervalCell.TYPE);
DataColumnSpec col2 = creator.createSpec();
DataTableSpec spec = new DataTableSpec(new DataColumnSpec[] { col1, col2 });
DataContainer rows = new DataContainer(spec);
for (RowIterator itr = m_rules.iterator(); itr.hasNext(); ) {
DataRow currRow = itr.next();
DataCell[] newCells = new DataCell[2];
for (int cell = 0; cell < currRow.getNumCells(); cell++) {
// if (!m_rules.getDataTableSpec().getColumnSpec(cell)
// .getType().isCompatible(
// FuzzyIntervalValue.class)) {
// continue;
// }
Rectangle rect = calculateDrawingRectangle();
double a;
double b;
double c;
double d;
if (cell == xIdx) {
if (currRow.getCell(cell).isMissing()) {
// normalize xValues
a = getXmin();
b = getXmin();
c = getXmax();
d = getXmax();
} else {
// normalize xValues
a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
}
double newA = x.calculateMappedValue(new DoubleCell(a), rect.width, true);
double newB = x.calculateMappedValue(new DoubleCell(b), rect.width, true);
double newC = x.calculateMappedValue(new DoubleCell(c), rect.width, true);
double newD = x.calculateMappedValue(new DoubleCell(d), rect.width, true);
DataCell newInterval = new FuzzyIntervalCell(rect.x + newA, rect.x + newB, rect.x + newC, rect.x + newD);
newCells[0] = newInterval;
}
if (cell == yIdx) {
if (currRow.getCell(cell).isMissing()) {
a = getYmin();
b = getYmin();
c = getYmax();
d = getYmax();
} else {
// normalize yValues
a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
}
double newA = y.calculateMappedValue(new DoubleCell(a), rect.height, true);
double newB = y.calculateMappedValue(new DoubleCell(b), rect.height, true);
double newC = y.calculateMappedValue(new DoubleCell(c), rect.height, true);
double newD = y.calculateMappedValue(new DoubleCell(d), rect.height, true);
DataCell newInterval = new FuzzyIntervalCell(rect.y + rect.height - newD, rect.y + rect.height - newC, rect.y + rect.height - newB, rect.y + rect.height - newA);
newCells[1] = newInterval;
}
}
// create new row out of the normalized cells
rows.addRowToTable(new DefaultRow(currRow.getKey(), newCells));
}
rows.close();
drawingPane.setNormalizedRules(new DefaultDataArray(rows.getTable(), 1, m_rules.size()));
}
super.updatePaintModel();
}
}
use of org.knime.core.data.RowIterator in project knime-core by knime.
the class TableRowToImageNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
BufferedDataTable inTable = (BufferedDataTable) inObjects[0];
// check for empty table
if (inTable.size() == 0) {
throw new IllegalArgumentException("Input table is empty.");
}
// warn if more than one row
if (inTable.size() > 1) {
setWarningMessage("Input data table has more than one rows! " + "Using first row only.");
}
String column = m_imageColSettingsModel.getStringValue();
DataTableSpec inSpec = inTable.getDataTableSpec();
int columnIndex = inSpec.findColumnIndex(column);
if (columnIndex < 0) {
columnIndex = findImageColumnIndex(inSpec);
}
ImagePortObjectSpec imagePortObjectSpec = new ImagePortObjectSpec(inSpec.getColumnSpec(columnIndex).getType());
final RowIterator it = inTable.iterator();
while (it.hasNext()) {
DataRow row = it.next();
DataCell cell = row.getCell(columnIndex);
if (!cell.isMissing()) {
ImageContent ic = ((ImageValue) cell).getImageContent();
return new PortObject[] { new ImagePortObject(ic, imagePortObjectSpec) };
} else {
setWarningMessage("Found missing image cell, skipping it...");
}
}
throw new IllegalArgumentException("Input table contains only missing cells.");
}
use of org.knime.core.data.RowIterator in project knime-core by knime.
the class AppendedRowsIterator method initNextTable.
/**
* Start iterator on next table.
*/
private void initNextTable() {
assert (m_curItIndex < m_iteratorSuppliers.length - 1);
m_curItIndex++;
Pair<RowIterator, DataTableSpec> pair = m_iteratorSuppliers[m_curItIndex].get();
m_curIterator = pair.getFirst();
DataTableSpec spec = pair.getSecond();
int missingNumber = m_spec.getNumColumns() - spec.getNumColumns();
m_curMissingCells = new DataCell[missingNumber];
int missingCounter = 0;
m_curMapping = new int[m_spec.getNumColumns()];
for (int c = 0; c < m_spec.getNumColumns(); c++) {
DataColumnSpec colSpec = m_spec.getColumnSpec(c);
int targetCol = spec.findColumnIndex(colSpec.getName());
if (targetCol < 0) {
// that is one of the "missing" columns
targetCol = spec.getNumColumns() + missingCounter;
// create the missing cell
m_curMissingCells[missingCounter] = DataType.getMissingCell();
missingCounter++;
}
m_curMapping[c] = targetCol;
}
boolean leaveUntouched = missingCounter == 0;
for (int i = 0; leaveUntouched && i < m_curMapping.length; i++) {
if (m_curMapping[i] != i) {
leaveUntouched = false;
}
}
if (leaveUntouched) {
m_curMapping = null;
m_curMissingCells = null;
}
assert missingCounter == missingNumber;
}
Aggregations