Search in sources :

Example 1 with PMMLStringConversionTranslator

use of org.knime.base.node.preproc.pmml.PMMLStringConversionTranslator in project knime-core by knime.

the class StringToNumberNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    StringBuilder warnings = new StringBuilder();
    BufferedDataTable inData = (BufferedDataTable) inObjects[0];
    DataTableSpec inSpec = inData.getDataTableSpec();
    // find indices to work on.
    List<String> inclcols = m_inclCols.getIncludeList();
    BufferedDataTable resultTable = null;
    if (inclcols.size() == 0) {
        // nothing to convert, let's return the input table.
        resultTable = inData;
        setWarningMessage("No columns selected," + " returning input DataTable.");
    } else {
        int[] indices = findColumnIndices(inSpec);
        ConverterFactory converterFac = new ConverterFactory(indices, inSpec, m_parseType);
        ColumnRearranger colre = new ColumnRearranger(inSpec);
        colre.replace(converterFac, indices);
        resultTable = exec.createColumnRearrangeTable(inData, colre, exec);
        String errorMessage = converterFac.getErrorMessage();
        if (errorMessage.length() > 0) {
            warnings.append("Problems occurred, see Console messages.\n");
        }
        if (warnings.length() > 0) {
            LOGGER.warn(errorMessage);
            setWarningMessage(warnings.toString());
        }
    }
    // the optional PMML in port (can be null)
    PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
    PMMLStringConversionTranslator trans = new PMMLStringConversionTranslator(m_inclCols.getIncludeList(), m_parseType, new DerivedFieldMapper(inPMMLPort));
    PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, inSpec);
    PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort, inSpec);
    outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
    return new PortObject[] { resultTable, outPMMLPort };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) PMMLStringConversionTranslator(org.knime.base.node.preproc.pmml.PMMLStringConversionTranslator) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 2 with PMMLStringConversionTranslator

use of org.knime.base.node.preproc.pmml.PMMLStringConversionTranslator in project knime-core by knime.

the class NumberToStringNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    StringBuilder warnings = new StringBuilder();
    BufferedDataTable inData = (BufferedDataTable) inObjects[0];
    DataTableSpec inSpec = inData.getDataTableSpec();
    // find indices to work on.
    List<String> inclcols = m_inclCols.getIncludeList();
    BufferedDataTable resultTable = null;
    if (inclcols.size() == 0) {
        // nothing to convert, let's return the input table.
        resultTable = inData;
        setWarningMessage("No columns selected," + " returning input DataTable.");
    } else {
        int[] indices = findColumnIndices(inData.getSpec());
        ConverterFactory converterFac = new ConverterFactory(indices, inSpec);
        ColumnRearranger colre = new ColumnRearranger(inSpec);
        colre.replace(converterFac, indices);
        resultTable = exec.createColumnRearrangeTable(inData, colre, exec);
        String errorMessage = converterFac.getErrorMessage();
        if (errorMessage.length() > 0) {
            warnings.append("Problems occurred, see Console messages.\n");
        }
        if (warnings.length() > 0) {
            getLogger().warn(errorMessage);
            setWarningMessage(warnings.toString());
        }
    }
    // the optional PMML in port (can be null)
    PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
    PMMLStringConversionTranslator trans = new PMMLStringConversionTranslator(m_inclCols.getIncludeList(), StringCell.TYPE, new DerivedFieldMapper(inPMMLPort));
    PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, inSpec);
    PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort, inSpec);
    outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
    return new PortObject[] { resultTable, outPMMLPort };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) PMMLStringConversionTranslator(org.knime.base.node.preproc.pmml.PMMLStringConversionTranslator) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Aggregations

PMMLStringConversionTranslator (org.knime.base.node.preproc.pmml.PMMLStringConversionTranslator)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)2 BufferedDataTable (org.knime.core.node.BufferedDataTable)2 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)2 PortObject (org.knime.core.node.port.PortObject)2 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)2 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)2 DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)2