Search in sources :

Example 41 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class DataColumnSpecFilterPMMLNodeModel method configure.

/**
 * Excludes a number of columns from the input spec and generates a new output spec.
 *
 * @param inSpecs the input table spec
 * @return outSpecs the output table spec with some excluded columns
 *
 * @throws InvalidSettingsException if the selected column is not available
 *             in the table spec.
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
    final DataTableSpec outSpec = super.configure(new DataTableSpec[] { inSpec })[0];
    final FilterResult res = getFilterResult(inSpec);
    final PMMLPortObjectSpec pmmlSpec = createPMMLSpec((PMMLPortObjectSpec) inSpecs[1], inSpec, res);
    return new PortObjectSpec[] { outSpec, pmmlSpec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Example 42 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class BinnerNodeModel method configure.

/**
 * Passes the input spec to the output.
 *
 * @param inSpecs The input spec.
 * @return The generated output specs.
 * @throws InvalidSettingsException If column to bin cannot be identified.
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inDataSpec = (DataTableSpec) inSpecs[DATA_INPORT];
    PMMLPortObjectSpec inModelSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[MODEL_INPORT] : null;
    for (String columnKey : m_columnToBins.keySet()) {
        assert m_columnToAppended.containsKey(columnKey) : columnKey;
        if (!inDataSpec.containsName(columnKey)) {
            throw new InvalidSettingsException("Binner: column \"" + columnKey + "\" not found in spec.");
        }
        if (!inDataSpec.getColumnSpec(columnKey).getType().isCompatible(DoubleValue.class)) {
            throw new InvalidSettingsException("Binner: column \"" + columnKey + "\" not compatible with double-type.");
        }
        String appended = m_columnToAppended.get(columnKey);
        if (appended != null) {
            if (inDataSpec.containsName(appended)) {
                throw new InvalidSettingsException("Binner: duplicate " + "appended column \"" + appended + "\" in spec.");
            }
        }
    }
    // set warning when no binning is defined
    if (m_columnToBins.isEmpty()) {
        super.setWarningMessage("No column select for binning.");
    }
    // generate numeric binned table spec
    DataTableSpec outDataSpec = createColumnRearranger(inDataSpec).createSpec();
    if (!m_pmmlOutEnabled) {
        return new PortObjectSpec[] { outDataSpec };
    }
    PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(inModelSpec, outDataSpec);
    return new PortObjectSpec[] { outDataSpec, pmmlSpecCreator.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DoubleValue(org.knime.core.data.DoubleValue) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 43 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class Many2OneCol2PMMLNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inDataSpec = (DataTableSpec) inSpecs[0];
    String[] includes = m_includedColumns.applyTo(inDataSpec).getIncludes();
    if (includes.length <= 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 : includes) {
            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_pmmlOutEnabled) {
        PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
        PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inDataSpec);
        return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
    } else {
        return new DataTableSpec[] { rearranger.createSpec() };
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DoubleValue(org.knime.core.data.DoubleValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 44 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class MissingValueHandlerNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    m_settings.configure((DataTableSpec) inSpecs[0]);
    MissingCellReplacingDataTable mvTable = new MissingCellReplacingDataTable((DataTableSpec) inSpecs[0], m_settings);
    PMMLPortObjectSpecCreator pmmlC = new PMMLPortObjectSpecCreator((DataTableSpec) inSpecs[0]);
    return new PortObjectSpec[] { mvTable.getDataTableSpec(), pmmlC.createSpec() };
}
Also used : MissingCellReplacingDataTable(org.knime.base.node.preproc.pmml.missingval.MissingCellReplacingDataTable) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 45 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class StringToNumberNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    // find indices to work on
    DataTableSpec dts = (DataTableSpec) inSpecs[0];
    int[] indices = findColumnIndices(dts);
    ConverterFactory converterFac = new ConverterFactory(indices, dts, m_parseType);
    ColumnRearranger colre = new ColumnRearranger(dts);
    colre.replace(converterFac, indices);
    DataTableSpec newspec = colre.createSpec();
    // create the PMML spec based on the optional incoming PMML spec
    PMMLPortObjectSpec pmmlSpec = m_pmmlInEnabled ? (PMMLPortObjectSpec) inSpecs[1] : null;
    PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, dts);
    return new PortObjectSpec[] { newspec, pmmlSpecCreator.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Aggregations

PortObjectSpec (org.knime.core.node.port.PortObjectSpec)123 DataTableSpec (org.knime.core.data.DataTableSpec)91 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)81 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)35 DataColumnSpec (org.knime.core.data.DataColumnSpec)28 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)28 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)24 FlowVariablePortObjectSpec (org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)19 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)18 IOException (java.io.IOException)17 PortObject (org.knime.core.node.port.PortObject)14 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)14 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)12 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)12 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)12 DataType (org.knime.core.data.DataType)11 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)11 File (java.io.File)10 ArrayList (java.util.ArrayList)10 DoubleValue (org.knime.core.data.DoubleValue)10