kie-pmml-trusty/DeveloperGuide.md
kie-pmml-trusty is a PMML engine implementing PMML specs.
The overall architectural design is inspired by "Clean architecture" principles. More details on that may be read here.
This project is meant to be used as standalone-library, and clearly defines two lifecycles:
Some models may rely only on plain java code-generation, while others may use the drools engine.
There are multiple modules and submodules inside kie-pmml-trusty, but the most important are
For every model' module, there are the following submodules:
Classes to be implemented:
For integration tests:
Code generation is done using JavaParser library and is strongly based on templates. Template files are saved with the .tmpl extension. The preferred way to work with java generation is to use java methods to create/modify coe, and rely on plain string replacement/manipulation only for specific cases. kie-pmml-compiler/kie-pmml-compiler-commons module contains a lot of already written/tested functionalities, especially for code-generation. When a new code-generation-related method is needed, please add it inside the above module, covering it with unit test.
PMML compilation may actually happen in two different phases:
In the former case a KiePMML(modelName)ModelWithSources has to be created/instantiated, and it will work as DTO. Client code (maven plugin/kogito codegen) will retrieve sources from it and compile/package them. In the latter case, or even for runtime evaluation, a KiePMML(modelName)Model has to be created/instantiated, and it will be used directly for evaluation.
Latest PMML specs may define new fields, or made some of them mandatory while they were optional previously. To comply with that, a "normalization" phase is implemented inside org.kie.pmml.compiler.commons.utils.KiePMMLUtil.
For each model, a "Factory" class has to be generated. This factory represents the "entry point" for model evaluation. At runtime, each model should live in its own "kieBase" context to avoid interference between them.
Service discovery is done with standard java SPI. Please check for org.kie.pmml.compiler.api.provider.ModelImplementationProvider (compiler) and org.kie.pmml.evaluator.core.executor.PMMLModelEvaluator (evaluator) files if services are not found.
Code generation is made directly. Creates one or more abstract classes to contain as much code as possible, and code-generate actual implementations just to pass parameters.
Such models require an additional step, i.e creation of rules files. To do that, AST files have to be generated and transformed in packages. kie-pmml-models/kie-pmml-models-drools/kie-pmml-models-drools-commons module contains a lot of already written/tested functionalities, especially for AST-generation. When a new AST-generation-related method is needed, please add it inside the above module, covering it with unit test. Since this models must live in different kiebases, but the user must not be concerned with that, i.e. he/she should not be forced to create a kmodule.xml to specify the kiebase for each of them, even because we may choose to change the kiebase name policy. To allow that, two additional classes are generated: PMMLRuleMappersImpl and PMMLRuleMapperImpl: those are needed to load drools-rules at runtime, without the needs of kmodule.xml.
Please keep updated Release and CurrentLimitations file while implementing new features or discovering missing ones.