Search in sources :

Example 31 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class PMMLCompoundPredicate method saveToPredParams.

/**
 * {@inheritDoc}
 */
@Override
public void saveToPredParams(final Config conf) {
    conf.addString(PMMLPredicate.TYPE_KEY, NAME);
    conf.addString(PMMLPredicate.OPERATOR_KEY, m_op.toString());
    String splitAttribute = getSplitAttribute();
    conf.addString(PMMLPredicate.ATTRIBUTE_KEY, splitAttribute);
    conf.addInt(NUM_PREDICATES, m_predicates.size());
    int i = 0;
    for (PMMLPredicate pred : m_predicates) {
        Config pconf = conf.addConfig(PRED + i++);
        pred.saveToPredParams(pconf);
    }
}
Also used : Config(org.knime.core.node.config.Config)

Example 32 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class DecisionTreeNode method saveToPredictorParams.

// ////////////////////////////////////
// Save & Load to/from ModelContent
// ////////////////////////////////////
/**
 * Save node to a model content object.
 *
 * @param predParams configuration object to attach decision tree to
 * @param saveColorsAndKeys whether to save the colors and the row keys
 */
public void saveToPredictorParams(final ModelContentWO predParams, final boolean saveColorsAndKeys) {
    predParams.addDataCell("class", m_class);
    predParams.addDouble("allClassFreq", m_allClassFreq);
    predParams.addDouble("ownClassFreq", m_ownClassFreq);
    predParams.addInt("ownIndex", m_ownIndex);
    predParams.addString("prefix", m_prefix);
    predParams.addBoolean("newColors", m_newColors);
    // also write out frequencies of all classes
    DataCell[] keys = new DataCell[m_classCounts.size()];
    double[] values = new double[m_classCounts.size()];
    int i = 0;
    for (Entry<DataCell, Double> mapIt : m_classCounts.entrySet()) {
        keys[i] = mapIt.getKey();
        values[i] = mapIt.getValue();
        i++;
    }
    predParams.addDataCellArray("classes", keys);
    predParams.addDoubleArray("frequencies", values);
    // need to re-create when loading this node...
    if (this instanceof DecisionTreeNodeLeaf) {
        predParams.addString("className", "LeafNode");
    } else if (this instanceof DecisionTreeNodeSplitContinuous) {
        predParams.addString("className", "ContinuousSplit");
    } else if (this instanceof DecisionTreeNodeSplitNominal) {
        predParams.addString("className", "NominalSplit");
    } else if (this instanceof DecisionTreeNodeSplitPMML) {
        predParams.addString("className", "PMMLPredicateSplit");
    } else {
        LOGGER.error("DecisionTreeNode.saveToPredictorParams() doesn't" + " know this node type: " + this.getClass().getName());
    }
    // and finally save all internals of the derived class as well
    saveNodeInternalsToPredParams(predParams, saveColorsAndKeys);
    // if the keys and colors are supposed to be stored
    if (saveColorsAndKeys) {
        Config colorsConfig = predParams.addConfig(CONFIG_KEY_COLORS);
        int counter = 0;
        for (Entry<Color, Double> entry : m_coveredColors.entrySet()) {
            Config colorConfig = colorsConfig.addConfig(CONFIG_KEY_COLOR + "_" + counter);
            colorConfig.addInt(CONFIG_KEY_RED, entry.getKey().getRed());
            colorConfig.addInt(CONFIG_KEY_GREEN, entry.getKey().getGreen());
            colorConfig.addInt(CONFIG_KEY_BLUE, entry.getKey().getBlue());
            colorConfig.addDouble(CONFIG_KEY_COUNT, entry.getValue());
            counter++;
        }
    }
}
Also used : Config(org.knime.core.node.config.Config) Color(java.awt.Color) DataCell(org.knime.core.data.DataCell)

Example 33 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class DiscretizationModel method save.

/**
 * {@inheritDoc}
 * <p />
 * IMPORTANT NOTE: This method DOES NOT save the table spec of included
 * columns. This table spec must be saved before (by calling getSpec and
 * saving the returned object).
 */
@Override
protected void save(final ModelContentWO model, final ExecutionMonitor exec) throws CanceledExecutionException {
    Config schemesConfig = model.addConfig(CONFIG_KEY_SCHEMES);
    int i = 0;
    for (DiscretizationScheme scheme : m_schemes) {
        if (exec != null) {
            exec.checkCanceled();
        }
        Config schemeConfig = schemesConfig.addConfig(CONFIG_KEY_SCHEME_PREFIX + m_includedColumnNames.getColumnSpec(i).getName());
        scheme.saveToModelContent(schemeConfig);
        i++;
    }
}
Also used : Config(org.knime.core.node.config.Config)

Example 34 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class DiscretizationScheme method saveToModelContent.

/**
 * Saves this scheme to a {@link org.knime.core.node.ModelContentWO} object.
 *
 * @param modelContent the {@link Config} object to store the
 *            {@link DiscretizationScheme} to
 */
public void saveToModelContent(final Config modelContent) {
    int i = 0;
    for (Interval interval : m_intervals) {
        Config intervalConfig = modelContent.addConfig(CONFIG_KEY_INTERVAL_PREFIX + i);
        interval.saveToModelContent(intervalConfig);
        i++;
    }
}
Also used : Config(org.knime.core.node.config.Config)

Example 35 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class AggregationValModel method save2File.

/**
 * @param config the config object to use
 * @param exec the {@link ExecutionMonitor} to provide progress messages
 * @throws CanceledExecutionException if the operation is canceled
 */
public void save2File(final ConfigWO config, final ExecutionMonitor exec) throws CanceledExecutionException {
    config.addString(CFG_BAR_NAME, getName());
    config.addInt(CFG_COLOR_RGB, getColor().getRGB());
    config.addInt(CFG_ROW_COUNTER, getRowCount());
    config.addInt(CFG_VALUE_COUNTER, getValueCount());
    config.addDouble(CFG_AGGR_SUM, getAggregationSum());
    config.addBoolean(CFG_HILITING, supportsHiliting());
    final Config subConfig = config.addConfig(CFG_SUBMODELS);
    saveElements(getElements(), subConfig, exec);
}
Also used : Config(org.knime.core.node.config.Config)

Aggregations

Config (org.knime.core.node.config.Config)84 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)25 Color (java.awt.Color)10 File (java.io.File)10 FileOutputStream (java.io.FileOutputStream)8 NodeSettings (org.knime.core.node.NodeSettings)8 ArrayList (java.util.ArrayList)7 DataColumnSpec (org.knime.core.data.DataColumnSpec)7 ConfigRO (org.knime.core.node.config.ConfigRO)7 HashMap (java.util.HashMap)6 GZIPOutputStream (java.util.zip.GZIPOutputStream)6 LinkedHashMap (java.util.LinkedHashMap)5 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)5 DataTableSpec (org.knime.core.data.DataTableSpec)5 SimpleStreamableOperatorInternals (org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)5 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 DataCell (org.knime.core.data.DataCell)4