use of org.knime.core.node.config.Config in project knime-core by knime.
the class NodeContainerProperties method setPropertyValue.
/**
* {@inheritDoc}
*/
@Override
public void setPropertyValue(final Object id, final Object value) {
if ((id instanceof String) && (value instanceof String)) {
String strVal = (String) value;
String strID = (String) id;
if (strID.startsWith(m_prefix)) {
String[] hierarchy = strID.split(CONFIG_SEPARATOR);
String key = hierarchy[hierarchy.length - 1];
// apply it to the node's settings:
NodeContainer node = getNode();
if (node == null) {
return;
}
WorkflowManager wfm = node.getParent();
NodeSettings nodeSettings = new NodeSettings("Transfer");
NodeSettings settings;
try {
wfm.saveNodeSettings(node.getID(), nodeSettings);
// overwrite our config in the settings
settings = nodeSettings.getNodeSettings("model");
if (hierarchy.length > 1) {
for (int i = 0; i < hierarchy.length - 1; i++) {
settings = settings.getNodeSettings(hierarchy[i]);
if (settings == null) {
return;
}
}
}
} catch (InvalidSettingsException e) {
// somehow node is not able to save its settings anymore
return;
}
AbstractConfigEntry entry = settings.getEntry(key);
if (entry == null || entry instanceof Config) {
// settings are not complete or correct anymore
return;
}
switch(entry.getType()) {
case xboolean:
settings.addBoolean(key, Boolean.parseBoolean(strVal));
break;
case xbyte:
settings.addByte(key, Byte.parseByte(strVal));
break;
case xchar:
String decoded = TokenizerSettings.unescapeString(strVal);
settings.addChar(key, decoded.charAt(0));
break;
case xdouble:
settings.addDouble(key, Double.parseDouble(strVal));
break;
case xfloat:
settings.addFloat(key, Float.parseFloat(strVal));
break;
case xint:
settings.addInt(key, Integer.parseInt(strVal));
break;
case xlong:
settings.addLong(key, Long.parseLong(strVal));
break;
case xshort:
settings.addShort(key, Short.parseShort(strVal));
break;
case xstring:
String dec = TokenizerSettings.unescapeString(strVal);
settings.addString(key, dec);
break;
default:
// ignore the new value
return;
}
try {
wfm.loadNodeSettings(node.getID(), nodeSettings);
} catch (Exception ex) {
LOGGER.error("Invalid Value (" + strVal + "): " + ex.getMessage(), ex);
return;
}
return;
}
}
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class HistogramColumn method loadNominalHistogramsPrivate.
private static Map<Integer, HistogramNominalModel> loadNominalHistogramsPrivate(final File histogramsGz, final int[] nominalKeysSize) throws IOException, InvalidSettingsException {
final FileInputStream is = new FileInputStream(histogramsGz);
final GZIPInputStream inData = new GZIPInputStream(is);
final ConfigRO config = NodeSettings.loadFromXML(inData);
Map<Integer, HistogramNominalModel> histograms = new HashMap<Integer, HistogramNominalModel>();
// .getConfig(HISTOGRAMS);
ConfigRO hs = config;
int[] nomColumnIndices = config.getIntArray(NOMINAL_COLUMNS);
for (int colIdx : nomColumnIndices) {
Config h = hs.getConfig(HISTOGRAM + colIdx);
int maxCount = h.getInt(MAX_COUNT);
int rowCount = h.getInt(ROW_COUNT);
String colName = h.getString(COL_NAME);
String[] values = h.getStringArray(BIN_VALUES);
int[] binCounts = h.getIntArray(BIN_COUNTS);
Map<DataValue, Integer> bins = new HashMap<DataValue, Integer>();
for (int i = binCounts.length; i-- > 0; ) {
if (values[i] == "?") {
bins.put(new MissingCell(null), binCounts[i]);
} else {
bins.put(new StringCell(values[i]), binCounts[i]);
}
}
HistogramNominalModel histogramData = new HistogramNominalModel(bins, colIdx, colName, rowCount);
histogramData.setMaxCount(maxCount);
histogramData.setRowCount(rowCount);
// assert Math.abs(histogramData.m_width - width) < 1e-9: "histogram data width: " + histogramData.m_width + " width: " + width;
assert nominalKeysSize[colIdx] == bins.size() : "Saved size of nominal bins: " + nominalKeysSize[colIdx] + ", restored from the file: " + bins.size();
histograms.put(colIdx, histogramData);
}
return histograms;
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class HistogramColumn method saveHistogramData.
/**
* Saves the numeric histogram data to a file.
*
* @param histograms The numeric histogram models associated to the column indices.
* @param histogramsFile The output file.
* @throws IOException File write problem.
*/
public static void saveHistogramData(final Map<Integer, ?> histograms, final File histogramsFile) throws IOException {
Config histogramData = new NodeSettings(HISTOGRAMS);
final FileOutputStream os = new FileOutputStream(histogramsFile);
final GZIPOutputStream dataOS = new GZIPOutputStream(os);
List<Integer> colIndices = new ArrayList<Integer>(histograms.keySet());
Collections.sort(colIndices);
int[] numericColumnIndices = new int[colIndices.size()];
for (int i = colIndices.size(); i-- > 0; ) {
numericColumnIndices[i] = colIndices.get(i).intValue();
}
histogramData.addIntArray(NUMERIC_COLUMNS, numericColumnIndices);
for (Integer colIdx : colIndices) {
Object object = histograms.get(colIdx);
if (object instanceof HistogramNumericModel) {
HistogramNumericModel hd = (HistogramNumericModel) object;
assert hd.getColIndex() == colIdx.intValue() : "colIdx: " + colIdx + ", but: " + hd.getColIndex();
Config h = histogramData.addConfig(HISTOGRAM + colIdx);
h.addDouble(MIN, hd.m_min);
h.addDouble(MAX, hd.m_max);
h.addDouble(WIDTH, hd.m_width);
h.addInt(MAX_COUNT, hd.getMaxCount());
h.addInt(ROW_COUNT, hd.getRowCount());
h.addInt(COL_INDEX, hd.getColIndex());
h.addString(COL_NAME, hd.getColName());
double[] minValues = new double[hd.getBins().size()], maxValues = new double[hd.getBins().size()];
int[] counts = new int[hd.getBins().size()];
for (int c = 0; c < hd.getBins().size(); c++) {
HistogramNumericModel.NumericBin bin = (HistogramNumericModel.NumericBin) hd.getBins().get(c);
minValues[c] = bin.getDef().getFirst().doubleValue();
maxValues[c] = bin.getDef().getSecond().doubleValue();
counts[c] = bin.getCount();
}
h.addDoubleArray(BIN_MINS, minValues);
h.addDoubleArray(BIN_MAXES, maxValues);
h.addIntArray(BIN_COUNTS, counts);
} else {
throw new IllegalStateException("Illegal argument: " + colIdx + ": " + object.getClass() + "\n " + object);
}
}
histogramData.saveToXML(dataOS);
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class StringToDurationPeriodNodeModel method computeFinalOutputSpecs.
@Override
public PortObjectSpec[] computeFinalOutputSpecs(final StreamableOperatorInternals internals, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
if (m_type.getStringValue().equals(OutputType.Automatic.name())) {
final SimpleStreamableOperatorInternals simpleInternals = (SimpleStreamableOperatorInternals) internals;
final Config config = simpleInternals.getConfig();
final DataColumnSpec[] colSpecs = new DataColumnSpec[config.getInt("sizeRow")];
for (int i = 0; i < colSpecs.length; i++) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(config.getString("colname" + i), config.getDataType("type" + i));
colSpecs[i] = dataColumnSpecCreator.createSpec();
}
return new DataTableSpec[] { new DataTableSpec(colSpecs) };
} else {
return configure(new DataTableSpec[] { (DataTableSpec) inSpecs[0] });
}
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class OldToNewTimeNodeModel method computeFinalOutputSpecs.
@Override
public PortObjectSpec[] computeFinalOutputSpecs(final StreamableOperatorInternals internals, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
if (m_autoType.getBooleanValue()) {
final SimpleStreamableOperatorInternals simpleInternals = (SimpleStreamableOperatorInternals) internals;
final Config config = simpleInternals.getConfig();
final DataColumnSpec[] colSpecs = new DataColumnSpec[config.getInt("sizeRow")];
for (int i = 0; i < colSpecs.length; i++) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(config.getString("colname" + i), config.getDataType("type" + i));
colSpecs[i] = dataColumnSpecCreator.createSpec();
}
return new DataTableSpec[] { new DataTableSpec(colSpecs) };
} else {
return configure(new DataTableSpec[] { (DataTableSpec) inSpecs[0] });
}
}
Aggregations