Search in sources :

Example 81 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec 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 82 with PortObjectSpec

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

the class PMCCNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec in = (DataTableSpec) inSpecs[0];
    if (!in.containsCompatibleType(DoubleValue.class) && !in.containsCompatibleType(NominalValue.class)) {
        throw new InvalidSettingsException("Neither double nor nominal compatible columns in input");
    }
    List<String> includes = m_columnIncludesList.getIncludeList();
    List<String> excludes = m_columnIncludesList.getExcludeList();
    // not configured yet?
    if (includes.isEmpty() && excludes.isEmpty()) {
        ArrayList<String> includeDefault = new ArrayList<String>();
        for (DataColumnSpec s : in) {
            if (s.getType().isCompatible(DoubleValue.class) || s.getType().isCompatible(NominalValue.class)) {
                includeDefault.add(s.getName());
            }
        }
        m_columnIncludesList.setIncludeList(includeDefault);
        includes = m_columnIncludesList.getIncludeList();
        setWarningMessage("Auto configuration: Using all suitable " + "columns (in total " + includes.size() + ")");
    }
    for (String s : includes) {
        DataColumnSpec sp = in.getColumnSpec(s);
        if (sp == null) {
            throw new InvalidSettingsException("No such column: " + s);
        }
        if (!sp.getType().isCompatible(DoubleValue.class) && !sp.getType().isCompatible(NominalValue.class)) {
            throw new InvalidSettingsException("Column is neither double " + "nor nominal compatible: " + s);
        }
    }
    String[] toArray = includes.toArray(new String[includes.size()]);
    return new PortObjectSpec[] { PMCCPortObjectAndSpec.createOutSpec(toArray), new PMCCPortObjectAndSpec(toArray) };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DoubleValue(org.knime.core.data.DoubleValue) NominalValue(org.knime.core.data.NominalValue) ArrayList(java.util.ArrayList) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString)

Example 83 with PortObjectSpec

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

the class JavaEditVarNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    m_snippet.setSettings(m_settings);
    FlowVariableRepository flowVarRepository = new FlowVariableRepository(getAvailableInputFlowVariables());
    ValidationReport report = m_snippet.validateSettings(new DataTableSpec(), flowVarRepository);
    if (report.hasWarnings()) {
        setWarningMessage(StringUtils.join(report.getWarnings(), "\n"));
    }
    if (report.hasErrors()) {
        throw new InvalidSettingsException(StringUtils.join(report.getErrors(), "\n"));
    }
    m_snippet.configure(new DataTableSpec(), flowVarRepository);
    for (FlowVariable flowVar : flowVarRepository.getModified()) {
        if (flowVar.getType().equals(Type.INTEGER)) {
            pushFlowVariableInt(flowVar.getName(), flowVar.getIntValue());
        } else if (flowVar.getType().equals(Type.DOUBLE)) {
            pushFlowVariableDouble(flowVar.getName(), flowVar.getDoubleValue());
        } else {
            pushFlowVariableString(flowVar.getName(), flowVar.getStringValue());
        }
    }
    // execute if execute on config flag is set
    if (!m_settings.isRunOnExecute()) {
        performExecute(null);
    }
    return new PortObjectSpec[] { FlowVariablePortObjectSpec.INSTANCE };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) FlowVariableRepository(org.knime.base.node.jsnippet.util.FlowVariableRepository) ValidationReport(org.knime.base.node.jsnippet.util.ValidationReport) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 84 with PortObjectSpec

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

the class NumericOutliersApplyNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec outlierPortSpec = (DataTableSpec) inSpecs[0];
    final DataTableSpec inTableSpec = (DataTableSpec) inSpecs[1];
    // ensure that the in data table contains the group columns that were used to learn the outlier reviser
    final String[] groupColNames = NumericOutlierPortObject.getGroupColNames(outlierPortSpec);
    final String[] missingGroupColNames = // 
    Arrays.stream(groupColNames).filter(// 
    g -> !inTableSpec.containsName(g)).toArray(String[]::new);
    if (missingGroupColNames.length > 0) {
        throw new InvalidSettingsException(MISSING_GROUPS_EXCEPTION_PREFIX + ConvenienceMethods.getShortStringFrom(Arrays.asList(missingGroupColNames), MAX_PRINT));
    }
    // check if the data type for the groups differs between those the model was trained on and the input table
    final String[] groupSpecNames = NumericOutlierPortObject.getGroupSpecNames(outlierPortSpec);
    final String[] wrongDataType = // 
    IntStream.range(0, groupColNames.length).filter(i -> outlierPortSpec.getColumnSpec(groupSpecNames[i]).getType() != inTableSpec.getColumnSpec(groupColNames[i]).getType()).mapToObj(// 
    i -> groupColNames[i]).toArray(String[]::new);
    if (wrongDataType.length != 0) {
        throw new InvalidSettingsException(GROUPS_COMPATIBILITY_EXCEPTION_PREFIX + ConvenienceMethods.getShortStringFrom(Arrays.asList(wrongDataType), MAX_PRINT));
    }
    // get the outlier column names stored in the port spec
    final String[] outlierColNames = NumericOutlierPortObject.getOutlierColNames(outlierPortSpec);
    // check for outlier columns that are missing the input table
    final List<String> nonExistOrCompatibleOutliers = Arrays.stream(outlierColNames).filter(s -> (!inTableSpec.containsName(s) || // 
    !inTableSpec.getColumnSpec(s).getType().isCompatible(DoubleValue.class))).collect(Collectors.toList());
    // if all of them  are missing throw an exception
    if (outlierColNames.length == nonExistOrCompatibleOutliers.size()) {
        throw new InvalidSettingsException(MISSING_OUTLIERS_EXCEPTION_PREFIX + ConvenienceMethods.getShortStringFrom(Arrays.asList(outlierColNames), MAX_PRINT));
    }
    if (nonExistOrCompatibleOutliers.size() > 0) {
        setWarningMessage(MISSING_OUTLIERS_WARNING_PREFIX + ConvenienceMethods.getShortStringFrom(nonExistOrCompatibleOutliers, MAX_PRINT));
    }
    return new PortObjectSpec[] { NumericOutliersReviser.getOutTableSpec(inTableSpec), NumericOutliersReviser.getSummaryTableSpec(inTableSpec, groupColNames) };
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) PortObjectInput(org.knime.core.node.streamable.PortObjectInput) NumericOutliersReviser(org.knime.base.algorithms.outlier.NumericOutliersReviser) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) ConvenienceMethods(org.knime.core.node.util.ConvenienceMethods) PortType(org.knime.core.node.port.PortType) PortInput(org.knime.core.node.streamable.PortInput) SummaryInternals(org.knime.base.algorithms.outlier.NumericOutliersReviser.SummaryInternals) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PartitionInfo(org.knime.core.node.streamable.PartitionInfo) RowInput(org.knime.core.node.streamable.RowInput) NumericOutlierPortObject(org.knime.base.algorithms.outlier.NumericOutlierPortObject) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) IOException(java.io.IOException) OutputPortRole(org.knime.core.node.streamable.OutputPortRole) NodeModel(org.knime.core.node.NodeModel) Collectors(java.util.stream.Collectors) File(java.io.File) PortOutput(org.knime.core.node.streamable.PortOutput) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) List(java.util.List) BufferedDataTable(org.knime.core.node.BufferedDataTable) InputPortRole(org.knime.core.node.streamable.InputPortRole) NumericOutlierWarning(org.knime.base.algorithms.outlier.listeners.NumericOutlierWarning) DoubleValue(org.knime.core.data.DoubleValue) NumericOutlierWarningListener(org.knime.base.algorithms.outlier.listeners.NumericOutlierWarningListener) PortObject(org.knime.core.node.port.PortObject) MergeOperator(org.knime.core.node.streamable.MergeOperator) RowOutput(org.knime.core.node.streamable.RowOutput) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DoubleValue(org.knime.core.data.DoubleValue) PortObjectSpec(org.knime.core.node.port.PortObjectSpec)

Example 85 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec 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

PortObjectSpec (org.knime.core.node.port.PortObjectSpec)139 DataTableSpec (org.knime.core.data.DataTableSpec)93 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)86 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)35 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)30 DataColumnSpec (org.knime.core.data.DataColumnSpec)29 FlowVariablePortObjectSpec (org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)25 IOException (java.io.IOException)24 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)24 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)24 PortObject (org.knime.core.node.port.PortObject)19 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)16 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)16 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)14 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)13 File (java.io.File)12 ArrayList (java.util.ArrayList)12 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)12 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)12 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)12