Search in sources :

Example 1 with RuleUnitRegistry

use of org.drools.core.ruleunit.RuleUnitRegistry in project drools by kiegroup.

the class KnowledgePackageImpl method setTypeResolver.

public void setTypeResolver(TypeResolver typeResolver) {
    this.typeResolver = typeResolver;
    this.ruleUnitRegistry = new RuleUnitRegistry(typeResolver);
}
Also used : RuleUnitRegistry(org.drools.core.ruleunit.RuleUnitRegistry)

Example 2 with RuleUnitRegistry

use of org.drools.core.ruleunit.RuleUnitRegistry in project drools by kiegroup.

the class SegmentExecution method applySegmentModel.

public void applySegmentModel(PMMLRequestData requestData, DataSource<PMMLRequestData> data, DataSource<PMML4Result> results, DataSource<SegmentExecution> segmentExecutions, KnowledgeHelper helper) throws IllegalStateException {
    if (ruleUnitClassName == null || ruleUnitClassName.trim().isEmpty()) {
        throw new IllegalStateException("Unable to apply segment model: No rule unit class name is available");
    }
    Class<? extends RuleUnit> ruleUnitClass = null;
    RuleUnitRegistry rur = ((KnowledgeBaseImpl) helper.getKieRuntime().getKieBase()).getRuleUnitRegistry();
    RuleUnit ruOld = ((WrappedStatefulKnowledgeSessionForRHS) helper.getKieRuntime()).getRuleUnitExecutor().getCurrentRuleUnit();
    RuleUnitDescr rud = rur.getNamedRuleUnit(ruleUnitClassName).orElse(null);
    if (rud != null) {
        ruleUnitClass = rud.getRuleUnitClass();
    } else {
        throw new IllegalStateException("Unable to apply segment model: Unable to find rule unit");
    }
// if (ruleUnitClass != null) {
// helper.run(ruleUnitClass);
// PMML4Result result = new PMML4Result(this);
// FactHandle requestFH = data.insert(this.requestData);
// FactHandle resultsFH = results.insert(result);
// 
// helper.run(ruleUnitClass);
// RuleUnit ruNew = ((WrappedStatefulKnowledgeSessionForRHS)helper.getKieRuntime()).getRuleUnitExecutor().getCurrentRuleUnit();
// System.out.println("** Result **");
// System.out.println(result);
// 
// // Update the state and let the Mining session know
// this.state = SegmentExecutionState.EXECUTING;
// FactHandle handle = ((InternalDataSource)segmentExecutions).getFactHandleForObject(this);
// segmentExecutions.update(handle, this);
// 
// helper.run(ruleUnitClass);
// System.out.println("Sub-Model Results");
// results.forEach(r -> {System.out.println(r);});
// }
}
Also used : RuleUnitRegistry(org.drools.core.ruleunit.RuleUnitRegistry) RuleUnitDescr(org.drools.core.ruleunit.RuleUnitDescr) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) RuleUnit(org.kie.api.runtime.rule.RuleUnit)

Example 3 with RuleUnitRegistry

use of org.drools.core.ruleunit.RuleUnitRegistry in project drools by kiegroup.

the class DroolsAbstractPMMLTest method getStartingRuleUnit.

protected Class<? extends RuleUnit> getStartingRuleUnit(String startingRule, InternalKnowledgeBase ikb, List<String> possiblePackages) {
    RuleUnitRegistry unitRegistry = ikb.getRuleUnitRegistry();
    Map<String, InternalKnowledgePackage> pkgs = ikb.getPackagesMap();
    RuleImpl ruleImpl = null;
    for (String pkgName : possiblePackages) {
        if (pkgs.containsKey(pkgName)) {
            InternalKnowledgePackage pkg = pkgs.get(pkgName);
            ruleImpl = pkg.getRule(startingRule);
            if (ruleImpl != null) {
                RuleUnitDescr descr = unitRegistry.getRuleUnitFor(ruleImpl).orElse(null);
                if (descr != null) {
                    return descr.getRuleUnitClass();
                }
            }
        }
    }
    return null;
}
Also used : RuleUnitRegistry(org.drools.core.ruleunit.RuleUnitRegistry) RuleUnitDescr(org.drools.core.ruleunit.RuleUnitDescr) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 4 with RuleUnitRegistry

use of org.drools.core.ruleunit.RuleUnitRegistry in project drools by kiegroup.

the class PMMLExecutor method startingRuleUnit.

protected Class<? extends RuleUnit> startingRuleUnit(String startingRule, String modelId, String... knownPackageNames) {
    List<String> possiblePackages = calculatePossiblePackageNames(modelId, knownPackageNames);
    InternalKnowledgeBase internalKnowledgeBase = (InternalKnowledgeBase) kieBase;
    RuleUnitRegistry unitRegistry = internalKnowledgeBase.getRuleUnitRegistry();
    Map<String, InternalKnowledgePackage> pkgs = internalKnowledgeBase.getPackagesMap();
    RuleImpl ruleImpl = null;
    for (String pkgName : possiblePackages) {
        if (pkgs.containsKey(pkgName)) {
            InternalKnowledgePackage pkg = pkgs.get(pkgName);
            ruleImpl = pkg.getRule(startingRule);
            if (ruleImpl != null) {
                RuleUnitDescr descr = unitRegistry.getRuleUnitFor(ruleImpl).orElse(null);
                if (descr != null) {
                    return descr.getRuleUnitClass();
                }
            }
        }
    }
    return null;
}
Also used : RuleUnitRegistry(org.drools.core.ruleunit.RuleUnitRegistry) RuleUnitDescr(org.drools.core.ruleunit.RuleUnitDescr) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Aggregations

RuleUnitRegistry (org.drools.core.ruleunit.RuleUnitRegistry)4 RuleUnitDescr (org.drools.core.ruleunit.RuleUnitDescr)3 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)2 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)2 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)1 RuleUnit (org.kie.api.runtime.rule.RuleUnit)1