use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class ListFilesNodeDialog method saveSettingsTo.
/**
* {@inheritDoc}
*/
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
// check if all entered Locations are valid
String location = m_locations.getEditor().getItem().toString();
if (location.trim().isEmpty()) {
throw new InvalidSettingsException("Please select a file!");
}
String[] files = location.split(";");
for (int i = 0; i < files.length; i++) {
File currentFile = new File(files[i]);
if (!currentFile.isDirectory()) {
// check if it was an URL;
String s = files[i];
try {
if (s.startsWith("file:")) {
s = s.substring(5);
}
currentFile = new File(URIUtil.decode(s));
} catch (URIException ex) {
throw new InvalidSettingsException("\"" + s + "\" does not exist or is not a directory", ex);
}
if (!currentFile.isDirectory()) {
throw new InvalidSettingsException("\"" + s + "\" does not exist or is not a directory");
}
}
}
ListFilesSettings set = new ListFilesSettings();
set.setLocationString(location);
set.setRecursive(m_recursive.isSelected());
set.setCaseSensitive(m_caseSensitive.isSelected());
String extensions = m_extensionField.getEditor().getItem().toString();
set.setExtensionsString(extensions);
// save the selected radio-Button
Filter filter;
if (m_filterALLRadio.isSelected()) {
filter = Filter.None;
} else if (m_filterExtensionsRadio.isSelected()) {
filter = Filter.Extensions;
} else if (m_filterRegExpRadio.isSelected()) {
if (extensions.trim().isEmpty()) {
throw new InvalidSettingsException("Enter valid regular expressin pattern");
}
try {
String pattern = extensions;
Pattern.compile(pattern);
} catch (PatternSyntaxException pse) {
throw new InvalidSettingsException("Error in pattern: ('" + pse.getMessage(), pse);
}
filter = Filter.RegExp;
} else if (m_filterWildCardsRadio.isSelected()) {
if ((extensions).length() <= 0) {
throw new InvalidSettingsException("Enter valid wildcard pattern");
}
try {
String pattern = extensions;
pattern = WildcardMatcher.wildcardToRegex(pattern);
Pattern.compile(pattern);
} catch (PatternSyntaxException pse) {
throw new InvalidSettingsException("Error in pattern: '" + pse.getMessage(), pse);
}
filter = Filter.Wildcards;
} else {
// one button must be selected though
filter = Filter.None;
}
set.setFilter(filter);
set.saveSettingsTo(settings);
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class ColumnListLoopStartNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
if ((m_settings.iterateOverColumns().size() < 1) && !m_settings.iterateAllColumns()) {
throw new InvalidSettingsException("No columns to iterate over selected");
}
if (!m_settings.iterateAllColumns()) {
for (String col : m_settings.iterateOverColumns()) {
if (!inSpecs[0].containsName(col)) {
throw new IllegalArgumentException("Column '" + col + "' does not exist in input table");
}
}
}
assert m_iteration == 0;
pushFlowVariableInt("currentIteration", m_iteration);
ColumnRearranger crea = createRearranger(inSpecs[0]);
return new DataTableSpec[] { crea.createSpec() };
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class AttributeModel method loadModel.
/**
* @param config the <code>Config</code> object to read from
* @return the attribute model for the given <code>Config</code> object
* @throws InvalidSettingsException if the settings are invalid
*/
static AttributeModel loadModel(final Config config) throws InvalidSettingsException {
final String attrName = config.getString(ATTRIBUTE_NAME);
final String modelType = config.getString(MODEL_TYPE);
final boolean skipMissing = config.getBoolean(SKIP_MISSING_VALUES);
final int noOfMissingVals = config.getInt(NO_OF_MISSING_VALUES);
final String invalidCause = config.getString(INVALID_CAUSE);
final Config modelConfig = config.getConfig(MODEL_DATA_SECTION);
final AttributeModel model;
if (NominalAttributeModel.MODEL_TYPE.equals(modelType)) {
model = new NominalAttributeModel(attrName, noOfMissingVals, skipMissing, modelConfig);
} else if (NumericalAttributeModel.MODEL_TYPE.equals(modelType)) {
model = new NumericalAttributeModel(attrName, skipMissing, noOfMissingVals, modelConfig);
} else if (ClassAttributeModel.MODEL_TYPE.equals(modelType)) {
model = new ClassAttributeModel(attrName, noOfMissingVals, skipMissing, modelConfig);
} else if (BitVectorAttributeModel.MODEL_TYPE.equals(modelType)) {
model = new BitVectorAttributeModel(attrName, skipMissing, noOfMissingVals, modelConfig);
} else {
throw new InvalidSettingsException("Invalid model type: " + modelType);
}
model.setInvalidCause(invalidCause);
return model;
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class NaiveBayesModel method updateModel.
/**
* Updates the current {@link NaiveBayesModel} with the values from the
* given {@link DataRow}.
* @param row DataRow with values for update
* @param tableSpec underlying DataTableSpec
* @param classColIdx the index of the class column
* @throws InvalidSettingsException if missing values occur in class column
* or an attribute has too many values.
*/
public void updateModel(final DataRow row, final DataTableSpec tableSpec, final int classColIdx) throws InvalidSettingsException {
if (row == null) {
throw new NullPointerException("Row must not be null");
}
if (tableSpec == null) {
throw new NullPointerException("TableSpec must not be null");
}
final DataCell classCell = row.getCell(classColIdx);
if (classCell.isMissing()) {
if (m_skipMissingVals) {
return;
}
// check if the class value is missing
throw new InvalidSettingsException("Missing class value found in row " + row.getKey() + " to skip missing values tick the box in the dialog");
}
final String classVal = classCell.toString();
final int numColumns = tableSpec.getNumColumns();
for (int i = 0; i < numColumns; i++) {
final AttributeModel model = m_modelByAttrName.get(tableSpec.getColumnSpec(i).getName());
if (model != null) {
final DataCell cell = row.getCell(i);
try {
model.addValue(classVal, cell);
} catch (final TooManyValuesException e) {
if (model instanceof ClassAttributeModel) {
throw new InvalidSettingsException("Class attribute has too many unique values. " + "To avoid this exception increase the " + "maximum number of allowed nominal " + "values in the node dialog");
}
// delete the model if it contains too many unique values
m_modelByAttrName.remove(model.getAttributeName());
model.setInvalidCause("Too many values");
m_skippedAttributes.add(model);
}
}
}
m_noOfRecs++;
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class NaiveBayesPredictorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
// check the input data
assert (inSpecs != null && inSpecs.length == 2 && inSpecs[DATA_IN_PORT] != null && inSpecs[MODEL_IN_PORT] != null);
final PortObjectSpec modelObject = inSpecs[MODEL_IN_PORT];
if (!(modelObject instanceof NaiveBayesPortObjectSpec)) {
throw new IllegalArgumentException("Invalid input data");
}
final DataTableSpec trainingSpec = ((NaiveBayesPortObjectSpec) modelObject).getTableSpec();
final DataColumnSpec classColumn = ((NaiveBayesPortObjectSpec) modelObject).getClassColumn();
if (trainingSpec == null) {
throw new InvalidSettingsException("No model spec available");
}
final PortObjectSpec inSpec = inSpecs[DATA_IN_PORT];
if (!(inSpec instanceof DataTableSpec)) {
throw new IllegalArgumentException("TableSpec must not be null");
}
final DataTableSpec spec = (DataTableSpec) inSpec;
// check the input data for columns with the wrong name or wrong type
final List<String> unknownCols = check4UnknownCols(trainingSpec, spec);
if (unknownCols.size() >= spec.getNumColumns()) {
setWarningMessage("No known attribute columns found use " + "class prior probability to predict the class membership");
} else if (unknownCols.size() == 1) {
setWarningMessage("Input column " + unknownCols.get(0) + " is unknown and will be skipped.");
} else if (unknownCols.size() > 1) {
final StringBuilder buf = new StringBuilder();
buf.append("The following input columns are unknown and " + "will be skipped: ");
for (int i = 0, length = unknownCols.size(); i < length; i++) {
if (i != 0) {
buf.append(", ");
}
if (i > 3) {
buf.append("...");
break;
}
buf.append(unknownCols.get(i));
}
setWarningMessage(buf.toString());
}
// check if the learned model contains columns which are not in the
// input data
final List<String> missingInputCols = check4MissingCols(trainingSpec, classColumn.getName(), spec);
if (missingInputCols.size() == 1) {
setWarningMessage("Attribute " + missingInputCols.get(0) + " is missing in the input data");
} else if (missingInputCols.size() > 1) {
final StringBuilder buf = new StringBuilder();
buf.append("The following attributes are missing in " + "the input data: ");
for (int i = 0, length = missingInputCols.size(); i < length; i++) {
if (i != 0) {
buf.append(", ");
}
if (i > 3) {
buf.append("...");
break;
}
buf.append(missingInputCols.get(i));
}
setWarningMessage(buf.toString());
}
final DataColumnSpec resultColSpecs = NaiveBayesCellFactory.createResultColSpecs(classColumn, spec, m_inclProbVals.getBooleanValue());
if (resultColSpecs != null) {
return new PortObjectSpec[] { AppendedColumnTable.getTableSpec(spec, resultColSpecs) };
}
return null;
}
Aggregations