public interface Evaluator extends Consumer
Performs the evaluation of a Model in "interpreted mode".
Evaluator instance:
PMML pmml = ...; PMMLManager pmmlManager = new PMMLManager(pmml); Evaluator evaluator = (Evaluator)pmmlManager.getModelManager(ModelEvaluatorFactory.getInstance());Preparing
active fields:
Map<FieldName, FieldValue> arguments = new LinkedHashMap<FieldName, FieldValue>();
List<FieldName> activeFields = evaluator.getActiveFields();
for(FieldName activeField : activeFields){
FieldValue activeValue = evaluator.prepare(activeField, ...);
arguments.put(activeField, activeValue);
}
Performing the evaluation:
Map<FieldName, ?> result = evaluator.evaluate(arguments);Retrieving the value of the
target field and output fields:
FieldName targetField = evaluator.getTargetField();
Object targetValue = result.get(targetField);
List<FieldName> outputFields = evaluator.getOutputFields();
for(FieldName outputField : outputFields){
Object outputValue = result.get(outputField);
}
Decoding complex value to simple value:
Object value = ...;
if(value instanceof Computable){
Computable computable = (Computable)value;
value = computable.getResult();
}
EvaluatorUtil| Modifier and Type | Method and Description |
|---|---|
Map<org.dmg.pmml.FieldName,?> |
evaluate(Map<org.dmg.pmml.FieldName,?> arguments) |
FieldValue |
prepare(org.dmg.pmml.FieldName name,
Object value)
Prepares the input value for a field.
|
getActiveFields, getDataField, getGroupFields, getMiningField, getOrderFields, getOutputField, getOutputFields, getSummary, getTargetField, getTargetFieldsFieldValue prepare(org.dmg.pmml.FieldName name, Object value)
name - The name of the fieldstring - The input value in user-supplied representation. Use null to represent a missing input value.PMMLException - If the input value preparation fails.Consumer.getDataField(FieldName),
Consumer.getMiningField(FieldName)Map<org.dmg.pmml.FieldName,?> evaluate(Map<org.dmg.pmml.FieldName,?> arguments)
arguments - Map of active field values.target field and output field values.
Simple values are represented using the Java equivalents of PMML data types (eg. String, Integer, Float, Double etc.).
Complex values are represented as instances of Computable that return simple values.
A missing result is represented by null.PMMLException - If the evaluation fails.
This is either InvalidFeatureException or UnsupportedFeatureException if there is a persistent structural problem with the PMML class model.
This is EvaluationException (or one of its subclasses) if there is a problem with the evaluation request (eg. badly prepared arguments).ComputableCopyright © 2014. All Rights Reserved.