Search in sources :

Example 41 with RuleBaseConfiguration

use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.

the class PhreakNotNodeTest method createContext.

public BuildContext createContext() {
    RuleBaseConfiguration conf = new RuleBaseConfiguration();
    KnowledgeBaseImpl rbase = new KnowledgeBaseImpl("ID", conf);
    BuildContext buildContext = new BuildContext(rbase, Collections.emptyList());
    RuleImpl rule = new RuleImpl("rule1").setPackage("org.pkg1");
    InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("org.pkg1");
    pkg.getDialectRuntimeRegistry().setDialectData("java", new JavaDialectRuntimeData());
    pkg.addRule(rule);
    buildContext.setRule(rule);
    return buildContext;
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) BuildContext(org.drools.core.reteoo.builder.BuildContext) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) JavaDialectRuntimeData(org.drools.core.rule.JavaDialectRuntimeData) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 42 with RuleBaseConfiguration

use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.

the class KieBaseBuilder method createKieBaseFromModel.

public static InternalKnowledgeBase createKieBaseFromModel(Collection<Model> models, KieBaseModel kieBaseModel) {
    RuleBaseConfiguration kieBaseConf = new RuleBaseConfiguration();
    kieBaseConf.setEventProcessingMode(kieBaseModel.getEventProcessingMode());
    kieBaseConf.setSessionPoolSize(kieBaseModel.getSessionsPool().getSize());
    KiePackagesBuilder builder = new KiePackagesBuilder(kieBaseConf);
    models.stream().filter(m -> isPackageInKieBase(kieBaseModel, m.getPackageName())).forEach(builder::addModel);
    return new KieBaseBuilder(kieBaseModel, kieBaseConf).createKieBase(builder.build());
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) KieBaseOption(org.kie.api.conf.KieBaseOption) CanonicalKiePackages(org.drools.modelcompiler.CanonicalKiePackages) KieBaseConfiguration(org.kie.api.KieBaseConfiguration) Collection(java.util.Collection) KieBuilderImpl.isPackageInKieBase(org.drools.compiler.kie.builder.impl.KieBuilderImpl.isPackageInKieBase) KieBaseModel(org.kie.api.builder.model.KieBaseModel) KnowledgeBaseFactory(org.drools.kiesession.rulebase.KnowledgeBaseFactory) KiePackagesBuilder(org.drools.modelcompiler.KiePackagesBuilder) RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) KieServices(org.kie.api.KieServices) Collections(java.util.Collections) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Model(org.drools.model.Model) KiePackagesBuilder(org.drools.modelcompiler.KiePackagesBuilder)

Example 43 with RuleBaseConfiguration

use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.

the class PMMLMiningModelEvaluator method getPMMLRuntime.

/**
 * Retrieve the <code>PMMLRuntime</code> to be used for the given <b>segment</b>
 * It creates new <code>InternalKnowledgeBase</code>s and store them in a <code>Map</code>,
 * to reuse them.
 * @param kModulePackageName
 * @param knowledgeBase
 * @param containerModelName
 * @return
 */
PMMLRuntime getPMMLRuntime(final String kModulePackageName, final KieBase knowledgeBase, final String containerModelName) {
    final String key = containerModelName + "_" + kModulePackageName;
    InternalKnowledgeBase kieBase = MAPPED_KIEBASES.computeIfAbsent(key, s -> {
        final KiePackage kiePackage = knowledgeBase.getKiePackage(kModulePackageName);
        final List<KiePackage> packages = kiePackage != null ? Collections.singletonList(knowledgeBase.getKiePackage(kModulePackageName)) : Collections.emptyList();
        RuleBaseConfiguration conf = new RuleBaseConfiguration();
        conf.setClassLoader(((RuleBase) knowledgeBase).getRootClassLoader());
        InternalKnowledgeBase toReturn = KnowledgeBaseFactory.newKnowledgeBase(kModulePackageName, conf);
        toReturn.addPackages(packages);
        return toReturn;
    });
    KieRuntimeFactory kieRuntimeFactory = KieRuntimeFactory.of(kieBase);
    return kieRuntimeFactory.get(PMMLRuntime.class);
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) KieRuntimeFactory(org.kie.api.runtime.KieRuntimeFactory) KiePackage(org.kie.api.definition.KiePackage) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase)

Aggregations

RuleBaseConfiguration (org.drools.core.RuleBaseConfiguration)43 Test (org.junit.Test)19 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)11 BuildContext (org.drools.core.reteoo.builder.BuildContext)10 ArrayList (java.util.ArrayList)8 Properties (java.util.Properties)8 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)8 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)8 BetaNodeFieldConstraint (org.drools.core.spi.BetaNodeFieldConstraint)8 KieSession (org.kie.api.runtime.KieSession)8 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)6 BetaMemory (org.drools.core.reteoo.BetaMemory)6 TupleIndexHashTable (org.drools.core.util.index.TupleIndexHashTable)6 TupleList (org.drools.core.util.index.TupleList)6 List (java.util.List)5 BetaConstraints (org.drools.core.common.BetaConstraints)5 InternalFactHandle (org.drools.core.common.InternalFactHandle)5 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)5 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)5 SingleBetaConstraints (org.drools.core.common.SingleBetaConstraints)4