Search in sources :

Example 6 with NodeSettingsRO

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

the class TimeMissingValueHandlingColSetting method loadMetaColSettings.

/**
 * Helper that load meta settings from a config object, used in NodeModel.
 *
 * @param settings to load from
 * @return meta settings
 * @throws InvalidSettingsException if errors occur
 */
static TimeMissingValueHandlingColSetting[] loadMetaColSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    NodeSettingsRO subConfig = settings.getNodeSettings(CFG_META);
    Map<String, TimeMissingValueHandlingColSetting> map = loadSubConfigs(subConfig);
    return map.values().toArray(new TimeMissingValueHandlingColSetting[0]);
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Example 7 with NodeSettingsRO

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

the class TimeMissingValueHandlingColSetting method loadSubConfigs.

/**
 * Get ColSetting objects in a map, mapping name to ColSetting.
 */
private static Map<String, TimeMissingValueHandlingColSetting> loadSubConfigs(final NodeSettingsRO settings) throws InvalidSettingsException {
    LinkedHashMap<String, TimeMissingValueHandlingColSetting> result = new LinkedHashMap<String, TimeMissingValueHandlingColSetting>();
    for (String key : settings.keySet()) {
        NodeSettingsRO subConfig = settings.getNodeSettings(key);
        TimeMissingValueHandlingColSetting local = new TimeMissingValueHandlingColSetting();
        try {
            local.loadSettings(subConfig);
        } catch (InvalidSettingsException ise) {
            throw new InvalidSettingsException("Unable to load sub config for key '" + key + "'", ise);
        }
        result.put(key, local);
    }
    return result;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with NodeSettingsRO

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

the class Statistics2Table method load.

/**
 * Load a new statistic table by the given settings object.
 * @param sett to load this table from
 * @return a new statistic table
 * @throws InvalidSettingsException if the settings are corrupt
 */
public static Statistics2Table load(final NodeSettingsRO sett) throws InvalidSettingsException {
    DataTableSpec spec = DataTableSpec.load(sett.getConfig("spec"));
    Map<DataCell, Integer>[] nominalValues = new Map[spec.getNumColumns()];
    for (int c = 0; c < nominalValues.length; c++) {
        String name = spec.getColumnSpec(c).getName();
        if (!sett.containsKey(name)) {
            nominalValues[c] = null;
        } else {
            nominalValues[c] = new LinkedHashMap<DataCell, Integer>();
            NodeSettingsRO subSett = sett.getNodeSettings(name);
            for (String key : subSett.keySet()) {
                NodeSettingsRO nomSett = subSett.getNodeSettings(key);
                nominalValues[c].put(nomSett.getDataCell("key"), nomSett.getInt("value"));
            }
        }
    }
    double[] min = sett.getDoubleArray("minimum");
    double[] max = sett.getDoubleArray("maximum");
    double[] mean = sett.getDoubleArray("mean");
    double[] var = sett.getDoubleArray("variance");
    double[] median = sett.getDoubleArray("median");
    double[] missings = sett.getDoubleArray("missings");
    double[] sums = sett.getDoubleArray("sums");
    // added with 2.7, fallback -1
    int rowCount = sett.getInt("row_count", -1);
    return new Statistics2Table(spec, min, max, mean, median, var, sums, missings, nominalValues, rowCount);
}
Also used : MutableInteger(org.knime.core.util.MutableInteger) DataTableSpec(org.knime.core.data.DataTableSpec) DataCell(org.knime.core.data.DataCell) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 9 with NodeSettingsRO

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

the class VariableToTableSettings method loadSettingsFrom.

/**
 * Loads settings.
 *
 * @param settings to load from
 * @throws InvalidSettingsException if settings not present
 */
public void loadSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_variablesOfInterest.clear();
    m_includeAll = settings.getBoolean("all", false);
    NodeSettingsRO sub = settings.getNodeSettings("variables");
    if (sub == null) {
        throw new InvalidSettingsException("No settings available");
    }
    for (String key : sub.keySet()) {
        NodeSettingsRO sub2 = sub.getNodeSettings(key);
        String name = sub2.getString("name");
        String typeS = sub2.getString("type");
        if (name == null || typeS == null) {
            throw new InvalidSettingsException("Name and type must not be null.");
        }
        FlowVariable.Type type;
        try {
            type = FlowVariable.Type.valueOf(typeS);
        } catch (IllegalArgumentException iae) {
            throw new InvalidSettingsException("Can't parse type: " + typeS);
        }
        m_variablesOfInterest.add(new Pair<String, FlowVariable.Type>(name, type));
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 10 with NodeSettingsRO

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

the class BitVectorGeneratorNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File internDir, final ExecutionMonitor exec) throws IOException {
    File f = new File(internDir, FILE_NAME);
    FileInputStream fis = new FileInputStream(f);
    NodeSettingsRO internSettings = NodeSettings.loadFromXML(fis);
    try {
        m_nrOfProcessedRows = internSettings.getInt(INT_CFG_ROWS);
        m_totalNrOf0s = internSettings.getInt(INT_CFG_NR_ZEROS);
        m_totalNrOf1s = internSettings.getInt(INT_CFG_NR_ONES);
    } catch (InvalidSettingsException ise) {
        throw new IOException(ise.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)

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