ExpressionUtil { static public FieldValue evaluateMapValues(MapValues mapValues, EvaluationContext context){ Map<String, FieldValue> values = new LinkedHashMap<>(); List<FieldColumnPair> fieldColumnPairs = mapValues.getFieldColumnPairs(); for(FieldColumnPair fieldColumnPair : fieldColumnPairs){ FieldName name = fieldColumnPair.getField(); if(name == null){ throw new MissingAttributeException(fieldColumnPair, PMMLAttributes.FIELDCOLUMNPAIR_FIELD); } String column = fieldColumnPair.getColumn(); if(column == null){ throw new MissingAttributeException(fieldColumnPair, PMMLAttributes.FIELDCOLUMNPAIR_COLUMN); } FieldValue value = context.evaluate(name); if(FieldValueUtil.isMissing(value)){ return FieldValueUtil.create(mapValues.getDataType(DataType.STRING), OpType.CATEGORICAL, mapValues.getMapMissingTo()); } values.put(column, value); } return DiscretizationUtil.mapValue(mapValues, values); } private  ExpressionUtil(); static FieldName ensureField(E hasField); static Expression ensureExpression(E hasExpression); static FieldValue evaluateExpressionContainer(E hasExpression, EvaluationContext context); static FieldValue evaluateTypedExpressionContainer(E hasTypedExpression, EvaluationContext context); static FieldValue evaluate(DerivedField derivedField, EvaluationContext context); static FieldValue evaluate(DefineFunction defineFunction, List<FieldValue> values, EvaluationContext context); static FieldValue evaluate(Expression expression, EvaluationContext context); static FieldValue evaluateConstant(Constant constant); static FieldValue evaluateFieldRef(FieldRef fieldRef, EvaluationContext context); static FieldValue evaluateNormContinuous(NormContinuous normContinuous, EvaluationContext context); static FieldValue evaluateNormDiscrete(NormDiscrete normDiscrete, EvaluationContext context); static FieldValue evaluateDiscretize(Discretize discretize, EvaluationContext context); static FieldValue evaluateMapValues(MapValues mapValues, EvaluationContext context); static FieldValue evaluateTextIndex(TextIndex textIndex, EvaluationContext context); static FieldValue evaluateApply(Apply apply, EvaluationContext context); @SuppressWarnings ( value = {"unchecked"} ) static FieldValue evaluateAggregate(Aggregate aggregate, EvaluationContext context); static FieldValue evaluateJavaExpression(JavaExpression javaExpression, EvaluationContext context); static boolean isEmptyContent(Object value);  }
@Test public void evaluateMapValues(){ FieldName name = FieldName.create("x"); List<List<String>> rows = Arrays.asList( Arrays.asList("0", "zero"), Arrays.asList("1", "one") ); MapValues mapValues = new MapValues("data:output", null, createInlineTable(rows, Arrays.asList("data:input", "data:output"))) .addFieldColumnPairs(new FieldColumnPair(name, "data:input")); assertEquals("zero", evaluate(mapValues, name, "0")); assertEquals("one", evaluate(mapValues, name, "1")); assertEquals(null, evaluate(mapValues, name, "3")); assertEquals(null, evaluate(mapValues, name, null)); mapValues.setMapMissingTo("Missing"); assertEquals("Missing", evaluate(mapValues, name, null)); mapValues.setDefaultValue("Default"); assertEquals("Default", evaluate(mapValues, name, "3")); }