Search in sources :

Example 1 with HasNestedModels

use of org.kie.pmml.commons.model.HasNestedModels in project drools by kiegroup.

the class PMMLCompilerService method addPMMLRuleMapper.

static void addPMMLRuleMapper(final KiePMMLModel kiePMMLModel, final List<String> generatedRuleMappers, final String sourcePath) {
    if (!(kiePMMLModel instanceof HasSourcesMap)) {
        String errorMessage = String.format("Expecting HasSourcesMap instance, retrieved %s inside %s", kiePMMLModel.getClass().getName(), sourcePath);
        throw new KiePMMLException(errorMessage);
    }
    if (kiePMMLModel instanceof HasRule) {
        String pkgUUID = ((HasRule) kiePMMLModel).getPkgUUID();
        String rulesFileName = kiePMMLModel.getKModulePackageName() + "." + RULES_FILE_NAME + pkgUUID;
        String pmmlRuleMapper = kiePMMLModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME;
        String ruleMapperSource = PMMLRuleMapperFactory.getPMMLRuleMapperSource(rulesFileName);
        ((HasRule) kiePMMLModel).addSourceMap(pmmlRuleMapper, ruleMapperSource);
        generatedRuleMappers.add(pmmlRuleMapper);
    }
    if (kiePMMLModel instanceof HasNestedModels) {
        for (KiePMMLModel nestedModel : ((HasNestedModels) kiePMMLModel).getNestedModels()) {
            addPMMLRuleMapper(nestedModel, generatedRuleMappers, sourcePath);
        }
    }
}
Also used : HasRule(org.kie.pmml.commons.HasRule) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) HasNestedModels(org.kie.pmml.commons.model.HasNestedModels) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) HasSourcesMap(org.kie.pmml.commons.model.HasSourcesMap)

Example 2 with HasNestedModels

use of org.kie.pmml.commons.model.HasNestedModels in project drools by kiegroup.

the class PMMLAssemblerService method addModels.

protected void addModels(KnowledgeBuilderImpl kbuilderImpl, List<KiePMMLModel> toAdd) {
    for (KiePMMLModel kiePMMLModel : toAdd) {
        PackageDescr pkgDescr = new PackageDescr(kiePMMLModel.getKModulePackageName());
        PackageRegistry pkgReg = kbuilderImpl.getOrCreatePackageRegistry(pkgDescr);
        InternalKnowledgePackage kpkgs = pkgReg.getPackage();
        ResourceTypePackageRegistry rpkg = kpkgs.getResourceTypePackages();
        PMMLPackage pmmlPkg = rpkg.computeIfAbsent(ResourceType.PMML, rtp -> new PMMLPackageImpl());
        pmmlPkg.addAll(Collections.singletonList(kiePMMLModel));
        if (kiePMMLModel instanceof HasNestedModels) {
            addModels(kbuilderImpl, ((HasNestedModels) kiePMMLModel).getNestedModels());
        }
    }
}
Also used : PMMLPackage(org.kie.pmml.evaluator.api.container.PMMLPackage) ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) PackageRegistry(org.drools.compiler.compiler.PackageRegistry) PMMLPackageImpl(org.kie.pmml.evaluator.assembler.container.PMMLPackageImpl) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) HasNestedModels(org.kie.pmml.commons.model.HasNestedModels) PackageDescr(org.drools.drl.ast.descr.PackageDescr) ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Aggregations

HasNestedModels (org.kie.pmml.commons.model.HasNestedModels)2 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)2 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 ResourceTypePackageRegistry (org.drools.core.definitions.ResourceTypePackageRegistry)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)1 HasRule (org.kie.pmml.commons.HasRule)1 HasSourcesMap (org.kie.pmml.commons.model.HasSourcesMap)1 PMMLPackage (org.kie.pmml.evaluator.api.container.PMMLPackage)1 PMMLPackageImpl (org.kie.pmml.evaluator.assembler.container.PMMLPackageImpl)1