Search in sources :

Example 41 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class PolyRegLearnerSettings method loadSettingsFrom.

/**
 * Loads the settings from the node settings object.
 *
 * @param settings the node settings
 *
 * @throws InvalidSettingsException if one of the settings is missing
 */
public void loadSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_degree = settings.getInt("degree");
    m_targetColumn = settings.getString("targetColumn");
    m_maxRowsForView = settings.getInt("maxViewRows");
    // added v2.1
    boolean includeAll = settings.getBoolean("includeAll", false);
    // added in 2.10
    m_missingValueHandling = MissingValueHandling.valueOf(settings.getString(CFG_MISSING_VALUE_HANDLING, MissingValueHandling.ignore.name()));
    if (settings.containsKey("selectedColumns")) {
        // removed in 2.10
        String[] included = settings.getStringArray("selectedColumns");
        // we were able to load the old settings
        String[] excluded = new String[0];
        // but convert to new:
        NodeSettings fakeSettings = createFakeSettings(m_filterConfiguration.getConfigRootName(), included, excluded, includeAll);
        // added in 2.10
        m_filterConfiguration.loadConfigurationInModel(fakeSettings);
    } else {
        // no previous config: we should use the new config
        // added in 2.10
        NodeSettingsRO filterSettings = settings.getNodeSettings(m_filterConfiguration.getConfigRootName());
        NodeSettingsRO dtSettings = filterSettings.getNodeSettings("datatype");
        NodeSettingsRO tlSettings = dtSettings.getNodeSettings("typelist");
        if (!tlSettings.keySet().contains(DoubleValue.class.getName())) {
            NodeSettings fakeSettings = createFakeSettings(m_filterConfiguration.getConfigRootName(), new String[0], new String[0], false);
            m_filterConfiguration.loadConfigurationInModel(fakeSettings);
        } else {
            m_filterConfiguration.loadConfigurationInModel(settings);
        }
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Example 42 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class PolyRegLearnerSettings method createFakeSettings.

/**
 * Creates a fake configuration to help migrating the old configuration.
 *
 * @param configName Name of the {@link NodeSettings} to create.
 * @param included The included column names.
 * @param excluded The excluded column names.
 * @param includeAll Should we include all columns that are not in the exclude list ({@code true}), or use the include list ({@code false})?
 * @return The fake {@link NodeSettings}.
 */
static NodeSettings createFakeSettings(final String configName, final String[] included, final String[] excluded, final boolean includeAll) {
    NodeSettings fakeSettings = new NodeSettings("FakeRoot");
    NodeSettings filterSettings = (NodeSettings) fakeSettings.addNodeSettings(configName);
    filterSettings.addString("filter-type", "STANDARD");
    filterSettings.addStringArray("included_names", included);
    filterSettings.addStringArray("excluded_names", excluded);
    filterSettings.addString("enforce_option", (includeAll ? EnforceOption.EnforceExclusion : EnforceOption.EnforceInclusion).name());
    NodeSettings datatypeSettings = (NodeSettings) filterSettings.addNodeSettings("datatype");
    NodeSettingsWO typelist = datatypeSettings.addNodeSettings("typelist");
    typelist.addBoolean(DoubleValue.class.getName(), true);
    return fakeSettings;
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) DoubleValue(org.knime.core.data.DoubleValue)

Example 43 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class NumericScorerNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    NodeSettings set = new NodeSettings("scorer");
    set.addDouble(R2, m_rSquare);
    set.addDouble(MEAN_ABS_ERROR, m_meanAbsError);
    set.addDouble(MEAN_SQUARED_ERROR, m_meanSquaredError);
    set.addDouble(RMSD, m_rmsd);
    set.addDouble(MEAN_SIGNED_DIFFERENCE, m_meanSignedDifference);
    set.saveToXML(new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(new File(internDir, INTERNALS_XML_GZ)))));
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Example 44 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class HierarchicalClusterNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    File dataFile = new File(nodeInternDir, CFG_H_CLUST_DATA);
    DataContainer.writeToZip(m_dataArray, dataFile, exec);
    File distFile = new File(nodeInternDir, CFG_DIST_DATA);
    DataContainer.writeToZip(m_fusionTable, distFile, exec);
    NodeSettings settings = new NodeSettings(CFG_HCLUST);
    // no data -> no clustering nodes
    if (m_rootNode != null) {
        m_rootNode.saveToXML(settings);
    }
    File f = new File(nodeInternDir, CFG_HCLUST);
    FileOutputStream fos = new FileOutputStream(f);
    settings.saveToXML(fos);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 45 with NodeSettings

use of org.knime.core.node.NodeSettings in project knime-core by knime.

the class CreateBitVectorNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException {
    NodeSettings internSettings = new NodeSettings(FILE_NAME);
    internSettings.addInt(INT_CFG_ROWS, m_nrOfProcessedRows);
    internSettings.addInt(INT_CFG_NR_ZEROS, m_totalNrOf0s);
    internSettings.addInt(INT_CFG_NR_ONES, m_totalNrOf1s);
    File f = new File(internDir, FILE_NAME);
    FileOutputStream fos = new FileOutputStream(f);
    internSettings.saveToXML(fos);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

NodeSettings (org.knime.core.node.NodeSettings)156 File (java.io.File)58 FileOutputStream (java.io.FileOutputStream)57 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)37 GZIPOutputStream (java.util.zip.GZIPOutputStream)27 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)17 Test (org.junit.Test)16 NodeSettingsWO (org.knime.core.node.NodeSettingsWO)16 DefaultHiLiteMapper (org.knime.core.node.property.hilite.DefaultHiLiteMapper)16 IOException (java.io.IOException)14 OutputStream (java.io.OutputStream)12 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)11 BufferedOutputStream (java.io.BufferedOutputStream)9 Map (java.util.Map)8 RowKey (org.knime.core.data.RowKey)8 Config (org.knime.core.node.config.Config)8 LinkedHashMap (java.util.LinkedHashMap)7 DataTableSpec (org.knime.core.data.DataTableSpec)7 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)6 ArrayList (java.util.ArrayList)5