Search in sources :

Example 91 with NodeSettings

use of org.knime.core.node.NodeSettings 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 92 with NodeSettings

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

the class FixedPieDataModel method save2File.

/**
 * @param directory the directory to write to
 * @param exec the {@link ExecutionMonitor} to provide progress messages
 * @throws IOException if a file exception occurs
 * @throws CanceledExecutionException if the operation was canceled
 */
public void save2File(final File directory, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    if (exec != null) {
        exec.setProgress(0.0, "Start saving histogram data model to file");
    }
    final File dataFile = new File(directory, CFG_DATA_FILE);
    final FileOutputStream os = new FileOutputStream(dataFile);
    final GZIPOutputStream dataOS = new GZIPOutputStream(os);
    final Config config = new NodeSettings(CFG_DATA);
    config.addString(CFG_PIE_COL, m_pieCol);
    config.addBoolean(CFG_NUMERIC_PIE_COL, m_numericPieCol);
    config.addString(CFG_AGGR_COL, m_aggrCol);
    config.addBoolean(CFG_HILITING, supportsHiliting());
    config.addBoolean(CFG_DETAILS, detailsAvailable());
    config.addBoolean(CFG_IS_COLOR_COLUMN, m_isColorColumn);
    if (exec != null) {
        exec.setProgress(0.3, "Start saving sections...");
        exec.checkCanceled();
    }
    final Config sectionsConf = config.addConfig(CFG_SECTIONS);
    sectionsConf.addInt(CFG_SECTION_COUNT, m_sections.size());
    int idx = 0;
    for (final PieSectionDataModel section : m_sections) {
        final ConfigWO sectionConf = sectionsConf.addConfig(CFG_SECTION + idx++);
        section.save2File(sectionConf, exec);
    }
    if (exec != null) {
        exec.setProgress(0.8, "Start saving missing section...");
        exec.checkCanceled();
    }
    final ConfigWO missingSection = sectionsConf.addConfig(CFG_MISSING_SECTION);
    m_missingSection.save2File(missingSection, exec);
    config.saveToXML(dataOS);
    dataOS.flush();
    dataOS.close();
    os.flush();
    os.close();
    if (exec != null) {
        exec.setProgress(1.0, "Pie data model saved");
    }
}
Also used : PieSectionDataModel(org.knime.base.node.viz.pie.datamodel.PieSectionDataModel) NodeSettings(org.knime.core.node.NodeSettings) GZIPOutputStream(java.util.zip.GZIPOutputStream) Config(org.knime.core.node.config.Config) FileOutputStream(java.io.FileOutputStream) ConfigWO(org.knime.core.node.config.ConfigWO) File(java.io.File)

Example 93 with NodeSettings

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

the class PolyRegLearnerDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    DataTableSpec dataTableSpec = (DataTableSpec) specs[0];
    try {
        m_settings.loadSettingsInDialog(settings, dataTableSpec);
    } catch (InvalidSettingsException ex) {
        LinkedHashSet<String> defSelected = new LinkedHashSet<String>();
        for (DataColumnSpec s : dataTableSpec) {
            if (s.getType().isCompatible(DoubleValue.class)) {
                defSelected.add(s.getName());
            }
        }
        NodeSettings fakeSettings = PolyRegLearnerSettings.createFakeSettings("column filter", defSelected.toArray(new String[0]), new String[0], false);
        DataColumnSpecFilterConfiguration conf = new DataColumnSpecFilterConfiguration("column filter");
        conf.loadConfigurationInDialog(fakeSettings, dataTableSpec);
        m_settings.getFilterConfiguration().loadConfigurationInDialog(fakeSettings, dataTableSpec);
    // for the rest: ignore it, defaults are used instead
    }
    m_targetColumn.update(dataTableSpec, m_settings.getTargetColumn());
    m_degree.getModel().setValue(m_settings.getDegree());
    m_viewRows.getModel().setValue(m_settings.getMaxRowsForView());
    m_colSelectionPanel.loadConfiguration(m_settings.getFilterConfiguration(), dataTableSpec);
    m_colSelectionPanel.resetHiding();
    m_colSelectionPanel.hideNames((DataColumnSpec) m_targetColumn.getSelectedItem());
    m_missingValueHandlingIgnore.setSelected(m_settings.getMissingValueHandling().equals(MissingValueHandling.ignore));
    m_missingValueHandlingFail.setSelected(m_settings.getMissingValueHandling().equals(MissingValueHandling.fail));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataTableSpec(org.knime.core.data.DataTableSpec) NodeSettings(org.knime.core.node.NodeSettings) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DoubleValue(org.knime.core.data.DoubleValue) DataColumnSpecFilterConfiguration(org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration)

Example 94 with NodeSettings

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

the class AccuracyScorerNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException {
    NodeSettings set = new NodeSettings("scorer");
    set.addInt("correctCount", m_viewData.getCorrectCount());
    set.addInt("falseCount", m_viewData.getFalseCount());
    set.addInt("nrRows", m_viewData.getNrRows());
    set.addStringArray("values", m_viewData.getTargetValues());
    final int targetValueCount = m_viewData.getTargetValues().length;
    for (int i = 0; i < targetValueCount; i++) {
        NodeSettingsWO sub = set.addNodeSettings(m_viewData.getTargetValues()[i]);
        sub.addIntArray("scorerCount", m_viewData.getScorerCount()[i]);
        NodeSettingsWO subSub = sub.addNodeSettings("hilightMap");
        for (int j = 0; j < targetValueCount; j++) {
            NodeSettingsWO sub3 = subSub.addNodeSettings(m_viewData.getTargetValues()[j]);
            RowKey[] rowKeys = m_viewData.getKeyStore()[i][j].toArray(new RowKey[m_viewData.getKeyStore()[i][j].size()]);
            sub3.addRowKeyArray("keyStore", rowKeys);
        }
    }
    set.saveToXML(new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(new File(internDir, "internals.xml.gz")))));
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) RowKey(org.knime.core.data.RowKey) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Example 95 with NodeSettings

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

the class EntropyCalculator method save.

/**
 * Saves the structure of this objec to the target directory.
 *
 * @param dir to save to
 * @param exec for progress/cancel
 * @throws IOException if that fails
 * @throws CanceledExecutionException if canceled
 */
public void save(final File dir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    File scorerFile = new File(dir, FILE_SCORER_TABLE);
    DataContainer.writeToZip(m_scoreTable, scorerFile, exec);
    File settingsFile = new File(dir, FILE_SETTINGS);
    NodeSettings config = new NodeSettings(CFG_SETTINGS);
    config.addDouble(CFG_ENTROPY, m_entropy);
    config.addDouble(CFG_QUALITY, m_quality);
    config.addInt(CFG_PAT_IN_CLUSTER, m_patternsInClusters);
    config.addInt(CFG_PAT_IN_REFERENCE, m_patternsInReference);
    config.addInt(CFG_NR_CLUSTER, m_nrClusters);
    config.addInt(CFG_NR_REFERENCES, m_nrReference);
    NodeSettingsWO subConfig = config.addNodeSettings(CFG_CLUSTERING_MAP);
    for (Map.Entry<RowKey, Set<RowKey>> entry : m_clusteringMap.entrySet()) {
        exec.checkCanceled();
        RowKey key = entry.getKey();
        Set<RowKey> values = entry.getValue();
        NodeSettingsWO keySettings = subConfig.addNodeSettings(key.toString());
        keySettings.addRowKey(key.toString(), key);
        keySettings.addRowKeyArray(CFG_MAPPED_KEYS, values.toArray(new RowKey[values.size()]));
    }
    config.saveToXML(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(settingsFile))));
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) RowKey(org.knime.core.data.RowKey) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) BufferedOutputStream(java.io.BufferedOutputStream)

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