Search in sources :

Example 1 with BayesPackage

use of org.drools.beliefs.bayes.assembler.BayesPackage in project drools by kiegroup.

the class BayesRuntimeImpl method createInstance.

// @Override
// public BayesInstance createBayesFact(Class cls) {
// // using the two-tone pattern, to ensure only one is created
// BayesInstance instance = instances.get( cls.getName() );
// if ( instance == null ) {
// instance = createInstance(cls);
// }
// 
// return instance;
// }
public BayesInstance createInstance(Class cls) {
    // synchronised using the two-tone pattern, to ensure only one is created
    // BayesInstance instance = instances.get( cls.getName() );
    // if ( instance != null ) {
    // return instance;
    // }
    InternalKnowledgePackage kpkg = (InternalKnowledgePackage) runtime.getKieBase().getKiePackage(cls.getPackage().getName());
    Map<ResourceType, ResourceTypePackage> map = kpkg.getResourceTypePackages();
    BayesPackage bayesPkg = (BayesPackage) map.get(ResourceType.BAYES);
    JunctionTree jtree = bayesPkg.getJunctionTree(cls.getSimpleName());
    BayesInstance instance = new BayesInstance(jtree, cls);
    return instance;
}
Also used : BayesPackage(org.drools.beliefs.bayes.assembler.BayesPackage) BayesInstance(org.drools.beliefs.bayes.BayesInstance) JunctionTree(org.drools.beliefs.bayes.JunctionTree) ResourceType(org.kie.api.io.ResourceType) ResourceTypePackage(org.kie.api.internal.io.ResourceTypePackage) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 2 with BayesPackage

use of org.drools.beliefs.bayes.assembler.BayesPackage in project drools by kiegroup.

the class BayesWeaverService method merge.

@Override
public void merge(KieBase kieBase, KiePackage kiePkg, BayesPackage bayesPkg) {
    Map<ResourceType, ResourceTypePackage> map = ((InternalKnowledgePackage) kiePkg).getResourceTypePackages();
    BayesPackage existing = (BayesPackage) map.get(ResourceType.BAYES);
    if (existing == null) {
        existing = new BayesPackage();
        map.put(ResourceType.BAYES, existing);
    }
    for (String name : bayesPkg.listJunctionTrees()) {
        existing.addJunctionTree(name, bayesPkg.getJunctionTree(name));
    }
}
Also used : BayesPackage(org.drools.beliefs.bayes.assembler.BayesPackage) ResourceType(org.kie.api.io.ResourceType) ResourceTypePackage(org.kie.api.internal.io.ResourceTypePackage) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 3 with BayesPackage

use of org.drools.beliefs.bayes.assembler.BayesPackage in project drools by kiegroup.

the class AssemblerTest method testBayesPackageAssembly.

@Test
public void testBayesPackageAssembly() throws Exception {
    KnowledgeBuilderImpl kbuilder = new KnowledgeBuilderImpl();
    kbuilder.add(ResourceFactory.newClassPathResource("Garden.xmlbif", AssemblerTest.class), ResourceType.BAYES);
    InternalKnowledgePackage kpkg = kbuilder.getPackageRegistry("org.drools.beliefs.bayes.integration").getPackage();
    BayesPackage bkpg = (BayesPackage) kpkg.getResourceTypePackages().get(ResourceType.BAYES);
    assertNotNull(bkpg.getJunctionTree("Garden"));
}
Also used : BayesPackage(org.drools.beliefs.bayes.assembler.BayesPackage) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) Test(org.junit.Test)

Example 4 with BayesPackage

use of org.drools.beliefs.bayes.assembler.BayesPackage in project drools by kiegroup.

the class WeaverTest method testBayesPackageWeaving.

@Test
public void testBayesPackageWeaving() throws Exception {
    KnowledgeBuilderImpl kbuilder = new KnowledgeBuilderImpl();
    kbuilder.add(ResourceFactory.newClassPathResource("Garden.xmlbif", AssemblerTest.class), ResourceType.BAYES);
    InternalKnowledgeBase kbase = getKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    InternalKnowledgePackage kpkg = (InternalKnowledgePackage) kbase.getKiePackage("org.drools.beliefs.bayes.integration");
    Map<ResourceType, ResourceTypePackage> map = kpkg.getResourceTypePackages();
    BayesPackage existing = (BayesPackage) map.get(ResourceType.BAYES);
    JunctionTree jtree = existing.getJunctionTree("Garden");
    assertNotNull(jtree);
}
Also used : BayesPackage(org.drools.beliefs.bayes.assembler.BayesPackage) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) JunctionTree(org.drools.beliefs.bayes.JunctionTree) ResourceType(org.kie.api.io.ResourceType) ResourceTypePackage(org.kie.api.internal.io.ResourceTypePackage) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) Test(org.junit.Test)

Aggregations

BayesPackage (org.drools.beliefs.bayes.assembler.BayesPackage)4 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)4 ResourceTypePackage (org.kie.api.internal.io.ResourceTypePackage)3 ResourceType (org.kie.api.io.ResourceType)3 JunctionTree (org.drools.beliefs.bayes.JunctionTree)2 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)2 Test (org.junit.Test)2 BayesInstance (org.drools.beliefs.bayes.BayesInstance)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1