use of org.mvel2.integration.impl.MapVariableResolverFactory in project drools by kiegroup.
the class MiningSegmentation method generateSegmentationRules.
public String generateSegmentationRules() {
StringBuilder builder = new StringBuilder();
loadTemplates(this.multipleModelMethod);
Map<String, Object> templateVars = new HashMap<>();
// "org.kie.pmml.pmml_4_2."+this.getSegmentationId();
String pkgName = this.getOwner().getModelPackageName();
CompiledTemplate ct = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
switch(this.multipleModelMethod) {
case AVERAGE:
break;
case MAJORITY_VOTE:
break;
case MAX:
break;
case MEDIAN:
break;
case MODEL_CHAIN:
List<MiningSegmentTransfer> segmentTransfers = new ArrayList<>();
MiningSegmentTransfer mst = new MiningSegmentTransfer(this.getSegmentationId(), "1", "2");
mst.addResultToRequestMapping("calculatedScore", "calculatedScore");
segmentTransfers.add(mst);
templateVars.put("segmentTransfers", segmentTransfers);
templateVars.put("miningModel", this.getOwner());
templateVars.put("childSegments", this.getMiningSegments());
templateVars.put("packageName", pkgName);
templateVars.put("resultMappings", segmentTransfers);
templateVars.put("ruleUnitClassName", this.getOwner().getRuleUnitClassName());
ct = templates.getNamedTemplate(this.multipleModelMethod.name());
TemplateRuntime.execute(ct, null, new MapVariableResolverFactory(templateVars), baos);
builder.append(new String(baos.toByteArray()));
break;
case SELECT_ALL:
templateVars.put("ruleUnitClassName", this.getOwner().getRuleUnitClassName());
templateVars.put("miningModel", this.getOwner());
templateVars.put("childSegments", this.getMiningSegments());
templateVars.put("packageName", pkgName);
ct = templates.getNamedTemplate(this.multipleModelMethod.name());
TemplateRuntime.execute(ct, null, new MapVariableResolverFactory(templateVars), baos);
builder.append(new String(baos.toByteArray()));
break;
case SELECT_FIRST:
templateVars.put("ruleUnitClassName", this.getOwner().getRuleUnitClassName());
templateVars.put("miningModel", this.getOwner());
templateVars.put("childSegments", this.getMiningSegments());
templateVars.put("packageName", pkgName);
ct = templates.getNamedTemplate(this.multipleModelMethod.name());
TemplateRuntime.execute(ct, null, new MapVariableResolverFactory(templateVars), baos);
builder.append(new String(baos.toByteArray()));
break;
case SUM:
break;
case WEIGHTED_AVERAGE:
break;
case WEIGHTED_MAJORITY_VOTE:
break;
}
return builder.toString();
}
use of org.mvel2.integration.impl.MapVariableResolverFactory in project drools by kiegroup.
the class MiningSegment method generateSegmentRules.
public String generateSegmentRules(String segmentationAgenda, int segmentIndex) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CompiledTemplate template = getLaunchTemplate();
if (template != null) {
Map<String, Object> vars = new HashMap<>();
vars.put("segmentId", getSegmentId());
vars.put("segmentationAgendaId", segmentationAgenda);
vars.put("segmentSalience", new Integer(1000 - segmentIndex));
if (predicateRuleProducer instanceof CompoundSegmentPredicate) {
CompoundSegmentPredicate predProd = (CompoundSegmentPredicate) predicateRuleProducer;
if (predProd.hasSurrogation()) {
vars.put("segmentPredicate", getSurrogationPredicateText(predProd, -1));
} else {
vars.put("segmentPredicate", predProd.getPredicateRule());
}
} else {
vars.put("segmentPredicate", predicateRuleProducer.getPredicateRule());
}
vars.put("miningPojoClass", getOwner().getOwner().getMiningPojoClassName());
TemplateRuntime.execute(template, null, new MapVariableResolverFactory(vars), baos);
}
PMML pmml = new PMML();
pmml.setDataDictionary(this.internalModel.getDataDictionary());
pmml.getAssociationModelsAndBaselineModelsAndClusteringModels().add(this.internalModel.getRawModel());
PMML4Compiler compiler = new PMML4Compiler();
String innerRules = compiler.generateTheory(pmml);
return (new String(baos.toByteArray())).concat(innerRules);
}
Aggregations