use of org.knime.core.node.config.ConfigRO 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.ConfigRO in project knime-core by knime.
the class VirtualParallelizedChunkPortObjectInNodeFactory method loadPortTypeList.
/**
* @param config
* @return TODO
* @throws InvalidSettingsException
*/
static PortType[] loadPortTypeList(final ConfigRO config) throws InvalidSettingsException {
Set<String> keySet = config.keySet();
PortType[] outTypes = new PortType[keySet.size()];
for (String s : keySet) {
ConfigRO portConfig = config.getConfig(s);
int index = portConfig.getInt("index");
CheckUtils.checkSetting(index >= 0 && index < outTypes.length, "Invalid port index must be in [0, %d]: %d", keySet.size() - 1, index);
Config portTypeConfig = portConfig.getConfig("type");
PortType type = PortType.load(portTypeConfig);
outTypes[index] = type;
}
int invalidIndex = Arrays.asList(outTypes).indexOf(null);
if (invalidIndex >= 0) {
throw new InvalidSettingsException("Unassigned port type at index " + invalidIndex);
}
return outTypes;
}
use of org.knime.core.node.config.ConfigRO in project knime-core by knime.
the class ColorModelNominal method load.
/**
* Read color settings from given <code>Config</code> and returns a new
* <code>ColorModelNominal</code> object.
* @param config Reads color model from.
* @return A new <code>ColorModelNominal</code> object.
* @throws InvalidSettingsException If the color model settings could not
* be read.
* @throws NullPointerException If the <i>config</i> is <code>null</code>.
*/
public static ColorModelNominal load(final ConfigRO config) throws InvalidSettingsException {
Map<DataCell, ColorAttr> map = new LinkedHashMap<>();
ConfigRO keyConfig = config.getConfig(CFG_KEYS);
for (String key : keyConfig.keySet()) {
Color color;
try {
// load color components before 2.0
int[] v = config.getIntArray(key.toString());
color = new Color(v[0], v[1], v[2], v[3]);
} catch (InvalidSettingsException ise) {
color = new Color(config.getInt(key.toString()), true);
}
DataCell cell = keyConfig.getDataCell(key);
map.put(cell, ColorAttr.getInstance(color));
}
return new ColorModelNominal(map);
}
use of org.knime.core.node.config.ConfigRO in project knime-core by knime.
the class DefaultHiLiteMapper method load.
/**
* Restores the mapper from the config object that has been written using
* the save method.
* @param config To read from
* @return A new mapper based on the settings.
* @throws InvalidSettingsException If that fails.
*/
public static DefaultHiLiteMapper load(final ConfigRO config) throws InvalidSettingsException {
// load hilite mapping
LinkedHashMap<RowKey, Set<RowKey>> mapping = new LinkedHashMap<RowKey, Set<RowKey>>();
for (String key : config.keySet()) {
ConfigRO keySettings = config.getConfig(key);
String cellKey;
try {
// load keys before 2.0
cellKey = keySettings.getDataCell(key).toString();
} catch (InvalidSettingsException ise) {
cellKey = keySettings.getString(key);
}
Set<RowKey> keySet;
try {
// load mapping before 2.0
DataCell[] mappedKeys = keySettings.getDataCellArray(CFG_MAPPED_KEYS);
keySet = new LinkedHashSet<RowKey>();
for (DataCell dc : mappedKeys) {
keySet.add(new RowKey(dc.toString()));
}
} catch (InvalidSettingsException ise) {
RowKey[] mappedKeys = keySettings.getRowKeyArray(CFG_MAPPED_KEYS);
keySet = new LinkedHashSet<RowKey>(Arrays.asList(mappedKeys));
}
mapping.put(new RowKey(cellKey), keySet);
}
return new DefaultHiLiteMapper(mapping);
}
use of org.knime.core.node.config.ConfigRO in project knime-core by knime.
the class DataTableSpec method load.
/**
* Reads all {@link DataColumnSpec} objects from the given {@link ConfigRO}
* and returns a new <code>DataTableSpec</code> object containing them.
*
* @param config object to read column specs from
* @return a new table spec object containing the just read columns
* @throws InvalidSettingsException if the name, number of columns, or a
* column spec could not be read
*/
public static DataTableSpec load(final ConfigRO config) throws InvalidSettingsException {
String name = config.getString(CFG_SPEC_NAME);
int ncols = config.getInt(CFG_NR_COLUMNS);
DataColumnSpec[] specs = new DataColumnSpec[ncols];
for (int i = 0; i < ncols; i++) {
ConfigRO column = config.getConfig(CFG_COLUMN_SPEC + i);
specs[i] = DataColumnSpec.load(column);
}
Map<String, String> map;
if (config.containsKey(CFG_PROPERTIES)) {
map = new LinkedHashMap<String, String>();
ConfigRO propertiesConfig = config.getConfig(CFG_PROPERTIES);
for (String s : propertiesConfig.keySet()) {
ConfigRO entryConfig = propertiesConfig.getConfig(s);
String key = entryConfig.getString(CFG_PROPERTY_KEY);
if (key == null || key.length() == 0) {
throw new InvalidSettingsException("Invalid property key (empty or null)");
}
String value = entryConfig.getString(CFG_PROPERTY_VALUE);
if (map.put(key, value) != null) {
throw new InvalidSettingsException("Duplicate key identifier \"" + key + "\"");
}
}
} else {
map = Collections.emptyMap();
}
return new DataTableSpec(name, specs, map);
}
Aggregations