Search in sources :

Example 56 with NodeSettings

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

the class RowKeyNodeModel2 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 57 with NodeSettings

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

the class BoxPlotNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    try {
        File f = new File(nodeInternDir, FILE_NAME);
        FileInputStream fis = new FileInputStream(f);
        NodeSettingsRO settings = NodeSettings.loadFromXML(fis);
        m_statistics = new LinkedHashMap<DataColumnSpec, double[]>();
        m_mildOutliers = new LinkedHashMap<String, Map<Double, Set<RowKey>>>();
        m_extremeOutliers = new LinkedHashMap<String, Map<Double, Set<RowKey>>>();
        int nrOfCols = settings.getInt(CFG_NR_COLS);
        for (int i = 0; i < nrOfCols; i++) {
            NodeSettings subSetting = (NodeSettings) settings.getConfig(CFG_COL + i);
            DataColumnSpec spec = DataColumnSpec.load(subSetting);
            double[] stats = settings.getDoubleArray(CFG_STATS + spec.getName());
            m_statistics.put(spec, stats);
            loadOutliers(settings, spec);
        }
        File data = new File(nodeInternDir, ARRAY_FILE);
        ContainerTable table = DataContainer.readFromZip(data);
        m_array = new DefaultDataArray(table, 1, 2, exec);
    } catch (Exception e) {
        LOGGER.warn(e);
        throw new IOException(e.getMessage());
    }
}
Also used : RowKey(org.knime.core.data.RowKey) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ContainerTable(org.knime.core.data.container.ContainerTable) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) NodeSettings(org.knime.core.node.NodeSettings) DataColumnSpec(org.knime.core.data.DataColumnSpec) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 58 with NodeSettings

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

the class BoxPlotNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    try {
        NodeSettings settings = new NodeSettings(FILE_NAME);
        settings.addInt(CFG_NR_COLS, m_statistics.size());
        int i = 0;
        for (DataColumnSpec spec : m_statistics.keySet()) {
            NodeSettings colSetting = (NodeSettings) settings.addConfig(CFG_COL + i++);
            spec.save(colSetting);
        }
        for (Map.Entry<DataColumnSpec, double[]> entry : m_statistics.entrySet()) {
            String cfgName = entry.getKey().getName();
            settings.addDoubleArray(CFG_STATS + cfgName, entry.getValue());
            // mild outliers
            Map<Double, Set<RowKey>> mildOutliers = m_mildOutliers.get(cfgName);
            double[] mild = new double[mildOutliers.size()];
            Config mildKeysSubConfig = settings.addConfig(CFG_MILD + CFG_ROW + cfgName);
            int j = 0;
            for (Map.Entry<Double, Set<RowKey>> mildEntry : mildOutliers.entrySet()) {
                mild[j] = mildEntry.getKey();
                // save method -> savely store string from now on
                String[] keys = new String[mildEntry.getValue().size()];
                int rk = 0;
                for (RowKey key : mildEntry.getValue()) {
                    keys[rk] = key.getString();
                    rk++;
                }
                mildKeysSubConfig.addStringArray(CFG_MILD + CFG_ROW + cfgName + j, keys);
                j++;
            }
            settings.addDoubleArray(CFG_MILD + cfgName, mild);
            // settings.addDataCellArray(CFG_MILD + CFG_ROW + cfgName, mildKeys);
            Map<Double, Set<RowKey>> extremeOutliers = m_extremeOutliers.get(cfgName);
            double[] extreme = new double[extremeOutliers.size()];
            int ext = 0;
            Config extKeysSubConfig = settings.addConfig(CFG_EXTREME + CFG_ROW + cfgName);
            for (Map.Entry<Double, Set<RowKey>> extrEntry : extremeOutliers.entrySet()) {
                extreme[ext] = extrEntry.getKey();
                // save method -> save store strings from now on
                String[] keys = new String[extrEntry.getValue().size()];
                int rk = 0;
                for (RowKey key : extrEntry.getValue()) {
                    keys[rk] = key.getString();
                    rk++;
                }
                extKeysSubConfig.addStringArray(CFG_EXTREME + CFG_ROW + cfgName + ext, keys);
                ext++;
            }
            settings.addDoubleArray(CFG_EXTREME + cfgName, extreme);
        // settings.addDataCellArray(CFG_EXTREME + CFG_ROW + cfgName,
        // extremeKeys);
        }
        File f = new File(nodeInternDir, FILE_NAME);
        FileOutputStream fos = new FileOutputStream(f);
        settings.saveToXML(fos);
        File dataFile = new File(nodeInternDir, ARRAY_FILE);
        DataContainer.writeToZip(m_array, dataFile, exec);
    } catch (IOException e) {
        LOGGER.warn(e);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) RowKey(org.knime.core.data.RowKey) Config(org.knime.core.node.config.Config) IOException(java.io.IOException) NodeSettings(org.knime.core.node.NodeSettings) DataColumnSpec(org.knime.core.data.DataColumnSpec) FileOutputStream(java.io.FileOutputStream) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File)

Example 59 with NodeSettings

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

the class TypeSelectionConfiguration method saveSettings.

/**
 * {@inheritDoc}
 */
@Override
public void saveSettings(final NodeSettingsWO settings) {
    settings.addInt("numberOfPanels", m_panelList.size());
    List<DropPaneConfig> values = Arrays.asList(m_panelList.values().toArray(new DropPaneConfig[m_panelList.size()]));
    Collections.sort(values);
    for (int i = 0; i < values.size(); i++) {
        DropPaneConfig dpc = values.get(i);
        PaneConfigurationDialog p = dpc.getDialog();
        NodeSettings n = new NodeSettings("dialogSettings_" + i);
        p.saveSettings(n);
        settings.addNodeSettings(n);
        settings.addString("panelIndex_" + i, dpc.getSelectionAsString());
    // settings.addInt("panelIndex" + i, p.getIndex());
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) DropPaneConfig(org.knime.base.node.preproc.draganddroppanel.droppanes.DropPaneConfig)

Example 60 with NodeSettings

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

the class EqualSizeSamplingNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    if (m_configuration == null) {
        EqualSizeSamplingConfiguration c = new EqualSizeSamplingConfiguration();
        try {
            c.loadConfigurationInDialog(new NodeSettings("empty"), inSpecs[0]);
        } catch (NotConfigurableException e) {
            throw new InvalidSettingsException("Can't auto-guess settings: " + "No nominal column in input");
        }
        m_configuration = c;
        setWarningMessage("Auto-guessing \"" + c.getClassColumn() + "\" as selected nominal class column");
    }
    String classColumn = m_configuration.getClassColumn();
    DataColumnSpec col = inSpecs[0].getColumnSpec(classColumn);
    if (col == null) {
        throw new InvalidSettingsException("No column \"" + classColumn + "\" in input data");
    }
    if (!col.getType().isCompatible(NominalValue.class)) {
        throw new InvalidSettingsException("Class column \"" + classColumn + "\" is not a nominal attribute");
    }
    return new DataTableSpec[] { inSpecs[0] };
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) NodeSettings(org.knime.core.node.NodeSettings) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NominalValue(org.knime.core.data.NominalValue)

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