Search in sources :

Example 46 with PMMLPortObjectSpecCreator

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

the class ClusterNodeModel method createPMMLSpec.

private PMMLPortObjectSpec createPMMLSpec(final PMMLPortObjectSpec pmmlSpec, final DataTableSpec originalSpec) throws InvalidSettingsException {
    List<String> includes;
    if (m_usedColumns.isKeepAllSelected()) {
        includes = new ArrayList<String>();
        for (DataColumnSpec col : originalSpec) {
            if (col.getType().isCompatible(DoubleValue.class)) {
                includes.add(col.getName());
            }
        }
    } else {
        includes = new ArrayList<String>();
        for (String s : m_usedColumns.getIncludeList()) {
            if (originalSpec.getColumnSpec(s).getType().isCompatible(DoubleValue.class)) {
                includes.add(s);
            }
        }
    }
    HashSet<String> colNameHash = new HashSet<String>(includes);
    // the order in this list is important, need to use the order defined
    // by DTS, not m_usedColumns
    List<String> activeCols = new LinkedList<String>();
    for (DataColumnSpec colSpec : originalSpec) {
        String name = colSpec.getName();
        if (colNameHash.remove(name)) {
            activeCols.add(name);
        }
    }
    if (!colNameHash.isEmpty()) {
        throw new InvalidSettingsException("Input table does not match " + "selected columns, unable to find column(s): " + colNameHash);
    }
    PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(pmmlSpec, originalSpec);
    creator.setLearningColsNames(activeCols);
    return creator.createSpec();
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) LinkedList(java.util.LinkedList) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 47 with PMMLPortObjectSpecCreator

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

the class NaiveBayesLearnerNodeModel2 method createPMMLSpec.

private PMMLPortObjectSpec createPMMLSpec(final DataTableSpec tableSpec, final PMMLPortObjectSpec modelSpec, final List<String> learnCols, final String classColumn) {
    final PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(modelSpec, tableSpec);
    pmmlSpecCreator.setLearningColsNames(learnCols);
    pmmlSpecCreator.setTargetColName(classColumn);
    final PMMLPortObjectSpec pmmlSpec = pmmlSpecCreator.createSpec();
    return pmmlSpec;
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 48 with PMMLPortObjectSpecCreator

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

the class One2ManyCol2PMMLNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inDataSpec = (DataTableSpec) inSpecs[0];
    m_appendOrgColName = false;
    String[] includes = m_includedColumns.applyTo(inDataSpec).getIncludes();
    if (includes.length <= 0) {
        setWarningMessage("No columns to transfrom selected. Will have no effect!");
    }
    // check if the values are present in the current spec
    if (includes.length > 0) {
        checkColumnsSpecs(inDataSpec);
    }
    CellFactory cellFactory = new One2ManyCellFactory(inDataSpec, Arrays.asList(includes), m_appendOrgColName);
    ColumnRearranger rearranger = createRearranger(inDataSpec, cellFactory);
    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 PortObjectSpec[] { 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) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) One2ManyCellFactory(org.knime.base.node.preproc.columntrans2.One2ManyCellFactory) One2ManyCellFactory(org.knime.base.node.preproc.columntrans2.One2ManyCellFactory) CellFactory(org.knime.core.data.container.CellFactory) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 49 with PMMLPortObjectSpecCreator

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

the class BinnerNodeModel method createPMMLModel.

/**
 * Creates the pmml port object.
 * @param the in-port pmml object. Can be <code>null</code> (optional in-port)
 */
private PMMLPortObject createPMMLModel(final PMMLPortObject inPMMLPort, final DataTableSpec inSpec, final DataTableSpec outSpec) {
    PMMLBinningTranslator trans = new PMMLBinningTranslator(m_columnToBins, m_columnToAppended, new DerivedFieldMapper(inPMMLPort));
    PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(inPMMLPort, outSpec);
    PMMLPortObject outPMMLPort = new PMMLPortObject(pmmlSpecCreator.createSpec(), inPMMLPort, inSpec);
    outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
    return outPMMLPort;
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 50 with PMMLPortObjectSpecCreator

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

the class Many2OneCol2PMMLNodeModel 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_pmmlOutEnabled) {
        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 = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
        /*
             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.columntrans2.AbstractMany2OneCellFactory) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) 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)

Aggregations

PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)62 DataTableSpec (org.knime.core.data.DataTableSpec)35 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)24 DataColumnSpec (org.knime.core.data.DataColumnSpec)21 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)21 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)19 BufferedDataTable (org.knime.core.node.BufferedDataTable)15 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)14 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)13 PortObject (org.knime.core.node.port.PortObject)13 DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)11 ArrayList (java.util.ArrayList)10 DoubleValue (org.knime.core.data.DoubleValue)10 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)9 LinkedList (java.util.LinkedList)6 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)6 HashSet (java.util.HashSet)4 LinkedHashSet (java.util.LinkedHashSet)4 DataCell (org.knime.core.data.DataCell)3 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)3