use of org.knime.core.data.DataTableSpecCreator in project knime-core by knime.
the class PMMLRuleEditorNodeModel method computeSpecs.
/**
* Computes the specs after applying the derived fields.
*
* @param specs The input table and the possible preprocessing port.
* @return The computed (original+preproc) input table's specification.
*/
@Deprecated
static DataTableSpec computeSpecs(final PortObjectSpec[] specs) {
final DataTableSpec tableSpec = (DataTableSpec) specs[0];
if (specs[1] == null) {
return tableSpec;
}
PMMLPortObjectSpec portObjectSpec = (PMMLPortObjectSpec) specs[1];
List<DataColumnSpec> preprocessingCols = portObjectSpec.getPreprocessingCols();
DataTableSpecCreator creator = new DataTableSpecCreator(tableSpec);
for (DataColumnSpec spec : preprocessingCols) {
creator.addColumns(spec);
}
return creator.createSpec();
}
use of org.knime.core.data.DataTableSpecCreator in project knime-core by knime.
the class ExtendedStatisticsNodeModel method configure.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "unchecked", "deprecation" })
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
final DataTableSpec inputSpec = inSpecs[0];
if (!m_hasSettings) {
m_nominalFilter.loadDefaults(inputSpec, new DataTypeColumnFilter(NominalValue.class, StringValue.class, IntValue.class, LongValue.class, BooleanValue.class), true);
}
List<String> nominalValues = Arrays.asList(m_nominalFilter.applyTo(inputSpec).getIncludes());
DataTableSpec nominalSpec = Statistics3Table.createOutSpecNominal(inputSpec, nominalValues);
nominalSpec = renamedOccurrencesSpec(nominalSpec);
DataTableSpec[] ret = new DataTableSpec[3];
DataTableSpecCreator specCreator = new DataTableSpecCreator(Statistics3Table.getStatisticsSpecification());
final HistogramColumn hc = createHistogramColumn();
final DataColumnSpec histogramColumnSpec = hc.createHistogramColumnSpec();
specCreator.addColumns(histogramColumnSpec);
ret[0] = specCreator.createSpec();
ret[1] = hc.createNominalHistogramTableSpec();
ret[2] = nominalSpec;
return ret;
}
use of org.knime.core.data.DataTableSpecCreator in project knime-core by knime.
the class Node method configure.
/**
* Allows passing an object that may modify the specs created by the
* {@link NodeModel}, for example in case the node is wrapped and the
* output is modified.
*
* @param rawInSpecs table specs from the predecessors
* @param configureHelper object called after node model calculated output
* specs
* @return true if configure finished successfully.
* @noreference This method is not intended to be referenced by clients.
*/
public boolean configure(final PortObjectSpec[] rawInSpecs, final NodeConfigureHelper configureHelper) {
boolean success = false;
LOGGER.assertLog(NodeContext.getContext() != null, "No node context available, please check call hierarchy and fix it");
synchronized (m_configureLock) {
// reset message object
clearNodeMessageAndNotify();
// copy input port object specs, ignoring the 0-variable port:
PortObjectSpec[] inSpecs = Arrays.copyOfRange(rawInSpecs, 1, rawInSpecs.length);
// clean output spec
for (int p = 0; p < m_outputs.length; p++) {
// update data table spec
m_outputs[p].spec = null;
}
PortObjectSpec[] newOutSpec = new PortObjectSpec[getNrOutPorts() - 1];
try {
// check the inspecs against null
for (int i = 0; i < inSpecs.length; i++) {
if (inSpecs[i] == null) {
if (m_inputs[i + 1].getType().isOptional()) {
// ignore, unconnected optional input
} else {
return false;
}
// TODO: did we really need a warning here??
// throw new InvalidSettingsException(
// "Node is not executable until all predecessors "
// + "are configured and/or executed.");
}
}
// check if the node is part of a skipped branch and return
// appropriate specs without actually configuring the node.
// Note that we must also check the incoming variable port!
boolean isInactive = false;
if (!isInactiveBranchConsumer()) {
for (int i = 0; i < rawInSpecs.length; i++) {
if (rawInSpecs[i] instanceof InactiveBranchPortObjectSpec) {
isInactive = true;
break;
}
}
} else {
FlowLoopContext flc = getFlowObjectStack().peek(FlowLoopContext.class);
if (flc != null && flc.isInactiveScope()) {
isInactive = true;
}
}
if (isInactive) {
for (int j = 0; j < m_outputs.length; j++) {
m_outputs[j].spec = InactiveBranchPortObjectSpec.INSTANCE;
}
if (success) {
LOGGER.debug("Configure skipped. (" + getName() + " in inactive branch.)");
}
return true;
}
if (configureHelper != null) {
configureHelper.preConfigure();
}
// call configure model to create output table specs
// guaranteed to return non-null, correct-length array
newOutSpec = invokeNodeModelConfigure(inSpecs);
if (configureHelper != null) {
newOutSpec = configureHelper.postConfigure(inSpecs, newOutSpec);
}
// find out if we are in the middle of executing a loop and this is a LoopEnd node
boolean isIntermediateRunningLoop = false;
if (isModelCompatibleTo(LoopEndNode.class)) {
if ((getLoopContext() != null) && !getPauseLoopExecution()) {
FlowLoopContext flc = m_model.getFlowObjectStack().peek(FlowLoopContext.class);
if ((flc != null) && (flc.getIterationIndex() > 0)) {
// don't treat first iteration as "in the middle":
isIntermediateRunningLoop = true;
}
}
}
if (!isIntermediateRunningLoop) {
// update data table specs
for (int p = 0; p < newOutSpec.length; p++) {
m_outputs[p + 1].spec = newOutSpec[p];
}
} else {
// on the loop end node (avoids costly configure calls on remainder of workflow).
for (int p = 0; p < newOutSpec.length; p++) {
if (newOutSpec[p] instanceof DataTableSpec) {
// remove domain before assigning spec to outputs
DataTableSpecCreator dtsCreator = new DataTableSpecCreator((DataTableSpec) newOutSpec[p]);
dtsCreator.dropAllDomains();
m_outputs[p + 1].spec = dtsCreator.createSpec();
} else {
// no domain to clean in PortObjectSpecs
m_outputs[p + 1].spec = newOutSpec[p];
}
}
}
m_outputs[0].spec = FlowVariablePortObjectSpec.INSTANCE;
success = true;
} catch (InvalidSettingsException ise) {
Throwable cause = ise.getCause();
if (cause == null) {
createWarningMessageAndNotify(ise.getMessage());
} else {
createWarningMessageAndNotify(ise.getMessage(), ise);
}
} catch (Throwable t) {
String error = "Configure failed (" + t.getClass().getSimpleName() + "): " + t.getMessage();
createErrorMessageAndNotify(error, t);
}
}
if (success) {
LOGGER.debug("Configure succeeded. (" + this.getName() + ")");
}
return success;
}
use of org.knime.core.data.DataTableSpecCreator in project knime-core by knime.
the class StatisticCalculatorTest method createRandomTableWithMissingValues.
private static BufferedDataTable createRandomTableWithMissingValues(final int cols, final int rows) {
long currentTimeMillis = System.currentTimeMillis();
System.out.println("Using seed: " + currentTimeMillis);
Random random = new Random(currentTimeMillis);
DataTableSpecCreator creator = new DataTableSpecCreator();
for (int i = 0; i < cols; i++) {
creator.addColumns(new DataColumnSpecCreator("" + i, DoubleCell.TYPE).createSpec());
}
final BufferedDataContainer container = EXEC_CONTEXT.createDataContainer(creator.createSpec());
for (int i = 0; i < rows; i++) {
DataCell[] rowVals = new DataCell[cols];
for (int j = 0; j < cols; j++) {
rowVals[j] = random.nextDouble() > 0.66 ? new DoubleCell(random.nextDouble()) : DataType.getMissingCell();
}
container.addRowToTable(new DefaultRow(Integer.toString(i), rowVals));
if (i % 1000 == 0) {
System.out.println("Added row: " + i);
}
}
container.close();
return container.getTable();
}
use of org.knime.core.data.DataTableSpecCreator in project knime-core by knime.
the class LogRegCoordinator method createCoeffStatisticsTableSpec.
static DataTableSpec createCoeffStatisticsTableSpec() {
DataTableSpecCreator tableSpecCreator = new DataTableSpecCreator();
tableSpecCreator.addColumns(new DataColumnSpecCreator("Logit", StringCell.TYPE).createSpec(), new DataColumnSpecCreator("Variable", StringCell.TYPE).createSpec(), new DataColumnSpecCreator("Coeff.", DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator("Std. Err.", DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator("z-score", DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator("P>|z|", DoubleCell.TYPE).createSpec());
tableSpecCreator.setName("Coefficients and Statistics");
return tableSpecCreator.createSpec();
}
Aggregations