use of org.knime.core.data.def.DefaultRow in project knime-core by knime.
the class AffineTransRowIterator method next.
/**
* {@inheritDoc}
*/
@Override
public DataRow next() {
AffineTransConfiguration config = m_transtable.getConfiguration();
int[] indices = m_transtable.getIndicesInConfiguration();
double[] scales = config.getScales();
double[] translations = config.getTranslations();
double[] min = config.getMin();
double[] max = config.getMax();
final DataRow in = m_it.next();
final DataCell[] cells = new DataCell[in.getNumCells()];
for (int i = 0; i < cells.length; i++) {
final DataCell oldCell = in.getCell(i);
if (oldCell.isMissing() || indices[i] == -1) {
cells[i] = oldCell;
} else {
int index = indices[i];
double interval = max[index] - min[index];
double oldDouble = ((DoubleValue) oldCell).getDoubleValue();
double newDouble = scales[index] * oldDouble + translations[index];
if (!Double.isNaN(min[index])) {
if (newDouble < min[index]) {
if ((min[index] - newDouble) / interval < AffineTransTable.VERY_SMALL) {
newDouble = min[index];
} else {
m_transtable.setErrorMessage("Normalized value is out of bounds." + " Original value: " + oldDouble + " Transformed value: " + newDouble + " Lower Bound: " + min[index]);
}
}
}
if (!Double.isNaN(max[index])) {
if (newDouble > max[index]) {
if ((newDouble - max[index]) / interval < AffineTransTable.VERY_SMALL) {
newDouble = max[index];
} else {
m_transtable.setErrorMessage("Normalized value is out of bounds." + " Original value: " + oldDouble + " Transformed value: " + newDouble + " Upper Bound: " + max[index]);
}
}
}
cells[i] = new DoubleCell(newDouble);
}
}
return new DefaultRow(in.getKey(), cells);
}
use of org.knime.core.data.def.DefaultRow in project knime-core by knime.
the class VariableToTable2NodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
DataTableSpec spec = createOutSpec();
BufferedDataContainer cont = exec.createDataContainer(spec);
List<Pair<String, FlowVariable.Type>> vars = getVariablesOfInterest();
DataCell[] specs = new DataCell[vars.size()];
List<String> lostVariables = new ArrayList<String>();
for (int i = 0; i < vars.size(); i++) {
Pair<String, FlowVariable.Type> c = vars.get(i);
String name = c.getFirst();
// fallback
DataCell cell = DataType.getMissingCell();
switch(c.getSecond()) {
case DOUBLE:
try {
double dValue = peekFlowVariableDouble(c.getFirst());
cell = new DoubleCell(dValue);
} catch (NoSuchElementException e) {
lostVariables.add(name + " (Double)");
}
break;
case INTEGER:
try {
int iValue = peekFlowVariableInt(c.getFirst());
cell = new IntCell(iValue);
} catch (NoSuchElementException e) {
lostVariables.add(name + " (Integer)");
}
break;
case STRING:
try {
String sValue = peekFlowVariableString(c.getFirst());
sValue = sValue == null ? "" : sValue;
cell = new StringCell(sValue);
} catch (NoSuchElementException e) {
lostVariables.add(name + " (String)");
}
break;
}
specs[i] = cell;
}
cont.addRowToTable(new DefaultRow(m_rowID.getStringValue(), specs));
cont.close();
return new BufferedDataTable[] { cont.getTable() };
}
use of org.knime.core.data.def.DefaultRow in project knime-core by knime.
the class ExpressionFactoryTest method setUp.
/**
* Sets up the mock objects.
*
* @throws java.lang.Exception Should not happen.
*/
@Before
public void setUp() throws Exception {
final Map<String, Map<String, String>> emptyMap = Collections.emptyMap();
m_mockBoolExpression = new Expression.Base() {
@Override
public List<DataType> getInputArgs() {
return Collections.emptyList();
}
@Override
public DataType getOutputType() {
return BooleanCell.TYPE;
}
@Override
public ExpressionValue evaluate(final DataRow row, final VariableProvider provider) {
final DataCell cell;
switch(Integer.parseInt(row.getKey().getString())) {
case 0:
cell = BooleanCell.TRUE;
break;
case 1:
cell = BooleanCell.FALSE;
break;
case 2:
cell = BooleanCell.TRUE;
break;
case 3:
cell = BooleanCell.FALSE;
break;
case 4:
cell = DataType.getMissingCell();
break;
default:
throw new UnsupportedOperationException();
}
return new ExpressionValue(cell, emptyMap);
}
@Override
public boolean isConstant() {
return false;
}
@Override
public ASTType getTreeType() {
return ASTType.ColRef;
}
};
m_mockBoolExpressionOther = new Expression.Base() {
@Override
public boolean isConstant() {
return false;
}
@Override
public DataType getOutputType() {
return BooleanCell.TYPE;
}
@Override
public List<DataType> getInputArgs() {
return Collections.emptyList();
}
@Override
public ExpressionValue evaluate(final DataRow row, final VariableProvider provider) {
final DataCell cell;
switch(Integer.parseInt(row.getKey().getString())) {
case 0:
cell = BooleanCell.TRUE;
break;
case 1:
cell = BooleanCell.TRUE;
break;
case 2:
cell = BooleanCell.FALSE;
break;
case 3:
cell = BooleanCell.FALSE;
break;
case 4:
cell = BooleanCell.TRUE;
break;
default:
throw new UnsupportedOperationException();
}
return new ExpressionValue(cell, emptyMap);
}
@Override
public ASTType getTreeType() {
return ASTType.ColRef;
}
};
final DefaultRow row = new DefaultRow(new RowKey("x"), new DataCell[0]);
m_rows = new DataRow[] { new DefaultRow(new RowKey("0"), row), new DefaultRow(new RowKey("1"), row), new DefaultRow(new RowKey("2"), row), new DefaultRow(new RowKey("3"), row), new DefaultRow(new RowKey("4"), new DataCell[] { DataType.getMissingCell() }) };
}
use of org.knime.core.data.def.DefaultRow in project knime-core by knime.
the class ExpressionFactoryTest method testColumnRef.
/**
* Test method for {@link ExpressionFactory#columnRef(DataTableSpec, java.lang.String)} .
*/
@Test
public void testColumnRef() {
final DefaultRow row0 = new DefaultRow(new RowKey("0"), new IntCell(3));
final DefaultRow row1 = new DefaultRow(new RowKey("1"), new IntCell(3), new DoubleCell(3.14159));
final DefaultRow row2 = new DefaultRow(new RowKey("1"), new DoubleCell(3.14159), new StringCell("Hi"));
final ExpressionValue firstVal = m_factory.columnRef(new DataTableSpec(new String[] { "Num" }, new DataType[] { IntCell.TYPE }), "Num").evaluate(row0, null);
assertEquals(row0.getCell(0), firstVal.getValue());
assertEquals(row1.getCell(0), m_factory.columnRef(new DataTableSpec(new String[] { "Num", "Pi" }, new DataType[] { IntCell.TYPE, DoubleCell.TYPE }), "Num").evaluate(row0, null).getValue());
final ExpressionValue secondVal = m_factory.columnRef(new DataTableSpec(new String[] { "Num", "Pi" }, new DataType[] { IntCell.TYPE, DoubleCell.TYPE }), "Pi").evaluate(row1, null);
assertEquals(row1.getCell(1), secondVal.getValue());
final ExpressionValue thirdVal = m_factory.columnRef(new DataTableSpec(new String[] { "Pi", "Greeting" }, new DataType[] { DoubleCell.TYPE, StringCell.TYPE }), "Greeting").evaluate(row2, null);
assertEquals(row2.getCell(1), thirdVal.getValue());
}
use of org.knime.core.data.def.DefaultRow in project knime-core by knime.
the class ExpressionFactoryTest method testColumnRefForMissing.
/**
* Test method for {@link ExpressionFactory#columnRefForMissing(DataTableSpec, String)} .
*/
@Test
public void testColumnRefForMissing() {
final DefaultRow row0 = new DefaultRow(new RowKey("0"), DataType.getMissingCell());
final ExpressionValue firstVal = m_factory.columnRef(new DataTableSpec(new String[] { "Num" }, new DataType[] { IntCell.TYPE }), "Num").evaluate(row0, null);
assertEquals(row0.getCell(0), firstVal.getValue());
assertEquals(BooleanCell.FALSE, m_factory.columnRef(new DataTableSpec(new String[] { "Bool" }, new DataType[] { BooleanCell.TYPE }), "Bool").evaluate(row0, null).getValue());
final ExpressionValue secondVal = m_factory.columnRefForMissing(new DataTableSpec(new String[] { "Bool" }, new DataType[] { BooleanCell.TYPE }), "Bool").evaluate(row0, null);
assertEquals(row0.getCell(0), secondVal.getValue());
}
Aggregations