Search in sources :

Example 6 with GroupKey

use of org.knime.base.node.preproc.groupby.GroupKey in project knime-core by knime.

the class NumericOutliersModel method saveModel.

/**
 * Save the model to the provided model content.
 *
 * @param model the model to save to
 */
void saveModel(final ModelContentWO model) {
    // store groups and outlier column names
    model.addStringArray(CFG_GROUP_COL_NAMES, m_groupColNames);
    model.addStringArray(CFG_OUTLIER_COL_NAMES, m_outlierColNames);
    // store the permitted intervals for each group and outlier column
    final ModelContentWO data = model.addModelContent(CFG_DATA);
    int rowCount = 0;
    for (Entry<GroupKey, Map<String, double[]>> entry : m_permIntervals.entrySet()) {
        final ModelContentWO rowContent = data.addModelContent(CFG_ROW + rowCount++);
        // store the group key
        rowContent.addModelContent("key").addDataCellArray(CFG_GROUP_KEY, entry.getKey().getGroupVals());
        // store the permitted intervals for the given key
        ModelContentWO intervalCols = rowContent.addModelContent(CFG_INTERVAL_COLUMNS);
        int intervalCount = 0;
        for (Entry<String, double[]> interval : entry.getValue().entrySet()) {
            final ModelContentWO rowIntervalContent = intervalCols.addModelContent(CFG_INTERVAL + intervalCount++);
            rowIntervalContent.addString("outlier", interval.getKey());
            rowIntervalContent.addDoubleArray(CFG_INTERVAL, interval.getValue());
        }
    }
}
Also used : ModelContentWO(org.knime.core.node.ModelContentWO) GroupKey(org.knime.base.node.preproc.groupby.GroupKey) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 7 with GroupKey

use of org.knime.base.node.preproc.groupby.GroupKey in project knime-core by knime.

the class NumericOutliersModel method loadModel.

/**
 * Loads the information provided by the model content into the model.
 *
 * @param model the model content to be loaded
 * @throws InvalidSettingsException if the outliers defined by the model content differs from the outliers defining
 *             the intervals
 */
@SuppressWarnings("unchecked")
private void loadModel(final ModelContentRO model) throws InvalidSettingsException {
    final Enumeration<ModelContentRO> rowContents = model.children();
    while (rowContents.hasMoreElements()) {
        // acess the current group
        final ModelContentRO rowContent = rowContents.nextElement();
        // load the group key
        final GroupKey key = new GroupKey(rowContent.getModelContent("key").getDataCellArray(CFG_GROUP_KEY));
        // load all intervals for the current group key
        ModelContentRO intervalCols = rowContent.getModelContent(CFG_INTERVAL_COLUMNS);
        final Enumeration<ModelContentRO> intervalContents = intervalCols.children();
        while (intervalContents.hasMoreElements()) {
            final ModelContentRO intervalContent = intervalContents.nextElement();
            addEntry(key, intervalContent.getString("outlier"), intervalContent.getDoubleArray(CFG_INTERVAL));
        }
    }
}
Also used : ModelContentRO(org.knime.core.node.ModelContentRO) GroupKey(org.knime.base.node.preproc.groupby.GroupKey)

Aggregations

GroupKey (org.knime.base.node.preproc.groupby.GroupKey)7 DataCell (org.knime.core.data.DataCell)3 DataRow (org.knime.core.data.DataRow)3 DataTableSpec (org.knime.core.data.DataTableSpec)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 DoubleValue (org.knime.core.data.DoubleValue)2 ModelContentRO (org.knime.core.node.ModelContentRO)2 ModelContentWO (org.knime.core.node.ModelContentWO)2 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 AbstractCellFactory (org.knime.core.data.container.AbstractCellFactory)1 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)1