Search in sources :

Example 76 with PMMLPortObjectSpec

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

the class PMMLRuleEditorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    RuleSet ruleSet = RuleSet.Factory.newInstance();
    PMMLRuleParser parser = new PMMLRuleParser((DataTableSpec) inSpecs[0], getAvailableInputFlowVariables());
    try {
        ColumnRearranger rearranger = createRearranger((DataTableSpec) inSpecs[0], ruleSet, parser);
        PMMLPortObjectSpec portObjectSpec = createPMMLPortObjectSpec(rearranger.createSpec(), Collections.<String>emptyList());
        return new PortObjectSpec[] { rearranger.createSpec(), portObjectSpec };
    } catch (ParseException e) {
        throw new InvalidSettingsException(e);
    }
}
Also used : RuleSet(org.dmg.pmml.RuleSetDocument.RuleSet) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) ParseException(java.text.ParseException)

Example 77 with PMMLPortObjectSpec

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

the class DecisionTreeLearnerNodeModel method configure.

/**
 * The number of the class column must be > 0 and < number of input columns.
 *
 * @param inSpecs the tabel specs on the input port to use for configuration
 * @see NodeModel#configure(DataTableSpec[])
 * @throws InvalidSettingsException thrown if the configuration is not
 *             correct
 * @return the table specs for the output ports
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inSpec = (DataTableSpec) inSpecs[DATA_INPORT];
    PMMLPortObjectSpec modelSpec = (PMMLPortObjectSpec) inSpecs[MODEL_INPORT];
    // check spec with selected column
    String classifyColumn = m_classifyColumn.getStringValue();
    DataColumnSpec columnSpec = inSpec.getColumnSpec(classifyColumn);
    boolean isValid = columnSpec != null && columnSpec.getType().isCompatible(NominalValue.class);
    if (classifyColumn != null && !isValid) {
        throw new InvalidSettingsException("Class column \"" + classifyColumn + "\" not found or incompatible");
    }
    if (classifyColumn == null) {
        // auto-guessing
        assert !isValid : "No class column set but valid configuration";
        // get the first useful one starting at the end of the table
        for (int i = inSpec.getNumColumns() - 1; i >= 0; i--) {
            if (inSpec.getColumnSpec(i).getType().isCompatible(NominalValue.class)) {
                m_classifyColumn.setStringValue(inSpec.getColumnSpec(i).getName());
                super.setWarningMessage("Guessing target column: \"" + m_classifyColumn.getStringValue() + "\".");
                break;
            }
        }
        if (m_classifyColumn.getStringValue() == null) {
            throw new InvalidSettingsException("Table contains no nominal" + " attribute for classification.");
        }
    }
    return new PortObjectSpec[] { createPMMLPortObjectSpec(modelSpec, inSpec) };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NominalValue(org.knime.core.data.NominalValue) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)77 DataTableSpec (org.knime.core.data.DataTableSpec)57 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)40 DataColumnSpec (org.knime.core.data.DataColumnSpec)31 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)30 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)23 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)23 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)22 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)20 BufferedDataTable (org.knime.core.node.BufferedDataTable)15 PortObject (org.knime.core.node.port.PortObject)12 DataCell (org.knime.core.data.DataCell)10 DoubleValue (org.knime.core.data.DoubleValue)10 DataRow (org.knime.core.data.DataRow)8 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)7 ArrayList (java.util.ArrayList)6 LinkedList (java.util.LinkedList)6 DataColumnDomain (org.knime.core.data.DataColumnDomain)6 DoubleCell (org.knime.core.data.def.DoubleCell)6 IOException (java.io.IOException)4