Search in sources :

Example 56 with ColumnRearranger

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;
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger)

Example 57 with ColumnRearranger

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() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ArrayList(java.util.ArrayList) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 58 with ColumnRearranger

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);
        }
    };
}
Also used : TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObject) DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) TreeEnsemblePredictor(org.knime.base.node.mine.treeensemble2.node.predictor.TreeEnsemblePredictor) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Example 59 with ColumnRearranger

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 };
}
Also used : TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObject) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) BufferedDataTable(org.knime.core.node.BufferedDataTable) TreeEnsemblePredictor(org.knime.base.node.mine.treeensemble2.node.predictor.TreeEnsemblePredictor)

Example 60 with ColumnRearranger

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);
        }
    };
}
Also used : TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObject) DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) TreeEnsemblePredictor(org.knime.base.node.mine.treeensemble2.node.predictor.TreeEnsemblePredictor) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Aggregations

ColumnRearranger (org.knime.core.data.container.ColumnRearranger)393 DataTableSpec (org.knime.core.data.DataTableSpec)221 BufferedDataTable (org.knime.core.node.BufferedDataTable)153 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)125 DataColumnSpec (org.knime.core.data.DataColumnSpec)116 DataRow (org.knime.core.data.DataRow)79 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)69 DataCell (org.knime.core.data.DataCell)63 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)55 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)49 ExecutionContext (org.knime.core.node.ExecutionContext)46 PortObject (org.knime.core.node.port.PortObject)39 ArrayList (java.util.ArrayList)38 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)36 DataType (org.knime.core.data.DataType)34 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)32 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)27 DoubleValue (org.knime.core.data.DoubleValue)26 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)26 TreeEnsembleModelPortObjectSpec (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec)25