use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class LogRegLearnerNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
final BufferedDataTable data = (BufferedDataTable) inObjects[0];
DataTableSpec tableSpec = data.getDataTableSpec();
// handle the optional PMML input
PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
PMMLPortObjectSpec inPMMLSpec = null;
if (inPMMLPort != null) {
inPMMLSpec = inPMMLPort.getSpec();
} else {
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(tableSpec);
inPMMLSpec = creator.createSpec();
inPMMLPort = new PMMLPortObject(inPMMLSpec);
}
LogRegLearner learner = new LogRegLearner(new PortObjectSpec[] { tableSpec, inPMMLSpec }, m_pmmlInEnabled, m_settings);
m_content = learner.execute(new PortObject[] { data, inPMMLPort }, exec);
String warn = learner.getWarningMessage();
if (warn != null) {
setWarningMessage(warn);
}
// third argument is ignored since we provide a port
PMMLPortObject outPMMLPort = new PMMLPortObject((PMMLPortObjectSpec) learner.getOutputSpec()[0], inPMMLPort, null);
PMMLGeneralRegressionTranslator trans = new PMMLGeneralRegressionTranslator(m_content.createGeneralRegressionContent());
outPMMLPort.addModelTranslater(trans);
return new PortObject[] { outPMMLPort, m_content.createTablePortObject(exec) };
}
use of org.knime.core.node.port.PortObject 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;
}
use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class Node method removeOutputTablesFromGlobalRepository.
/**
* Reverse operation to
* {@link #putOutputTablesIntoGlobalRepository(HashMap)}. It will remove
* all output tables and its delegates from the global table repository.
* @param rep The global table rep.
* @return The number of tables effectively removed, used for assertions.
*/
public int removeOutputTablesFromGlobalRepository(final HashMap<Integer, ContainerTable> rep) {
int result = 0;
for (int i = 0; i < m_outputs.length; i++) {
PortObject portObject = m_outputs[i].object;
if (portObject instanceof BufferedDataTable) {
BufferedDataTable t = (BufferedDataTable) portObject;
result += t.removeFromTableRepository(rep, this);
}
}
return result;
}
use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class Node method cleanOutPorts.
/**
* Sets output objects to null.
* @param isLoopRestart If true, does not clear tables that are part
* of the internally held tables (loop start nodes implements the
* {@link BufferedDataTableHolder} interface). This can only be true
* between two loop iterations.
* @noreference This method is not intended to be referenced by clients.
*/
public void cleanOutPorts(final boolean isLoopRestart) {
if (isLoopRestart) {
// just as an assertion
FlowObjectStack inStack = getFlowObjectStack();
FlowLoopContext flc = inStack.peek(FlowLoopContext.class);
if (flc != null && flc.isInactiveScope()) {
LOGGER.coding("Encountered an inactive FlowLoopContext in a loop restart.");
// continue with historically "correct" solution:
flc = inStack.peekScopeContext(FlowLoopContext.class, false);
}
if (flc == null && !this.isModelCompatibleTo(LoopStartNode.class)) {
LOGGER.coding("Encountered a loop restart action but there is" + " no loop context on the flow object stack (node " + getName() + ")");
}
}
LOGGER.debug("clean output ports.");
Set<BufferedDataTable> disposableTables = new LinkedHashSet<BufferedDataTable>();
for (int i = 0; i < m_outputs.length; i++) {
PortObject portObject = m_outputs[i].object;
if (portObject instanceof BufferedDataTable) {
final BufferedDataTable table = (BufferedDataTable) portObject;
table.collectTableAndReferencesOwnedBy(this, disposableTables);
}
m_outputs[i].spec = null;
m_outputs[i].object = null;
m_outputs[i].summary = null;
}
if (m_internalHeldPortObjects != null) {
Set<BufferedDataTable> internalTableSet = collectTableAndReferences(m_internalHeldPortObjects);
// internal table reference that must not be cleared).
if (isLoopRestart) {
disposableTables.removeAll(internalTableSet);
} else {
disposableTables.addAll(internalTableSet);
m_internalHeldPortObjects = null;
}
}
for (BufferedDataTable disposable : disposableTables) {
disposable.clearSingle(this);
}
// clear temporary tables that have been created during execute
for (ContainerTable t : m_localTempTables) {
t.clear();
}
m_localTempTables.clear();
}
use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class PortObjectInNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
int id = m_portObjectIDSettings.getId();
PortObject obj = PortObjectRepository.get(id);
if (obj == null) {
throw new RuntimeException("No port object for id " + id);
}
pushFlowVariables();
PortObject cloneOrSelf = m_portObjectIDSettings.isCopyData() ? PortObjectRepository.copy(obj, exec, exec) : obj;
return new PortObject[] { cloneOrSelf };
}
Aggregations