Search in sources :

Example 1 with TargetField

use of org.jpmml.evaluator.TargetField in project openscoring by openscoring.

the class ModelUtil method encodeTargetFields.

private static List<Field> encodeTargetFields(List<TargetField> targetFields) {
    Function<TargetField, Field> function = new Function<TargetField, Field>() {

        @Override
        public Field apply(TargetField targetField) {
            FieldName name = targetField.getName();
            // A "phantom" default target field
            if (targetField.isSynthetic()) {
                name = ModelResource.DEFAULT_NAME;
            }
            DataField dataField = targetField.getDataField();
            Field field = new Field(name.getValue());
            field.setName(dataField.getDisplayName());
            field.setDataType(targetField.getDataType());
            field.setOpType(targetField.getOpType());
            field.setValues(encodeValues(dataField));
            return field;
        }
    };
    List<Field> fields = new ArrayList<>(Lists.transform(targetFields, function));
    return fields;
}
Also used : InputField(org.jpmml.evaluator.InputField) OutputField(org.jpmml.evaluator.OutputField) DataField(org.dmg.pmml.DataField) TargetField(org.jpmml.evaluator.TargetField) Field(org.openscoring.common.Field) Function(com.google.common.base.Function) DataField(org.dmg.pmml.DataField) ArrayList(java.util.ArrayList) TargetField(org.jpmml.evaluator.TargetField) FieldName(org.dmg.pmml.FieldName)

Example 2 with TargetField

use of org.jpmml.evaluator.TargetField in project openscoring by openscoring.

the class ModelUtil method encodeSchema.

public static Map<String, List<Field>> encodeSchema(Evaluator evaluator) {
    Map<String, List<Field>> result = new LinkedHashMap<>();
    List<InputField> inputFields = evaluator.getInputFields();
    result.put("inputFields", encodeInputFields(inputFields));
    List<InputField> groupFields = Collections.emptyList();
    if (evaluator instanceof HasGroupFields) {
        HasGroupFields hasGroupFields = (HasGroupFields) evaluator;
        groupFields = hasGroupFields.getGroupFields();
    }
    result.put("groupFields", encodeInputFields(groupFields));
    List<TargetField> targetFields = evaluator.getTargetFields();
    result.put("targetFields", encodeTargetFields(targetFields));
    List<OutputField> outputFields = evaluator.getOutputFields();
    result.put("outputFields", encodeOutputFields(outputFields));
    return result;
}
Also used : HasGroupFields(org.jpmml.evaluator.HasGroupFields) InputField(org.jpmml.evaluator.InputField) OutputField(org.jpmml.evaluator.OutputField) ArrayList(java.util.ArrayList) List(java.util.List) TargetField(org.jpmml.evaluator.TargetField) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ArrayList (java.util.ArrayList)2 InputField (org.jpmml.evaluator.InputField)2 OutputField (org.jpmml.evaluator.OutputField)2 TargetField (org.jpmml.evaluator.TargetField)2 Function (com.google.common.base.Function)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 DataField (org.dmg.pmml.DataField)1 FieldName (org.dmg.pmml.FieldName)1 HasGroupFields (org.jpmml.evaluator.HasGroupFields)1 Field (org.openscoring.common.Field)1