Search in sources :

Example 1 with AbstractMany2OneCellFactory

use of org.knime.base.node.preproc.columnTrans.AbstractMany2OneCellFactory in project knime-core by knime.

the class Many2OneColPMMLNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    BufferedDataTable inData = (BufferedDataTable) inObjects[0];
    AbstractMany2OneCellFactory cellFactory = getCellFactory(inData.getDataTableSpec());
    BufferedDataTable outData = exec.createColumnRearrangeTable(inData, createRearranger(inData.getDataTableSpec(), cellFactory), exec);
    if (m_pmmlEnabled) {
        if (IncludeMethod.valueOf(m_includeMethod.getStringValue()) == IncludeMethod.RegExpPattern) {
            setWarningMessage("Regular Expressions are not supported in PMML. " + "The generated PMML document is invalid.");
        }
        // the optional PMML in port (can be null)
        PMMLPortObject inPMMLPort = (PMMLPortObject) inObjects[1];
        /*
             PMMLOne2ManyTranslator trans = new PMMLOne2ManyTranslator(
                    cellFactory.getColumnMapping(),
                    new DerivedFieldMapper(inPMMLPort));
            */
        int[] sourceColIndices = cellFactory.getIncludedColIndices();
        String[] sourceColNames = new String[sourceColIndices.length];
        for (int i = 0; i < sourceColIndices.length; i++) {
            sourceColNames[i] = inData.getDataTableSpec().getColumnSpec(sourceColIndices[i]).getName();
        }
        PMMLMany2OneTranslator trans = new PMMLMany2OneTranslator(cellFactory.getAppendedColumnName(), sourceColNames, IncludeMethod.valueOf(m_includeMethod.getStringValue()));
        PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, outData.getDataTableSpec());
        PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
        outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
        return new PortObject[] { outData, outPMMLPort };
    } else {
        return new PortObject[] { outData };
    }
}
Also used : AbstractMany2OneCellFactory(org.knime.base.node.preproc.columnTrans.AbstractMany2OneCellFactory) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 2 with AbstractMany2OneCellFactory

use of org.knime.base.node.preproc.columnTrans.AbstractMany2OneCellFactory in project knime-core by knime.

the class Many2OneColPMMLNodeModel method getCellFactory.

private AbstractMany2OneCellFactory getCellFactory(final DataTableSpec spec) {
    AbstractMany2OneCellFactory cellFactory;
    IncludeMethod method = IncludeMethod.valueOf(m_includeMethod.getStringValue());
    int[] includedColIndices = new int[m_includedColumns.getIncludeList().size()];
    int index = 0;
    for (String colName : m_includedColumns.getIncludeList()) {
        includedColIndices[index++] = spec.findColumnIndex(colName);
    }
    String newColName = DataTableSpec.getUniqueColumnName(spec, m_appendedColumnName.getStringValue());
    m_appendedColumnName.setStringValue(newColName);
    if (method.equals(IncludeMethod.RegExpPattern)) {
        cellFactory = new RegExpCellFactory(spec, newColName, includedColIndices, m_pattern.getStringValue());
    } else if (method.equals(IncludeMethod.Minimum)) {
        cellFactory = new MinMaxCellFactory(spec, newColName, includedColIndices, false);
    } else if (method.equals(IncludeMethod.Binary)) {
        cellFactory = new BinaryCellFactory(spec, newColName, includedColIndices);
    } else {
        cellFactory = new MinMaxCellFactory(spec, newColName, includedColIndices, true);
    }
    return cellFactory;
}
Also used : RegExpCellFactory(org.knime.base.node.preproc.columnTrans.RegExpCellFactory) BinaryCellFactory(org.knime.base.node.preproc.columnTrans.BinaryCellFactory) AbstractMany2OneCellFactory(org.knime.base.node.preproc.columnTrans.AbstractMany2OneCellFactory) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) MinMaxCellFactory(org.knime.base.node.preproc.columnTrans.MinMaxCellFactory)

Aggregations

AbstractMany2OneCellFactory (org.knime.base.node.preproc.columnTrans.AbstractMany2OneCellFactory)2 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)2 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)2 BinaryCellFactory (org.knime.base.node.preproc.columnTrans.BinaryCellFactory)1 MinMaxCellFactory (org.knime.base.node.preproc.columnTrans.MinMaxCellFactory)1 RegExpCellFactory (org.knime.base.node.preproc.columnTrans.RegExpCellFactory)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 PortObject (org.knime.core.node.port.PortObject)1 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)1 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)1