Search in sources :

Example 21 with NodeSettingsRO

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

the class CrosstabNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
    if (m_settings.getEnableHiliting()) {
        final NodeSettingsRO config = NodeSettings.loadFromXML(new FileInputStream(new File(nodeInternDir, INTERNALS_FILE_NAME)));
        try {
            setHiliteMapping(DefaultHiLiteMapper.load(config));
            m_hilite.addToHiLiteHandler(getInHiLiteHandler(0));
        } catch (final InvalidSettingsException ex) {
            throw new IOException(ex.getMessage());
        }
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 22 with NodeSettingsRO

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

the class ValueCounterNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    File f = new File(nodeInternDir, "Hiliting.conf.gz");
    if (f.exists() && f.canRead()) {
        InputStream in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(f)));
        NodeSettingsRO s = NodeSettings.loadFromXML(in);
        in.close();
        try {
            m_translator.setMapper(DefaultHiLiteMapper.load(s));
        } catch (InvalidSettingsException ex) {
            throw new IOException(ex);
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 23 with NodeSettingsRO

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

the class BasisFunctionLearnerNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    // load model info
    exec.checkCanceled();
    exec.setProgress(0.1, "Loading model information");
    File file = new File(internDir, MODEL_INFO_FILE_NAME);
    m_modelInfo = (ModelContent) ModelContent.loadFromXML(new GZIPInputStream(new BufferedInputStream(new FileInputStream(file))));
    // load hilite mapping
    exec.checkCanceled();
    exec.setProgress(0.5, "Loading hilite mapping");
    File mappingFile = new File(internDir, HILITE_MAPPING_FILE_NAME);
    NodeSettingsRO mapSettings = NodeSettings.loadFromXML(new GZIPInputStream(new BufferedInputStream(new FileInputStream(mappingFile))));
    try {
        m_translator.setMapper(DefaultHiLiteMapper.load(mapSettings));
    } catch (InvalidSettingsException ise) {
        throw new IOException(ise.getMessage());
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 24 with NodeSettingsRO

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

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

the class PolyRegLearnerNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    File f = new File(nodeInternDir, "data.zip");
    final DataArray rowContainer;
    if (f.exists()) {
        ContainerTable t = DataContainer.readFromZip(f);
        int rowCount = t.getRowCount();
        rowContainer = new DefaultDataArray(t, 1, rowCount, exec);
    } else {
        throw new FileNotFoundException("Internals do not exist");
    }
    f = new File(nodeInternDir, "internals.xml");
    if (f.exists()) {
        NodeSettingsRO internals = NodeSettings.loadFromXML(new BufferedInputStream(new FileInputStream(f)));
        try {
            double[] betas = internals.getDoubleArray("betas");
            String[] columnNames = internals.getStringArray("columnNames");
            double squaredError = internals.getDouble("squaredError");
            double adjustedR2 = internals.getDouble("adjustedSquaredError", Double.NaN);
            double[] meanValues = internals.getDoubleArray("meanValues");
            double[] emptyArray = new double[betas.length];
            Arrays.fill(emptyArray, Double.NaN);
            double[] stdErrs = internals.getDoubleArray("stdErrors", emptyArray);
            double[] tValues = internals.getDoubleArray("tValues", emptyArray);
            double[] pValues = internals.getDoubleArray("pValues", emptyArray);
            m_viewData = new PolyRegViewData(meanValues, betas, stdErrs, tValues, pValues, squaredError, adjustedR2, columnNames, m_settings.getDegree(), m_settings.getTargetColumn(), rowContainer);
        } catch (InvalidSettingsException ex) {
            throw new IOException("Old or corrupt internals", ex);
        }
    } else {
        throw new FileNotFoundException("Internals do not exist");
    }
}
Also used : DefaultDataArray(org.knime.base.node.util.DefaultDataArray) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) DataArray(org.knime.base.node.util.DataArray) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) ContainerTable(org.knime.core.data.container.ContainerTable) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) File(java.io.File)

Aggregations

NodeSettingsRO (org.knime.core.node.NodeSettingsRO)208 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)125 File (java.io.File)49 FileInputStream (java.io.FileInputStream)47 IOException (java.io.IOException)43 InputStream (java.io.InputStream)22 LinkedHashMap (java.util.LinkedHashMap)20 NodeSettings (org.knime.core.node.NodeSettings)20 BufferedInputStream (java.io.BufferedInputStream)19 ArrayList (java.util.ArrayList)16 GZIPInputStream (java.util.zip.GZIPInputStream)15 DataTableSpec (org.knime.core.data.DataTableSpec)14 Map (java.util.Map)11 ReferencedFile (org.knime.core.internal.ReferencedFile)11 BufferedDataTable (org.knime.core.node.BufferedDataTable)10 HashMap (java.util.HashMap)9 DataColumnSpec (org.knime.core.data.DataColumnSpec)9 RowKey (org.knime.core.data.RowKey)9 DataType (org.knime.core.data.DataType)8 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)8