Search in sources :

Example 1 with ResourceTypePackageRegistry

use of org.drools.core.definitions.ResourceTypePackageRegistry 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 2 with ResourceTypePackageRegistry

use of org.drools.core.definitions.ResourceTypePackageRegistry in project drools by kiegroup.

the class DMNAssemblerService method compileResourceToModel.

private DMNModel compileResourceToModel(KnowledgeBuilderImpl kbuilderImpl, DMNCompiler dmnCompiler, Resource resource, DMNResource dmnRes, Collection<DMNModel> dmnModels) {
    DMNModel model = dmnRes != null ? dmnCompiler.compile(dmnRes.getDefinitions(), resource, dmnModels) : dmnCompiler.compile(resource, dmnModels);
    if (model != null) {
        String namespace = model.getNamespace();
        PackageRegistry pkgReg = kbuilderImpl.getOrCreatePackageRegistry(new PackageDescr(namespace));
        InternalKnowledgePackage kpkgs = pkgReg.getPackage();
        kpkgs.addCloningResource(DMN_COMPILER_CACHE_KEY, dmnCompiler);
        ResourceTypePackageRegistry rpkg = kpkgs.getResourceTypePackages();
        DMNPackageImpl dmnpkg = rpkg.computeIfAbsent(ResourceType.DMN, rtp -> new DMNPackageImpl(namespace));
        if (dmnpkg.getModel(model.getName()) != null) {
            kbuilderImpl.addBuilderResult(new DMNKnowledgeBuilderError(ResultSeverity.ERROR, resource, namespace, "Duplicate model name " + model.getName() + " in namespace " + namespace));
            logger.error("Duplicate model name {} in namespace {}", model.getName(), namespace);
        }
        dmnpkg.addModel(model.getName(), model);
        for (DMNMessage m : model.getMessages()) {
            kbuilderImpl.addBuilderResult(DMNKnowledgeBuilderError.from(resource, namespace, m));
        }
        dmnpkg.addProfiles(kbuilderImpl.getCachedOrCreate(DMN_PROFILES_CACHE_KEY, () -> getDMNProfiles(kbuilderImpl)));
    } else {
        kbuilderImpl.addBuilderResult(new DMNKnowledgeBuilderError(ResultSeverity.ERROR, resource, "Unable to compile DMN model for the resource"));
        logger.error("Unable to compile DMN model for the resource {}", resource.getSourcePath());
    }
    return model;
}
Also used : ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) PackageRegistry(org.drools.compiler.compiler.PackageRegistry) DMNPackageImpl(org.kie.dmn.core.impl.DMNPackageImpl) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNKnowledgeBuilderError(org.kie.dmn.core.impl.DMNKnowledgeBuilderError) PackageDescr(org.drools.drl.ast.descr.PackageDescr) ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) DMNModel(org.kie.dmn.api.core.DMNModel) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 3 with ResourceTypePackageRegistry

use of org.drools.core.definitions.ResourceTypePackageRegistry in project drools by kiegroup.

the class DMNRuntimeKBWrappingIKB method getModelById.

@Override
public DMNModel getModelById(String namespace, String modelId) {
    Objects.requireNonNull(namespace, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "namespace"));
    Objects.requireNonNull(modelId, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "modelId"));
    InternalKnowledgePackage kpkg = (InternalKnowledgePackage) knowledgeBase.getKiePackage(namespace);
    if (kpkg == null) {
        return null;
    }
    ResourceTypePackageRegistry map = kpkg.getResourceTypePackages();
    DMNPackage dmnpkg = (DMNPackage) map.get(ResourceType.DMN);
    return dmnpkg != null ? dmnpkg.getModelById(modelId) : null;
}
Also used : DMNPackage(org.kie.dmn.api.core.DMNPackage) ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 4 with ResourceTypePackageRegistry

use of org.drools.core.definitions.ResourceTypePackageRegistry in project drools by kiegroup.

the class BayesRuntimeImpl method createInstance.

public BayesInstance createInstance(Class cls) {
    InternalKnowledgePackage kpkg = (InternalKnowledgePackage) kieBase.getKiePackage(cls.getPackage().getName());
    ResourceTypePackageRegistry map = kpkg.getResourceTypePackages();
    BayesPackage bayesPkg = (BayesPackage) map.get(ResourceType.BAYES);
    JunctionTree jtree = bayesPkg.getJunctionTree(cls.getSimpleName());
    return new BayesInstance(jtree, cls);
}
Also used : BayesPackage(org.drools.beliefs.bayes.assembler.BayesPackage) BayesInstance(org.drools.beliefs.bayes.BayesInstance) JunctionTree(org.drools.beliefs.bayes.JunctionTree) ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 5 with ResourceTypePackageRegistry

use of org.drools.core.definitions.ResourceTypePackageRegistry 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

ResourceTypePackageRegistry (org.drools.core.definitions.ResourceTypePackageRegistry)9 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)8 JunctionTree (org.drools.beliefs.bayes.JunctionTree)2 BayesPackage (org.drools.beliefs.bayes.assembler.BayesPackage)2 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)2 PackageDescr (org.drools.drl.ast.descr.PackageDescr)2 DMNModel (org.kie.dmn.api.core.DMNModel)2 DMNPackage (org.kie.dmn.api.core.DMNPackage)2 DMNPackageImpl (org.kie.dmn.core.impl.DMNPackageImpl)2 PMMLPackageImpl (org.kie.pmml.evaluator.assembler.container.PMMLPackageImpl)2 Map (java.util.Map)1 BayesInstance (org.drools.beliefs.bayes.BayesInstance)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 ProcessPackage (org.drools.core.definitions.ProcessPackage)1 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)1 Test (org.junit.Test)1 DMNMessage (org.kie.dmn.api.core.DMNMessage)1 DMNKnowledgeBuilderError (org.kie.dmn.core.impl.DMNKnowledgeBuilderError)1 HasNestedModels (org.kie.pmml.commons.model.HasNestedModels)1 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)1