public interface Evaluator extends Consumer
Performs the evaluation of a Model in "interpreted mode".
PMML pmml = ...; PMMLManager pmmlManager = new PMMLManager(pmml); Evaluator evaluator = (Evaluator)pmmlManager.getModelManager(ModelEvaluatorFactory.getInstance()); evaluator.verify();
Map<FieldName, ?> userArguments = ...;
Map<FieldName, FieldValue> arguments = new LinkedHashMap<FieldName, FieldValue>();
List<FieldName> activeFields = evaluator.getActiveFields();
for(FieldName activeField : activeFields){
FieldValue activeValue = evaluator.prepare(activeField, userArguments.get(activeField));
arguments.put(activeField, activeValue);
}
Map<FieldName, ?> result = evaluator.evaluate(arguments);
target field (ie. the primary result):
FieldName targetField = evaluator.getTargetField(); Object targetValue = result.get(targetField);Decoding a
complex value to a Java primitive value:
if(targetValue instanceof Computable){
Computable computable = (Computable)targetValue;
targetValue = computable.getResult();
}
Retrieving the values of output fields (ie. secondary results):
List<FieldName> outputFields = evaluator.getOutputFields();
for(FieldName outputField : outputFields){
Object outputValue = result.get(outputField);
}
EvaluatorUtil| Modifier and Type | Method and Description |
|---|---|
Map<org.dmg.pmml.FieldName,?> |
evaluate(Map<org.dmg.pmml.FieldName,?> arguments)
Evaluates the model with the specified arguments.
|
FieldValue |
prepare(org.dmg.pmml.FieldName name,
Object value)
Prepares the input value for a field.
|
void |
verify()
Verifies the model.
|
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)void verify()
PMMLException - If the verification fails.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 © 2015. All Rights Reserved.