use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class PMMLRuleEditorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
RuleSet ruleSet = RuleSet.Factory.newInstance();
PMMLRuleParser parser = new PMMLRuleParser((DataTableSpec) inSpecs[0], getAvailableInputFlowVariables());
try {
ColumnRearranger rearranger = createRearranger((DataTableSpec) inSpecs[0], ruleSet, parser);
PMMLPortObjectSpec portObjectSpec = createPMMLPortObjectSpec(rearranger.createSpec(), Collections.<String>emptyList());
return new PortObjectSpec[] { rearranger.createSpec(), portObjectSpec };
} catch (ParseException e) {
throw new InvalidSettingsException(e);
}
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class PMCCNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec in = (DataTableSpec) inSpecs[0];
if (!in.containsCompatibleType(DoubleValue.class) && !in.containsCompatibleType(NominalValue.class)) {
throw new InvalidSettingsException("Neither double nor nominal compatible columns in input");
}
List<String> includes = m_columnIncludesList.getIncludeList();
List<String> excludes = m_columnIncludesList.getExcludeList();
// not configured yet?
if (includes.isEmpty() && excludes.isEmpty()) {
ArrayList<String> includeDefault = new ArrayList<String>();
for (DataColumnSpec s : in) {
if (s.getType().isCompatible(DoubleValue.class) || s.getType().isCompatible(NominalValue.class)) {
includeDefault.add(s.getName());
}
}
m_columnIncludesList.setIncludeList(includeDefault);
includes = m_columnIncludesList.getIncludeList();
setWarningMessage("Auto configuration: Using all suitable " + "columns (in total " + includes.size() + ")");
}
for (String s : includes) {
DataColumnSpec sp = in.getColumnSpec(s);
if (sp == null) {
throw new InvalidSettingsException("No such column: " + s);
}
if (!sp.getType().isCompatible(DoubleValue.class) && !sp.getType().isCompatible(NominalValue.class)) {
throw new InvalidSettingsException("Column is neither double " + "nor nominal compatible: " + s);
}
}
String[] toArray = includes.toArray(new String[includes.size()]);
return new PortObjectSpec[] { PMCCPortObjectAndSpec.createOutSpec(toArray), new PMCCPortObjectAndSpec(toArray) };
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class JavaEditVarNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
m_snippet.setSettings(m_settings);
FlowVariableRepository flowVarRepository = new FlowVariableRepository(getAvailableInputFlowVariables());
ValidationReport report = m_snippet.validateSettings(new DataTableSpec(), flowVarRepository);
if (report.hasWarnings()) {
setWarningMessage(StringUtils.join(report.getWarnings(), "\n"));
}
if (report.hasErrors()) {
throw new InvalidSettingsException(StringUtils.join(report.getErrors(), "\n"));
}
m_snippet.configure(new DataTableSpec(), flowVarRepository);
for (FlowVariable flowVar : flowVarRepository.getModified()) {
if (flowVar.getType().equals(Type.INTEGER)) {
pushFlowVariableInt(flowVar.getName(), flowVar.getIntValue());
} else if (flowVar.getType().equals(Type.DOUBLE)) {
pushFlowVariableDouble(flowVar.getName(), flowVar.getDoubleValue());
} else {
pushFlowVariableString(flowVar.getName(), flowVar.getStringValue());
}
}
// execute if execute on config flag is set
if (!m_settings.isRunOnExecute()) {
performExecute(null);
}
return new PortObjectSpec[] { FlowVariablePortObjectSpec.INSTANCE };
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class NumericOutliersApplyNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final DataTableSpec outlierPortSpec = (DataTableSpec) inSpecs[0];
final DataTableSpec inTableSpec = (DataTableSpec) inSpecs[1];
// ensure that the in data table contains the group columns that were used to learn the outlier reviser
final String[] groupColNames = NumericOutlierPortObject.getGroupColNames(outlierPortSpec);
final String[] missingGroupColNames = //
Arrays.stream(groupColNames).filter(//
g -> !inTableSpec.containsName(g)).toArray(String[]::new);
if (missingGroupColNames.length > 0) {
throw new InvalidSettingsException(MISSING_GROUPS_EXCEPTION_PREFIX + ConvenienceMethods.getShortStringFrom(Arrays.asList(missingGroupColNames), MAX_PRINT));
}
// check if the data type for the groups differs between those the model was trained on and the input table
final String[] groupSpecNames = NumericOutlierPortObject.getGroupSpecNames(outlierPortSpec);
final String[] wrongDataType = //
IntStream.range(0, groupColNames.length).filter(i -> outlierPortSpec.getColumnSpec(groupSpecNames[i]).getType() != inTableSpec.getColumnSpec(groupColNames[i]).getType()).mapToObj(//
i -> groupColNames[i]).toArray(String[]::new);
if (wrongDataType.length != 0) {
throw new InvalidSettingsException(GROUPS_COMPATIBILITY_EXCEPTION_PREFIX + ConvenienceMethods.getShortStringFrom(Arrays.asList(wrongDataType), MAX_PRINT));
}
// get the outlier column names stored in the port spec
final String[] outlierColNames = NumericOutlierPortObject.getOutlierColNames(outlierPortSpec);
// check for outlier columns that are missing the input table
final List<String> nonExistOrCompatibleOutliers = Arrays.stream(outlierColNames).filter(s -> (!inTableSpec.containsName(s) || //
!inTableSpec.getColumnSpec(s).getType().isCompatible(DoubleValue.class))).collect(Collectors.toList());
// if all of them are missing throw an exception
if (outlierColNames.length == nonExistOrCompatibleOutliers.size()) {
throw new InvalidSettingsException(MISSING_OUTLIERS_EXCEPTION_PREFIX + ConvenienceMethods.getShortStringFrom(Arrays.asList(outlierColNames), MAX_PRINT));
}
if (nonExistOrCompatibleOutliers.size() > 0) {
setWarningMessage(MISSING_OUTLIERS_WARNING_PREFIX + ConvenienceMethods.getShortStringFrom(nonExistOrCompatibleOutliers, MAX_PRINT));
}
return new PortObjectSpec[] { NumericOutliersReviser.getOutTableSpec(inTableSpec), NumericOutliersReviser.getSummaryTableSpec(inTableSpec, groupColNames) };
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class DecisionTreeLearnerNodeModel method configure.
/**
* The number of the class column must be > 0 and < number of input columns.
*
* @param inSpecs the tabel specs on the input port to use for configuration
* @see NodeModel#configure(DataTableSpec[])
* @throws InvalidSettingsException thrown if the configuration is not
* correct
* @return the table specs for the output ports
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = (DataTableSpec) inSpecs[DATA_INPORT];
PMMLPortObjectSpec modelSpec = (PMMLPortObjectSpec) inSpecs[MODEL_INPORT];
// check spec with selected column
String classifyColumn = m_classifyColumn.getStringValue();
DataColumnSpec columnSpec = inSpec.getColumnSpec(classifyColumn);
boolean isValid = columnSpec != null && columnSpec.getType().isCompatible(NominalValue.class);
if (classifyColumn != null && !isValid) {
throw new InvalidSettingsException("Class column \"" + classifyColumn + "\" not found or incompatible");
}
if (classifyColumn == null) {
// auto-guessing
assert !isValid : "No class column set but valid configuration";
// get the first useful one starting at the end of the table
for (int i = inSpec.getNumColumns() - 1; i >= 0; i--) {
if (inSpec.getColumnSpec(i).getType().isCompatible(NominalValue.class)) {
m_classifyColumn.setStringValue(inSpec.getColumnSpec(i).getName());
super.setWarningMessage("Guessing target column: \"" + m_classifyColumn.getStringValue() + "\".");
break;
}
}
if (m_classifyColumn.getStringValue() == null) {
throw new InvalidSettingsException("Table contains no nominal" + " attribute for classification.");
}
}
return new PortObjectSpec[] { createPMMLPortObjectSpec(modelSpec, inSpec) };
}
Aggregations