Java Code Examples for org.jpmml.evaluator.Evaluator#getActiveFields()

The following examples show how to use org.jpmml.evaluator.Evaluator#getActiveFields() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MLModelRegistryService.java    From registry with Apache License 2.0 5 votes vote down vote up
private List<MLModelField> doGetInputFieldsFromPMMLStream(String pmmlContents) throws SAXException, JAXBException {
    final List<MLModelField> fieldNames = new ArrayList<>();
    PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes())));
    Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
    for (FieldName predictedField : modelEvaluator.getActiveFields()) {
        fieldNames.add(getModelField(modelEvaluator.getDataField(predictedField)));
    }
    return fieldNames;
}
 
Example 2
Source File: MLModelRegistryService.java    From streamline with Apache License 2.0 5 votes vote down vote up
private List<MLModelField> doGetInputFieldsFromPMMLStream(String pmmlContents) throws SAXException, JAXBException, UnsupportedEncodingException {
    final List<MLModelField> fieldNames = new ArrayList<>();
    PMMLManager pmmlManager = new PMMLManager(IOUtil.unmarshal(new ByteArrayInputStream(pmmlContents.getBytes("UTF-8"))));
    Evaluator modelEvaluator = (ModelEvaluator<?>) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());
    for (FieldName predictedField: modelEvaluator.getActiveFields()) {
        fieldNames.add(getModelField(modelEvaluator.getDataField(predictedField)));
    }
    return fieldNames;
}
 
Example 3
Source File: PmmlProcessorConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@ServiceActivator(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public Object evaluate(Message<?> input) {
	Model model = selectModel(input);
	Evaluator evaluator = modelEvaluatorFactory.newModelManager(pmml, model);

	Map<FieldName, FieldValue> arguments = new LinkedHashMap<>();

	List<FieldName> activeFields = evaluator.getActiveFields();
	for (FieldName activeField : activeFields) {
		// The raw (ie. user-supplied) value could be any Java primitive value
		Object rawValue = resolveActiveValue(input, activeField.getValue());

		// The raw value is passed through:
		// 1) outlier treatment,
		// 2) missing value treatment,
		// 3) invalid value treatment
		// and 4) type conversion
		FieldValue activeValue = evaluator.prepare(activeField, rawValue);

		arguments.put(activeField, activeValue);
	}

	Map<FieldName, ?> results = evaluator.evaluate(arguments);

	MutableMessage<?> result = convertToMutable(input);

	for (Map.Entry<FieldName, ?> entry : results.entrySet()) {

                       String fieldName = null;
                       if (entry.getKey()==null)
                           fieldName = DEFAULT_OUTPUT_FIELD;
                       else 
		    fieldName = entry.getKey().getValue();

		Expression expression = properties.getOutputs().get(fieldName);
		if (expression == null) {
			expression = spelExpressionParser.parseExpression("payload." + fieldName);
		}
		if (logger.isDebugEnabled()) {
			logger.debug("Setting result field named " + fieldName + " using SpEL[" + expression + " = "
					+ entry.getValue() + "]");
		}
		expression.setValue(evaluationContext, result, entry.getValue());
	}

	return result;

}