此内容没有您所选择的语言版本。
Chapter 4. Options for invoking a PMML model
You can import PMML files into your Red Hat Process Automation Manager project using Business Central (Menu
Currently, embedding PMML calls directly in your Java application is the available method for deploying and executing PMML models that are integrated with Red Hat Process Automation Manager. Other options for invoking PMML models (such as with Process Server) will be available in a future release and will be added to PMML documentation.
For more information about including PMML assets with your project packaging and deployment method, see Packaging and deploying a Red Hat Process Automation Manager project.
A KIE container is local when the knowledge assets are either embedded directly into the calling program or are physically pulled in using Maven dependencies for the KJAR. You typically embed knowledge assets directly into a project if there is a tight relationship between the version of the code and the version of the PMML definition. Any changes to the decision take effect after you have intentionally updated and redeployed the application. A benefit of this approach is that proper operation does not rely on any external dependencies to the run time, which can be a limitation of locked-down environments.
Using Maven dependencies enables further flexibility because the specific version of the decision can dynamically change (for example, by using a system property), and it can be periodically scanned for updates and automatically updated. This introduces an external dependency on the deploy time of the service, but executes the decision locally, reducing reliance on an external service being available during run time.
Currently, embedding PMML calls directly in your Java application is the available method for deploying and executing PMML models that are integrated with Red Hat Process Automation Manager. Other options for invoking PMML models (such as with Process Server) will be available in a future release.
Prerequisite
A KJAR containing the PMML model to execute has been created. For more information about project packaging, see Packaging and deploying a Red Hat Process Automation Manager project.
Procedure
In your client application, add the following dependencies to the relevant classpath of your Java project:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
<version>
is the Maven artifact version for Red Hat Process Automation Manager currently used in your project (for example, 7.14.0.Final-redhat-00002).NoteInstead of specifying a Red Hat Process Automation Manager
<version>
for individual dependencies, consider adding the Red Hat Business Automation bill of materials (BOM) dependency to your projectpom.xml
file. The Red Hat Business Automation BOM applies to both Red Hat Decision Manager and Red Hat Process Automation Manager. When you add the BOM files, the correct versions of transitive dependencies from the provided Maven repositories are included in the project.Example BOM dependency:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information about the Red Hat Business Automation BOM, see What is the mapping between RHPAM product and maven library version?.
Create a KIE container from
classpath
orReleaseId
:KieServices kieServices = KieServices.Factory.get(); ReleaseId releaseId = kieServices.newReleaseId( "org.acme", "my-kjar", "1.0.0" ); KieContainer kieContainer = kieServices.newKieContainer( releaseId );
KieServices kieServices = KieServices.Factory.get(); ReleaseId releaseId = kieServices.newReleaseId( "org.acme", "my-kjar", "1.0.0" ); KieContainer kieContainer = kieServices.newKieContainer( releaseId );
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Alternative option:
KieServices kieServices = KieServices.Factory.get(); KieContainer kieContainer = kieServices.getKieClasspathContainer();
KieServices kieServices = KieServices.Factory.get(); KieContainer kieContainer = kieServices.getKieClasspathContainer();
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create an instance of the
PMMLRequestData
class, which applies your PMML model to a set of data:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create an instance of the
PMML4Result
class, which holds the output information that is the result of applying the PMML-based rules to the input data:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Used when the model type is
MiningModel
. ThesegmentationId
is used to differentiate between multiple segmentations. - 2
- Used in conjunction with the
segmentationId
to identify which segment generated the results. - 3
- Used to maintain the order of segments.
- 4
- Used to determine whether the model was successfully applied, where
OK
indicates success. - 5
- Contains the name of a resultant variable and its associated value.
In addition to the normal getter methods, the
PMML4Result
class also supports the following methods for directly retrieving the values for result variables:public <T> Optional<T> getResultValue(String objName, String objField, Class<T> clazz, Object...params) public Object getResultValue(String objName, String objField, Object...params)
public <T> Optional<T> getResultValue(String objName, String objField, Class<T> clazz, Object...params) public Object getResultValue(String objName, String objField, Object...params)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create an instance of the
ParameterInfo
class, which serves as a wrapper for basic data type objects used as part of thePMMLRequestData
class:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Execute the PMML model based on the required PMML class instances that you have created:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Rules are executed by the
RuleUnitExecutor
class. TheRuleUnitExecutor
class creates KIE sessions and adds the requiredDataSource
objects to those sessions, and then executes the rules based on theRuleUnit
that is passed as a parameter to therun()
method. ThecalculatePossiblePackageNames
and thegetStartingRuleUnit
methods determine the fully qualified name of theRuleUnit
class that is passed to therun()
method.
To facilitate your PMML model execution, you can also use a PMML4ExecutionHelper
class supported in Red Hat Process Automation Manager. For more information about the PMML helper class, see Section 4.1.1, “PMML execution helper class”.
4.1.1. PMML execution helper class 复制链接链接已复制到粘贴板!
Red Hat Process Automation Manager provides a PMML4ExecutionHelper
class that helps create the PMMLRequestData
class required for PMML model execution and that helps execute rules using the RuleUnitExecutor
class.
The following are examples of a PMML model execution without and with the PMML4ExecutionHelper
class, as a comparison:
Example PMML model execution without using PMML4ExecutionHelper
Example PMML model execution using PMML4ExecutionHelper
When you use the PMML4ExecutionHelper
, you do not need to specify the possible package names nor the RuleUnit
class as you would in a typical PMML model execution.
To construct a PMML4ExecutionHelper
class, you use the PMML4ExecutionHelperFactory
class to determine how instances of PMML4ExecutionHelper
are retrieved.
The following are the available PMML4ExecutionHelperFactory
class methods for constructing a PMML4ExecutionHelper
class:
- PMML4ExecutionHelperFactory methods for PMML assets in a KIE base
Use these methods when PMML assets have already been compiled and are being used from an existing KIE base:
public static PMML4ExecutionHelper getExecutionHelper(String modelName, KieBase kbase) public static PMML4ExecutionHelper getExecutionHelper(String modelName, KieBase kbase, boolean includeMiningDataSources)
public static PMML4ExecutionHelper getExecutionHelper(String modelName, KieBase kbase) public static PMML4ExecutionHelper getExecutionHelper(String modelName, KieBase kbase, boolean includeMiningDataSources)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - PMML4ExecutionHelperFactory methods for PMML assets on the project classpath
Use these methods when PMML assets are on the project classpath. The
classPath
argument is the project classpath location of the PMML file:public static PMML4ExecutionHelper getExecutionHelper(String modelName, String classPath, KieBaseConfiguration kieBaseConf) public static PMML4ExecutionHelper getExecutionHelper(String modelName,String classPath, KieBaseConfiguration kieBaseConf, boolean includeMiningDataSources)
public static PMML4ExecutionHelper getExecutionHelper(String modelName, String classPath, KieBaseConfiguration kieBaseConf) public static PMML4ExecutionHelper getExecutionHelper(String modelName,String classPath, KieBaseConfiguration kieBaseConf, boolean includeMiningDataSources)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - PMML4ExecutionHelperFactory methods for PMML assets in a byte array
Use these methods when PMML assets are in the form of a byte array:
public static PMML4ExecutionHelper getExecutionHelper(String modelName, byte[] content, KieBaseConfiguration kieBaseConf) public static PMML4ExecutionHelper getExecutionHelper(String modelName, byte[] content, KieBaseConfiguration kieBaseConf, boolean includeMiningDataSources)
public static PMML4ExecutionHelper getExecutionHelper(String modelName, byte[] content, KieBaseConfiguration kieBaseConf) public static PMML4ExecutionHelper getExecutionHelper(String modelName, byte[] content, KieBaseConfiguration kieBaseConf, boolean includeMiningDataSources)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - PMML4ExecutionHelperFactory methods for PMML assets in a
Resource
Use these methods when PMML assets are in the form of an
org.kie.api.io.Resource
object:public static PMML4ExecutionHelper getExecutionHelper(String modelName, Resource resource, KieBaseConfiguration kieBaseConf) public static PMML4ExecutionHelper getExecutionHelper(String modelName, Resource resource, KieBaseConfiguration kieBaseConf, boolean includeMiningDataSources)
public static PMML4ExecutionHelper getExecutionHelper(String modelName, Resource resource, KieBaseConfiguration kieBaseConf) public static PMML4ExecutionHelper getExecutionHelper(String modelName, Resource resource, KieBaseConfiguration kieBaseConf, boolean includeMiningDataSources)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The classpath, byte array, and resource PMML4ExecutionHelperFactory
methods create a KIE container for the generated rules and Java classes. The container is used as the source of the KIE base that the RuleUnitExecutor
uses. The container is not persisted. The PMML4ExecutionHelperFactory
method for PMML assets that are already in a KIE base does not create a KIE container in this way.