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;
}
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));
}
}
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"));
}
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);
}
Aggregations