Apama Predictive Analytics Plug-in 10.15 | Apama Predictive Analytics Plug-in | Working with Predictive Analytics Plug-in | User application EPL
 
User application EPL
A user application EPL script should perform the following tasks:
1. Create an instance of ServiceParams.
com.apama.pa.pmml.ServiceParams serviceParams :=
com.apama.pa.pmml.ServiceParamsHelper.create();
2. Set the configuration parameters.
serviceParams.setPMMLFileName("PMML_CONFIG_FILE_NAME");
serviceParams.addResource(CUSTOM_RESOURCE_NAME1);
serviceParams.addResource(CUSTOM_RESOURCE_NAME2);
For a full list of configuration parameters, see API Reference for Predictive Analytics Plug-in EPL (ApamaDoc).
3. Request the ServiceHandlerFactory to create a new service handler and pass the ServiceParams.
com.apama.pa.pmml.ServiceHandlerFactory
.create(com.apama.pa.pmml.ServiceName.Zementis,
"PREDICTIVE_ANALYTICS_INSTANCE_1",
serviceParams,
onServiceInitialised,
onServiceError);
You must pass two additional callbacks to the service handler factory.
*This callback is called when the PMML file is successfully loaded and the service is initialised. The ServiceHandler received in this callback can be used to retrieve the list of models available for this service.
action onServiceInitialised(com.apama.pa.pmml.ServiceHandler
servicehandler) {
//Implement your application logic here
}
*This callback is called if an error is encountered while loading the PMML file or when there is an issue with the input.
action onServiceError(com.apama.pa.pmml.ServiceError serviceError) {
log "Received Service Error " + serviceError.getErrorMessage() at ERROR;
}
4. Create an input event and pass it to the plug-in.
com.apama.pa.pmml.Input input := new com.apama.pa.pmml.Input;

input.instanceName := "PREDICTIVE_ANALYTICS_INSTANCE_1";
input.modelName := "SAMPLE_MODEL_NAME";
input.requestId := integer.getUnique().toString();
input.inputFields.add("FIELD_1", "FIELD_1_VALUE");
input.inputFields.add("FIELD_2", "FIELD_2_VALUE");
input.inputFields.add("FIELD_2", "FIELD_3_VALUE");

route input;
5. Check for the output event which corresponds to the specified input.
com.apama.pa.pmml.Output output;
on all com.apama.pa.pmml.Output
(instanceName="PREDICTIVE_ANALYTICS_INSTANCE_1") : output
{
log output.toString() at INFO;
//Do additional processing
}
Error handling when processing an input request:
*If there is a significant error while processing the input request, you will receive a callback on the onServiceError callback registered during service initialisation.
*Errors and warnings reported by the Predictive Analytics Engine are also propagated through the output event.
*If any errors are found during scoring, search for PredictiveAnalytics_Error in the outputFields
Example:
com.apama.pa.pmml.Output("Instance_1","206",
{"PredictiveAnalytics_Error":"Value [NA] is invalid for field [PreUse]."},{})
*Warnings reported by the scoring engine are also forwarded in the outputFields as PredictiveAnalytics_Warning_<N>, where N can be 1, 2, 3 ...
Example:
com.apama.pa.pmml.Output("Instance_1","206",
{"PredictiveAnalytics_Warning_1":"warning message",
"Predicted_Usage":"19.980840445004088"},{})