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;
}
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;
}
Aggregations