Search in sources :

Example 6 with MapValues

use of org.dmg.pmml.MapValuesDocument.MapValues in project knime-core by knime.

the class CategoryToNumberApplyNodeModel method getMapValues.

/**
 * @param model the PMML model
 * @return the field in the first FieldColumnPair of the MapValues mapped
 * to the MapValues Model
 */
private Map<String, DerivedField> getMapValues(final PMMLPortObject model) {
    Map<String, DerivedField> mapValues = new LinkedHashMap<String, DerivedField>();
    DerivedField[] derivedFields = model.getDerivedFields();
    for (DerivedField derivedField : derivedFields) {
        MapValues map = derivedField.getMapValues();
        if (null != map) {
            // This is the field name the mapValues is based on
            String name = map.getFieldColumnPairArray()[0].getField();
            mapValues.put(name, derivedField);
        }
    }
    return mapValues;
}
Also used : MapValues(org.dmg.pmml.MapValuesDocument.MapValues) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with MapValues

use of org.dmg.pmml.MapValuesDocument.MapValues in project knime-core by knime.

the class NumberToCategoryApplyNodeModel method createRearranger.

/**
 * Creates a rearranger that processes the derived fields with MapValues
 * in the given model.
 */
private ColumnRearranger createRearranger(final DataTableSpec spec, final PMMLPortObject model) {
    // Retrieve columns with string data in the spec
    Set<String> intCols = new LinkedHashSet<String>();
    Set<String> otherCols = new LinkedHashSet<String>();
    for (DataColumnSpec colSpec : spec) {
        if (colSpec.getType().isCompatible(IntValue.class)) {
            intCols.add(colSpec.getName());
        } else {
            otherCols.add(colSpec.getName());
        }
    }
    if (intCols.isEmpty()) {
        if (null == model) {
            // during configure
            setWarningMessage("No columns to process.");
        } else {
            // during execute
            setWarningMessage("No columns to process, returning input.");
        }
    }
    // The map values in the model if present
    Map<String, DerivedField> mapValues = null != model ? getMapValues(model) : Collections.<String, DerivedField>emptyMap();
    // Create rearranger
    ColumnRearranger rearranger = new ColumnRearranger(spec);
    for (String col : mapValues.keySet()) {
        DerivedField derivedField = mapValues.get(col);
        MapValues map = derivedField.getMapValues();
        // this PMML MapValues model is found but has wrong type.
        if (null != model && otherCols.contains(col)) {
            String outColumn = null == derivedField.getDisplayName() || derivedField.getDisplayName().trim().isEmpty() ? derivedField.getName() : derivedField.getDisplayName();
            LOGGER.warn("Cannot create column \"" + outColumn + "\" since the input column \"" + col + "\" is not of type IntValue.");
            continue;
        }
        // this PMML MapValues model.
        if (null != model && !intCols.contains(col)) {
            String outColumn = derivedField.getMapValues().getFieldColumnPairList().get(0).getField();
            LOGGER.warn("Cannot create column \"" + outColumn + "\" since the column \"" + col + "\" is not in the input.");
            continue;
        }
        NumberToCategoryApplyCellFactory factory = new NumberToCategoryApplyCellFactory(spec, col, m_settings, map);
        if (m_settings.getAppendColumns()) {
            rearranger.append(factory);
        } else {
            rearranger.replace(factory, col);
        }
    }
    return rearranger;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) MapValues(org.dmg.pmml.MapValuesDocument.MapValues) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField)

Aggregations

DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)7 MapValues (org.dmg.pmml.MapValuesDocument.MapValues)7 FieldColumnPair (org.dmg.pmml.FieldColumnPairDocument.FieldColumnPair)3 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 QName (javax.xml.namespace.QName)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 InlineTable (org.dmg.pmml.InlineTableDocument.InlineTable)2 Row (org.dmg.pmml.RowDocument.Row)2 DataCell (org.knime.core.data.DataCell)2 DataColumnSpec (org.knime.core.data.DataColumnSpec)2 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Aggregate (org.dmg.pmml.AggregateDocument.Aggregate)1 Apply (org.dmg.pmml.ApplyDocument.Apply)1 DataDictionary (org.dmg.pmml.DataDictionaryDocument.DataDictionary)1 DataField (org.dmg.pmml.DataFieldDocument.DataField)1 Discretize (org.dmg.pmml.DiscretizeDocument.Discretize)1 FieldRef (org.dmg.pmml.FieldRefDocument.FieldRef)1