use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class BatchExecutor method setNodeOptions.
private static void setNodeOptions(final Collection<Option> options, final WorkflowManager wfm) throws InvalidSettingsException, IllegalOptionException {
for (Option o : options) {
int[] idPath = o.m_nodeIDs;
NodeID subID = new NodeID(wfm.getID(), idPath[0]);
NodeContainer cont = null;
try {
cont = wfm.getNodeContainer(subID);
for (int i = 1; i < idPath.length; i++) {
if (cont instanceof WorkflowManager) {
WorkflowManager subWM = (WorkflowManager) cont;
subID = new NodeID(subID, idPath[i]);
cont = subWM.getNodeContainer(subID);
} else {
cont = null;
}
}
} catch (IllegalArgumentException ex) {
// throw by getNodeContainer if no node with the id exists
cont = null;
}
if (cont == null) {
LOGGER.warn("No node with id " + Arrays.toString(idPath) + " found.");
} else {
WorkflowManager parent = cont.getParent();
NodeSettings settings = new NodeSettings("something");
parent.saveNodeSettings(cont.getID(), settings);
NodeSettings model = settings.getNodeSettings(Node.CFG_MODEL);
String[] splitName = o.m_name.split("/");
String name = splitName[splitName.length - 1];
String[] pathElements = new String[splitName.length - 1];
System.arraycopy(splitName, 0, pathElements, 0, pathElements.length);
for (String s : pathElements) {
model = model.getNodeSettings(s);
}
if ("int".equals(o.m_type)) {
model.addInt(name, Integer.parseInt(o.m_value));
} else if ("long".equals(o.m_type)) {
model.addLong(name, Long.parseLong(o.m_value));
} else if ("short".equals(o.m_type)) {
model.addShort(name, Short.parseShort(o.m_value));
} else if ("byte".equals(o.m_type)) {
model.addByte(name, Byte.parseByte(o.m_value));
} else if ("boolean".equals(o.m_type)) {
model.addBoolean(name, Boolean.parseBoolean(o.m_value));
} else if ("char".equals(o.m_type)) {
model.addChar(name, o.m_value.charAt(0));
} else if ("float".equals(o.m_type) || ("double".equals(o.m_type))) {
model.addDouble(name, Double.parseDouble(o.m_value));
} else if ("String".equals(o.m_type)) {
model.addString(name, o.m_value);
} else if ("StringCell".equals(o.m_type)) {
model.addDataCell(name, new StringCell(o.m_value));
} else if ("DoubleCell".equals(o.m_type)) {
double d = Double.parseDouble(o.m_value);
model.addDataCell(name, new DoubleCell(d));
} else if ("IntCell".equals(o.m_type)) {
int i = Integer.parseInt(o.m_value);
model.addDataCell(name, new IntCell(i));
} else if ("LongCell".equals(o.m_type)) {
long i = Long.parseLong(o.m_value);
model.addDataCell(name, new LongCell(i));
} else {
throw new IllegalOptionException("Unknown option type for " + o.m_name + ": " + o.m_type);
}
parent.loadNodeSettings(cont.getID(), settings);
}
}
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class ARFFRowIterator method createNewDataCellOfType.
/*
* The function creates a default <code> DataCell </code> of a type
* depending on the <code> type </code> passed in, and initializes the value
* of this data cell from the <code> data </code> string (converting the
* string to the corresponding type). It will create a missing cell and
* print a warning if it couldn't convert the string into the appropreate
* format (to int or double). It throws a <code> IllegalStateException
* </code> if the <code> type </code> passed in is not supported. @param
* type Specifies the type of DataCell that is to be created, supported are
* DoubleCell, IntCell, and StringCell. @param data the string
* representation of the value that will be set in the DataCell created. It
* gets trimmed before it's converted into a number. @param
* createMissingCell If set true the default ' <code> missing </code> '
* value of that cell type will be set indicating that the data in that cell
* was not specified. The <code> data </code> parameter is ignored then.
*
* @return <code> DataCell </code> of the type specified in <code> type
* </code> .
*/
private DataCell createNewDataCellOfType(final DataType type, final String data, final boolean createMissingCell) {
if (type.equals(StringCell.TYPE)) {
if (createMissingCell) {
return DataType.getMissingCell();
} else {
return new StringCell(data);
}
} else if (type.equals(IntCell.TYPE)) {
if (createMissingCell) {
return DataType.getMissingCell();
} else {
try {
int val = Integer.parseInt(data.trim());
return new IntCell(val);
} catch (NumberFormatException nfe) {
if (m_numMsgWrongFormat < MAX_ERR_MSG) {
LOGGER.warn("ARFF reader WARNING: Wrong data " + "format. In line " + m_tokenizer.getLineNumber() + " read '" + data + "' for an integer.");
LOGGER.warn(" Creating missing cell for it.");
m_numMsgWrongFormat++;
}
if (m_numMsgWrongFormat == MAX_ERR_MSG) {
LOGGER.warn(" (last message of " + "this kind.)");
m_numMsgWrongFormat++;
}
return DataType.getMissingCell();
}
}
} else if (type.equals(DoubleCell.TYPE)) {
if (createMissingCell) {
return DataType.getMissingCell();
} else {
try {
double val = Double.parseDouble(data.trim());
return new DoubleCell(val);
} catch (NumberFormatException nfe) {
if (m_numMsgWrongFormat < MAX_ERR_MSG) {
LOGGER.warn("ARFF reader WARNING: Wrong data " + "format. In line " + m_tokenizer.getLineNumber() + " read '" + data + "' for a floating point.");
LOGGER.warn(" Creating missing cell for it.");
m_numMsgWrongFormat++;
}
if (m_numMsgWrongFormat == MAX_ERR_MSG) {
m_numMsgWrongFormat++;
LOGGER.warn(" (last message of this kind.)");
}
return DataType.getMissingCell();
}
}
} else {
throw new IllegalStateException("Cannot create DataCell of type" + type.toString());
}
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class MissingValueHandling2Panel method getSettings.
/**
* Get the settings currently entered in the dialog.
*
* @return the current settings
*/
public MissingValueHandling2ColSetting getSettings() {
int method;
if (m_nothingButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_NO_HANDLING;
} else if (m_removeButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_IGNORE_ROWS;
} else if (m_fixButton != null && m_fixButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_FIX_VAL;
DataCell cell;
switch(m_setting.getType()) {
case MissingValueHandling2ColSetting.TYPE_INT:
Object value = ((JFormattedTextField) m_fixText).getValue();
cell = new IntCell(((Number) value).intValue());
break;
case MissingValueHandling2ColSetting.TYPE_DOUBLE:
value = ((JFormattedTextField) m_fixText).getValue();
cell = new DoubleCell(((Number) value).doubleValue());
break;
case MissingValueHandling2ColSetting.TYPE_STRING:
value = ((JComboBox) m_fixText).getEditor().getItem();
cell = new StringCell(value.toString());
break;
default:
throw new RuntimeException("You shouldn't have come here.");
}
m_setting.setFixCell(cell);
} else if (m_maxButton != null && m_maxButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_MAX;
} else if (m_minButton != null && m_minButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_MIN;
} else if (m_meanButton != null && m_meanButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_MEAN;
} else if (m_mostFrequentButton != null && m_mostFrequentButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT;
} else {
assert false : "One button must be selected.";
method = MissingValueHandling2ColSetting.METHOD_NO_HANDLING;
}
m_setting.setMethod(method);
return m_setting;
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class MissingValueHandling2TableIterator method handleMissing.
/* Does the missing value handling on a row. */
private DataRow handleMissing(final DataRow row) {
DataCell[] cells = new DataCell[row.getNumCells()];
for (int i = 0; i < row.getNumCells(); i++) {
MissingValueHandling2ColSetting colset = m_table.getColSetting(i);
DataCell oldCell = row.getCell(i);
DataCell newCell;
if (oldCell.isMissing()) {
switch(colset.getMethod()) {
case MissingValueHandling2ColSetting.METHOD_NO_HANDLING:
newCell = oldCell;
break;
case MissingValueHandling2ColSetting.METHOD_FIX_VAL:
newCell = m_table.getColSetting(i).getFixCell();
assert (newCell != null);
break;
case MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT:
newCell = m_table.getMostFrequent(i);
break;
case MissingValueHandling2ColSetting.METHOD_MAX:
newCell = m_table.getMax(i);
break;
case MissingValueHandling2ColSetting.METHOD_MIN:
newCell = m_table.getMin(i);
break;
case MissingValueHandling2ColSetting.METHOD_MEAN:
// in contrast to the above, it will return
// a newly generate value, thus, only a double
double mean = m_table.getMean(i);
if (colset.getType() == MissingValueHandling2ColSetting.TYPE_DOUBLE) {
newCell = new DoubleCell(mean);
} else {
assert colset.getType() == MissingValueHandling2ColSetting.TYPE_INT;
newCell = new IntCell((int) Math.round(mean));
}
break;
case MissingValueHandling2ColSetting.METHOD_IGNORE_ROWS:
assert false : "That should have been filtered.";
newCell = oldCell;
default:
throw new RuntimeException("Invalid method!");
}
} else {
newCell = oldCell;
}
cells[i] = newCell;
}
RowKey key = row.getKey();
return new DefaultRow(key, cells);
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class MissingValueHandling3TableIterator method handleMissing.
/* Does the missing value handling on a row. */
private DataRow handleMissing(final DataRow row) {
DataCell[] cells = new DataCell[row.getNumCells()];
for (int i = 0; i < row.getNumCells(); i++) {
MissingValueHandling2ColSetting colset = m_table.getColSetting(i);
DataCell oldCell = row.getCell(i);
DataCell newCell;
if (oldCell.isMissing()) {
switch(colset.getMethod()) {
case MissingValueHandling2ColSetting.METHOD_NO_HANDLING:
newCell = oldCell;
break;
case MissingValueHandling2ColSetting.METHOD_FIX_VAL:
newCell = m_table.getColSetting(i).getFixCell();
assert (newCell != null);
break;
case MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT:
newCell = m_table.getMostFrequent(i);
break;
case MissingValueHandling2ColSetting.METHOD_MAX:
newCell = m_table.getMax(i);
break;
case MissingValueHandling2ColSetting.METHOD_MIN:
newCell = m_table.getMin(i);
break;
case MissingValueHandling2ColSetting.METHOD_MEAN:
// in contrast to the above, it will return
// a newly generate value, thus, only a double
double mean = m_table.getMean(i);
if (colset.getType() == MissingValueHandling2ColSetting.TYPE_DOUBLE) {
if (Double.isNaN(mean) && m_table.getNumberNaNValues(i) == 0) {
newCell = new MissingCell("Calculated mean is not a number");
} else {
newCell = new DoubleCell(mean);
}
} else {
assert colset.getType() == MissingValueHandling2ColSetting.TYPE_INT;
if (Double.isNaN(mean)) {
newCell = new MissingCell("Calculated mean is not a number");
} else {
newCell = new IntCell((int) Math.round(mean));
}
}
break;
case MissingValueHandling2ColSetting.METHOD_IGNORE_ROWS:
assert false : "That should have been filtered.";
newCell = oldCell;
break;
default:
throw new RuntimeException("Invalid method!");
}
} else {
newCell = oldCell;
}
cells[i] = newCell;
}
RowKey key = row.getKey();
return new DefaultRow(key, cells);
}
Aggregations