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