use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class TreeEnsembleClassificationLearnerNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
// guaranteed to not be null (according to API)
DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
if (m_configuration == null) {
throw new InvalidSettingsException("No configuration available");
}
final FilterLearnColumnRearranger learnRearranger = m_configuration.filterLearnColumns(inSpec);
final String warn = learnRearranger.getWarning();
if (warn != null) {
setWarningMessage(warn);
}
m_configuration.checkColumnSelection(inSpec);
DataTableSpec learnSpec = learnRearranger.createSpec();
TreeEnsembleModelPortObjectSpec ensembleSpec = m_configuration.createPortObjectSpec(learnSpec);
// the following call may return null, which is OK during configure
// but not upon execution (spec may not be populated yet, e.g.
// predecessor not executed)
// if the possible values is not null, the following call checks
// for duplicates in the toString() representation
ensembleSpec.getTargetColumnPossibleValueMap();
final TreeEnsemblePredictor outOfBagPredictor = createOutOfBagPredictor(ensembleSpec, null, inSpec);
ColumnRearranger outOfBagRearranger = outOfBagPredictor.getPredictionRearranger();
DataTableSpec outOfBagSpec = outOfBagRearranger == null ? null : outOfBagRearranger.createSpec();
DataTableSpec colStatsSpec = TreeEnsembleLearner.getColumnStatisticTableSpec();
return new PortObjectSpec[] { outOfBagSpec, colStatsSpec, ensembleSpec };
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class Many2OneColPMMLNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inDataSpec = (DataTableSpec) inSpecs[0];
if (m_includedColumns.getIncludeList().size() <= 0) {
setWarningMessage("No column selected. Node will have no effect!");
}
// if it is not a reg exp it must be double compatible
if (!m_includeMethod.getStringValue().equals(IncludeMethod.RegExpPattern.name())) {
for (String colName : m_includedColumns.getIncludeList()) {
if (!inDataSpec.getColumnSpec(colName).getType().isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("For selected include method '" + m_includeMethod.getStringValue() + "' only double compatible values are allowed." + " Column '" + colName + "' is not.");
}
}
}
ColumnRearranger rearranger = createRearranger(inDataSpec, getCellFactory(inDataSpec));
if (m_pmmlEnabled) {
PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[1];
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inDataSpec);
return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
} else {
return new DataTableSpec[] { rearranger.createSpec() };
}
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class PolyRegLearnerNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[1];
String[] selectedCols = computeSelectedColumns(tableSpec);
for (String colName : selectedCols) {
DataColumnSpec dcs = tableSpec.getColumnSpec(colName);
if (dcs == null) {
throw new InvalidSettingsException("Selected column '" + colName + "' does not exist in input table");
}
if (!dcs.getType().isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("Selected column '" + dcs.getName() + "' from the input table is not a numeric column.");
}
}
if (m_settings.getTargetColumn() == null) {
throw new InvalidSettingsException("No target column selected");
}
if (tableSpec.findColumnIndex(m_settings.getTargetColumn()) == -1) {
throw new InvalidSettingsException("Target column '" + m_settings.getTargetColumn() + "' does not exist.");
}
DataColumnSpecCreator crea = new DataColumnSpecCreator("PolyReg prediction", DoubleCell.TYPE);
DataColumnSpec col1 = crea.createSpec();
crea = new DataColumnSpecCreator("Prediction Error", DoubleCell.TYPE);
DataColumnSpec col2 = crea.createSpec();
return new PortObjectSpec[] { AppendedColumnTable.getTableSpec(tableSpec, col1, col2), createModelSpec(pmmlSpec, tableSpec) };
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class Node method createNodeExecutionResult.
/**
* Creates an execution result containing all calculated values in a
* execution. The returned value is suitable to be used in
* {@link #loadDataAndInternals(
* NodeContentPersistor, ExecutionMonitor, LoadResult)}.
* If this node is not executed, it will assign null values to the fields
* in the returned execution result.
* @param exec For progress information.
* @return A new execution result containing the values being calculated.
* @throws CanceledExecutionException If canceled
*/
public NodeExecutionResult createNodeExecutionResult(final ExecutionMonitor exec) throws CanceledExecutionException {
NodeExecutionResult result = new NodeExecutionResult();
result.setWarningMessage(m_model.getWarningMessage());
if (hasContent()) {
File internTempDir;
try {
internTempDir = FileUtil.createTempDir("knime_node_internDir");
exec.setMessage("Saving internals");
saveInternals(internTempDir, exec.createSubProgress(0.0));
result.setNodeInternDir(new ReferencedFile(internTempDir));
} catch (IOException ioe) {
LOGGER.error("Unable to save internals", ioe);
}
}
if (m_internalHeldPortObjects != null) {
PortObject[] internalHeldPortObjects = Arrays.copyOf(m_internalHeldPortObjects, m_internalHeldPortObjects.length);
result.setInternalHeldPortObjects(internalHeldPortObjects);
}
PortObject[] pos = new PortObject[getNrOutPorts()];
PortObjectSpec[] poSpecs = new PortObjectSpec[getNrOutPorts()];
for (int i = 0; i < pos.length; i++) {
PortObject po = getOutputObject(i);
if (po != null) {
pos[i] = po;
poSpecs[i] = po.getSpec();
}
}
result.setPortObjects(pos);
result.setPortObjectSpecs(poSpecs);
// Add the outgoing flow variables to the execution result
FlowObjectStack outgoingStack = m_model.getOutgoingFlowObjectStack();
List<FlowVariable> nodeFlowVars = outgoingStack.getAvailableFlowVariables().values().stream().filter(f -> f.getScope().equals(FlowVariable.Scope.Flow)).collect(Collectors.toList());
// the bottom most element should remain at the bottom of the stack
Collections.reverse(nodeFlowVars);
result.setFlowVariables(nodeFlowVars);
return result;
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class Node method getDialogPaneWithSettings.
/**
* @param inSpecs The input specs, which will be forwarded to the dialog's
* {@link NodeDialogPane#loadSettingsFrom(NodeSettingsRO,
* PortObjectSpec[])}.
* @param settings The current settings of this node. The settings object
* will also contain the settings of the outer SNC.
* @param isWriteProtected Whether write protected, see
* {@link org.knime.core.node.workflow.WorkflowManager#isWriteProtected()}.
* @return The dialog pane which holds all the settings' components. In
* addition this method loads the settings from the model into the
* dialog pane.
* @throws NotConfigurableException if the dialog cannot be opened because
* of real invalid settings or if any preconditions are not
* fulfilled, e.g. no predecessor node, no nominal column in
* input table, etc.
* @throws IllegalStateException If node has no dialog.
* @see #hasDialog()
* @since 2.6
*/
public NodeDialogPane getDialogPaneWithSettings(final PortObjectSpec[] inSpecs, final PortObject[] inData, final NodeSettingsRO settings, final boolean isWriteProtected) throws NotConfigurableException {
NodeDialogPane dialogPane = getDialogPane();
PortObjectSpec[] corrInSpecs = new PortObjectSpec[inSpecs.length - 1];
PortObject[] corrInData = new PortObject[inData.length - 1];
for (int i = 1; i < inSpecs.length; i++) {
if (inSpecs[i] instanceof InactiveBranchPortObjectSpec) {
if (!isInactiveBranchConsumer()) {
throw new NotConfigurableException("Cannot configure nodes in inactive branches.");
}
}
PortType t = getInputType(i);
if (!t.acceptsPortObjectSpec(inSpecs[i]) && !(inSpecs[i] instanceof InactiveBranchPortObjectSpec)) {
// table(!) connection)
throw new NotConfigurableException("Invalid incoming port object spec \"" + inSpecs[i].getClass().getSimpleName() + "\", expected \"" + t.getPortObjectSpecClass().getSimpleName() + "\"");
} else if (inSpecs[i] == null && BufferedDataTable.TYPE.equals(t) && !t.isOptional()) {
corrInSpecs[i - 1] = new DataTableSpec();
} else {
corrInSpecs[i - 1] = inSpecs[i];
corrInData[i - 1] = inData[i];
}
}
// the sub node virtual input node shows in its dialog all flow variables that are available to the rest
// of the subnode. It's the only case where the flow variables shown in the dialog are not the ones available
// to the node model class ...
final FlowObjectStack flowObjectStack = m_model instanceof VirtualSubNodeInputNodeModel ? ((VirtualSubNodeInputNodeModel) m_model).getSubNodeContainerFlowObjectStack() : getFlowObjectStack();
dialogPane.internalLoadSettingsFrom(settings, corrInSpecs, corrInData, flowObjectStack, getCredentialsProvider(), isWriteProtected);
if (m_model instanceof ValueControlledNode && dialogPane instanceof ValueControlledDialogPane) {
NodeSettings currentValue = new NodeSettings("currentValue");
try {
((ValueControlledNode) m_model).saveCurrentValue(currentValue);
((ValueControlledDialogPane) dialogPane).loadCurrentValue(currentValue);
} catch (Exception ise) {
final String msg = "Could not load current value into dialog: " + ise.getMessage();
if (ise instanceof InvalidSettingsException) {
LOGGER.warn(msg, ise);
} else {
LOGGER.coding(msg, ise);
}
}
}
return dialogPane;
}
Aggregations