Search in sources :

Example 26 with DefaultHiLiteMapper

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)));
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) FileOutputStream(java.io.FileOutputStream) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper) File(java.io.File)

Example 27 with DefaultHiLiteMapper

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() };
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) RowKey(org.knime.core.data.RowKey) ArrayList(java.util.ArrayList) DataRow(org.knime.core.data.DataRow) DataValueComparator(org.knime.core.data.DataValueComparator) Entry(java.util.Map.Entry) BufferedDataTable(org.knime.core.node.BufferedDataTable) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) MutableInteger(org.knime.core.util.MutableInteger) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) HashMap(java.util.HashMap) Map(java.util.Map)

Example 28 with DefaultHiLiteMapper

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"))));
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper) File(java.io.File)

Example 29 with DefaultHiLiteMapper

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");
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper)

Example 30 with DefaultHiLiteMapper

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;
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) IOException(java.io.IOException) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper)

Aggregations

DefaultHiLiteMapper (org.knime.core.node.property.hilite.DefaultHiLiteMapper)35 File (java.io.File)16 FileOutputStream (java.io.FileOutputStream)16 NodeSettings (org.knime.core.node.NodeSettings)16 Set (java.util.Set)12 RowKey (org.knime.core.data.RowKey)12 BufferedDataTable (org.knime.core.node.BufferedDataTable)12 GZIPOutputStream (java.util.zip.GZIPOutputStream)9 DataRow (org.knime.core.data.DataRow)8 DataTableSpec (org.knime.core.data.DataTableSpec)8 DataCell (org.knime.core.data.DataCell)7 DefaultRow (org.knime.core.data.def.DefaultRow)7 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)7 HashMap (java.util.HashMap)6 LinkedHashSet (java.util.LinkedHashSet)6 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)6 LinkedHashMap (java.util.LinkedHashMap)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 DataColumnSpec (org.knime.core.data.DataColumnSpec)4