Search in sources :

Example 1 with PMMLPackageImpl

use of org.kie.pmml.evaluator.assembler.container.PMMLPackageImpl in project drools by kiegroup.

the class PMMLRuntimeFactoryInternalTest method getKnowledgePackageWithPMMLResourceType.

private InternalKnowledgePackage getKnowledgePackageWithPMMLResourceType(KiePMMLModel kiePMMLModel) {
    PMMLPackage pmmlPkg = new PMMLPackageImpl();
    pmmlPkg.addAll(Collections.singleton(kiePMMLModel));
    InternalKnowledgePackage pmmlKnowledgePackage = CoreComponentFactory.get().createKnowledgePackage(kiePMMLModel.getKModulePackageName());
    pmmlKnowledgePackage.getResourceTypePackages().put(ResourceType.PMML, pmmlPkg);
    return pmmlKnowledgePackage;
}
Also used : PMMLPackage(org.kie.pmml.evaluator.api.container.PMMLPackage) PMMLPackageImpl(org.kie.pmml.evaluator.assembler.container.PMMLPackageImpl) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 2 with PMMLPackageImpl

use of org.kie.pmml.evaluator.assembler.container.PMMLPackageImpl in project drools by kiegroup.

the class PMMLRuntimeFactoryInternalTest method createKieBaseFromKnowledgeBuilder.

@Test
public void createKieBaseFromKnowledgeBuilder() {
    KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    knowledgeBuilder.addPackage(CoreComponentFactory.get().createKnowledgePackage("namespace_1"));
    knowledgeBuilder.addPackage(CoreComponentFactory.get().createKnowledgePackage("namespace_2"));
    PMMLPackage pmmlPkg = new PMMLPackageImpl();
    pmmlPkg.addAll(Collections.singleton(new KiePMMLTestingModel("FAKE", Collections.emptyList())));
    InternalKnowledgePackage pmmlKnowledgePackage = CoreComponentFactory.get().createKnowledgePackage("pmmled_package");
    pmmlKnowledgePackage.getResourceTypePackages().put(ResourceType.PMML, pmmlPkg);
    KieBase retrieved = PMMLRuntimeFactoryInternal.createKieBase(knowledgeBuilder);
    assertNotNull(retrieved);
    assertFalse(retrieved.getKiePackages().isEmpty());
    assertEquals(knowledgeBuilder.getKnowledgePackages().size(), retrieved.getKiePackages().size());
    knowledgeBuilder.getKnowledgePackages().forEach(kBuilderPackage -> {
        assertNotNull(retrieved.getKiePackage(kBuilderPackage.getName()));
        ResourceTypePackage knowledgeBuilderResourceTypePackage = ((InternalKnowledgePackage) kBuilderPackage).getResourceTypePackages().get(ResourceType.PMML);
        if (((InternalKnowledgePackage) kBuilderPackage).getResourceTypePackages().get(ResourceType.PMML) != null) {
            InternalKnowledgePackage retrievedKiePackage = (InternalKnowledgePackage) retrieved.getKiePackage(kBuilderPackage.getName());
            ResourceTypePackage retrievedResourceTypePackage = retrievedKiePackage.getResourceTypePackages().get(ResourceType.PMML);
            assertNotNull(retrievedKiePackage.getResourceTypePackages().get(ResourceType.PMML));
            assertEquals(knowledgeBuilderResourceTypePackage, retrievedResourceTypePackage);
        }
    });
}
Also used : PMMLPackage(org.kie.pmml.evaluator.api.container.PMMLPackage) PMMLPackageImpl(org.kie.pmml.evaluator.assembler.container.PMMLPackageImpl) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) KieBase(org.kie.api.KieBase) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) ResourceTypePackage(org.kie.api.internal.io.ResourceTypePackage) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) Test(org.junit.Test)

Example 3 with PMMLPackageImpl

use of org.kie.pmml.evaluator.assembler.container.PMMLPackageImpl 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)

Example 4 with PMMLPackageImpl

use of org.kie.pmml.evaluator.assembler.container.PMMLPackageImpl in project drools by kiegroup.

the class PMMLWeaverService method merge.

@Override
public void merge(KiePackage kiePkg, PMMLPackage dmnpkg) {
    ResourceTypePackageRegistry registry = ((InternalKnowledgePackage) kiePkg).getResourceTypePackages();
    PMMLPackageImpl existing = registry.computeIfAbsent(ResourceType.PMML, rt -> new PMMLPackageImpl());
    existing.addAll(dmnpkg.getAllModels().values());
}
Also used : PMMLPackageImpl(org.kie.pmml.evaluator.assembler.container.PMMLPackageImpl) ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Aggregations

InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)4 PMMLPackageImpl (org.kie.pmml.evaluator.assembler.container.PMMLPackageImpl)4 PMMLPackage (org.kie.pmml.evaluator.api.container.PMMLPackage)3 ResourceTypePackageRegistry (org.drools.core.definitions.ResourceTypePackageRegistry)2 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 ResourceTypePackage (org.kie.api.internal.io.ResourceTypePackage)1 HasNestedModels (org.kie.pmml.commons.model.HasNestedModels)1 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)1 KiePMMLTestingModel (org.kie.pmml.commons.testingutility.KiePMMLTestingModel)1