use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class CategoryToNumberNodeModel method createRearranger.
private ColumnRearranger createRearranger(final DataTableSpec spec) {
m_factories.clear();
ColumnRearranger rearranger = new ColumnRearranger(spec);
for (String colName : m_settings.getIncludedColumns()) {
CategoryToNumberCellFactory cellFactory = new CategoryToNumberCellFactory(spec, colName, m_settings);
if (m_settings.getAppendColumns()) {
rearranger.append(cellFactory);
} else {
rearranger.replace(cellFactory, colName);
}
m_factories.add(cellFactory);
}
return rearranger;
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class CategoryToNumberNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
List<String> inputCols = new ArrayList<String>();
for (DataColumnSpec column : inSpec) {
if (column.getType().isCompatible(StringValue.class)) {
inputCols.add(column.getName());
}
}
// Auto configuration when included columns are not set
if (null == m_settings.getIncludedColumns()) {
// when there is no column with nominal data
if (inputCols.isEmpty()) {
throw new InvalidSettingsException("No column in " + "the input compatible to \"StringValue\".");
} else {
// auto-configure
m_settings.setIncludedColumns(inputCols.toArray(new String[inputCols.size()]));
}
} else {
if (!m_settings.getIncludeAll()) {
if (m_settings.getIncludedColumns().length == 0) {
setWarningMessage("No columns selected.");
}
List<String> included = new ArrayList<String>();
included.addAll(Arrays.asList(m_settings.getIncludedColumns()));
included.removeAll(inputCols);
if (!included.isEmpty()) {
// output first missing column
throw new InvalidSettingsException("Missing column: " + included.get(0).toString());
}
} else {
if (inputCols.isEmpty()) {
throw new InvalidSettingsException("No column in " + "the input compatible to \"StringValue\".");
} else {
// automatically add all columns
m_settings.setIncludedColumns(inputCols.toArray(new String[inputCols.size()]));
}
}
}
ColumnRearranger rearranger = createRearranger(inSpec);
PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[1];
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inSpec);
pmmlSpecCreator.addPreprocColNames(inputCols);
return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class TreeEnsembleClassificationPredictorNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
TreeEnsembleModelPortObject model = (TreeEnsembleModelPortObject) ((PortObjectInput) inputs[0]).getPortObject();
TreeEnsembleModelPortObjectSpec modelSpec = model.getSpec();
DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
final TreeEnsemblePredictor pred = new TreeEnsemblePredictor(modelSpec, model, dataSpec, m_configuration);
ColumnRearranger rearranger = pred.getPredictionRearranger();
StreamableFunction func = rearranger.createStreamableFunction(1, 0);
func.runFinal(inputs, outputs, exec);
}
};
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class TreeEnsembleRegressionPredictorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
TreeEnsembleModelPortObject model = (TreeEnsembleModelPortObject) inObjects[0];
TreeEnsembleModelPortObjectSpec modelSpec = model.getSpec();
BufferedDataTable data = (BufferedDataTable) inObjects[1];
DataTableSpec dataSpec = data.getDataTableSpec();
final TreeEnsemblePredictor pred = new TreeEnsemblePredictor(modelSpec, model, dataSpec, m_configuration);
ColumnRearranger rearranger = pred.getPredictionRearranger();
BufferedDataTable outTable = exec.createColumnRearrangeTable(data, rearranger, exec);
return new BufferedDataTable[] { outTable };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class TreeEnsembleRegressionPredictorNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
TreeEnsembleModelPortObject model = (TreeEnsembleModelPortObject) ((PortObjectInput) inputs[0]).getPortObject();
TreeEnsembleModelPortObjectSpec modelSpec = model.getSpec();
DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
final TreeEnsemblePredictor pred = new TreeEnsemblePredictor(modelSpec, model, dataSpec, m_configuration);
ColumnRearranger rearranger = pred.getPredictionRearranger();
StreamableFunction func = rearranger.createStreamableFunction(1, 0);
func.runFinal(inputs, outputs, exec);
}
};
}
Aggregations