use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class RowKeyNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
if (m_enableHilite.getBooleanValue()) {
final NodeSettings config = new NodeSettings("hilite_mapping");
final DefaultHiLiteMapper mapper = (DefaultHiLiteMapper) m_hilite.getMapper();
if (mapper != null) {
mapper.save(config);
}
config.saveToXML(new FileOutputStream(new File(nodeInternDir, INTERNALS_FILE_NAME)));
}
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class ValueCounterNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
final int colIndex = inData[0].getDataTableSpec().findColumnIndex(m_settings.columnName());
final double max = inData[0].getRowCount();
int rowCount = 0;
Map<DataCell, Set<RowKey>> hlMap = new HashMap<DataCell, Set<RowKey>>();
Map<DataCell, MutableInteger> countMap = new HashMap<DataCell, MutableInteger>();
for (DataRow row : inData[0]) {
exec.checkCanceled();
exec.setProgress(rowCount++ / max, countMap.size() + " different values found");
DataCell cell = row.getCell(colIndex);
MutableInteger count = countMap.get(cell);
if (count == null) {
count = new MutableInteger(0);
countMap.put(cell, count);
}
count.inc();
if (m_settings.hiliting()) {
Set<RowKey> s = hlMap.get(cell);
if (s == null) {
s = new HashSet<RowKey>();
hlMap.put(cell, s);
}
s.add(row.getKey());
}
}
final DataValueComparator comp = inData[0].getDataTableSpec().getColumnSpec(colIndex).getType().getComparator();
List<Map.Entry<DataCell, MutableInteger>> sorted = new ArrayList<Map.Entry<DataCell, MutableInteger>>(countMap.entrySet());
Collections.sort(sorted, new Comparator<Map.Entry<DataCell, MutableInteger>>() {
public int compare(final Map.Entry<DataCell, MutableInteger> o1, final Entry<DataCell, MutableInteger> o2) {
return comp.compare(o1.getKey(), o2.getKey());
}
});
BufferedDataContainer cont = exec.createDataContainer(TABLE_SPEC);
for (Map.Entry<DataCell, MutableInteger> entry : sorted) {
RowKey newKey = new RowKey(entry.getKey().toString());
cont.addRowToTable(new DefaultRow(newKey, new int[] { entry.getValue().intValue() }));
}
cont.close();
if (m_settings.hiliting()) {
Map<RowKey, Set<RowKey>> temp = new HashMap<RowKey, Set<RowKey>>();
for (Map.Entry<DataCell, Set<RowKey>> entry : hlMap.entrySet()) {
RowKey newKey = new RowKey(entry.getKey().toString());
temp.put(newKey, entry.getValue());
}
m_translator.setMapper(new DefaultHiLiteMapper(temp));
}
return new BufferedDataTable[] { cont.getTable() };
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class Unpivot2NodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
if (m_enableHilite.getBooleanValue()) {
final NodeSettings config = new NodeSettings("hilite_mapping");
((DefaultHiLiteMapper) m_trans.getMapper()).save(config);
config.saveToXML(new GZIPOutputStream(new FileOutputStream(new File(nodeInternDir, "hilite_mapping.xml.gz"))));
}
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class RowKeyNodeModel2 method replaceKey.
/* called if the row key is to be replaced */
private void replaceKey(final RowInput rowInput, final RowOutput rowOutput, final int totalNoOfOutCols, final int totalNoOfRows, final ExecutionContext exec) throws Exception {
assert m_replaceKey.getBooleanValue();
final boolean ensureUniqueness = m_ensureUniqueness.isEnabled() && m_ensureUniqueness.getBooleanValue();
final boolean handleMissing = m_handleMissingVals.isEnabled() && m_handleMissingVals.getBooleanValue();
final boolean removeRowKeyCol = m_removeRowKeyCol.isEnabled() && m_removeRowKeyCol.getBooleanValue();
LOGGER.debug("The user wants to replace the row ID with the" + " column " + m_newColumnName.getStringValue() + " optional appended column name" + m_appendRowKey.getBooleanValue());
if (m_newRowKeyColumn.getStringValue() != null) {
// the user wants a new column as rowkey column
final int colIdx = rowInput.getDataTableSpec().findColumnIndex(m_newRowKeyColumn.getStringValue());
if (colIdx < 0) {
throw new InvalidSettingsException("No column with name: " + m_newColumnName.getStringValue() + " exists. Please select a valid column name.");
}
}
DataColumnSpec newColSpec = null;
if (m_appendRowKey.getBooleanValue()) {
final String newColName = m_newColumnName.getStringValue();
newColSpec = createAppendRowKeyColSpec(newColName);
}
final RowKeyUtil2 util = new RowKeyUtil2();
util.changeRowKey(rowInput, rowOutput, exec, m_newRowKeyColumn.getStringValue(), m_appendRowKey.getBooleanValue(), newColSpec, ensureUniqueness, handleMissing, removeRowKeyCol, m_enableHilite.getBooleanValue(), totalNoOfOutCols, totalNoOfRows);
if (m_enableHilite.getBooleanValue()) {
m_hilite.setMapper(new DefaultHiLiteMapper(util.getHiliteMapping()));
}
final int missingValueCounter = util.getMissingValueCounter();
final int duplicatesCounter = util.getDuplicatesCounter();
final StringBuilder warningMsg = new StringBuilder();
if (duplicatesCounter > 0) {
warningMsg.append(duplicatesCounter + " duplicate(s) now unique. ");
}
if (missingValueCounter > 0) {
warningMsg.append(missingValueCounter + " missing value(s) replaced with " + RowKeyUtil2.MISSING_VALUE_REPLACEMENT + ".");
}
if (warningMsg.length() > 0) {
setWarningMessage(warningMsg.toString());
}
LOGGER.debug("Row ID replaced successfully");
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class EntropyNodeModel method loadInternals.
/**
* {@inheritDoc}
*/
@Override
protected void loadInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
try {
m_calculator = EntropyCalculator.load(internDir, exec);
m_translator.setMapper(new DefaultHiLiteMapper(m_calculator.getClusteringMap()));
} catch (InvalidSettingsException ise) {
IOException ioe = new IOException("Unable to read settings.");
ioe.initCause(ise);
throw ioe;
}
}
Aggregations