Search in sources :

Example 36 with MapVariableResolverFactory

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();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CompiledTemplate(org.mvel2.templates.CompiledTemplate)

Example 37 with MapVariableResolverFactory

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);
}
Also used : HashMap(java.util.HashMap) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) PMML(org.kie.dmg.pmml.pmml_4_2.descr.PMML) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PMML4Compiler(org.kie.pmml.pmml_4_2.PMML4Compiler) CompiledTemplate(org.mvel2.templates.CompiledTemplate)

Aggregations

MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)35 HashMap (java.util.HashMap)19 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)10 ParserContext (org.mvel2.ParserContext)8 CompiledExpression (org.mvel2.compiler.CompiledExpression)8 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)8 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Debugger (org.mvel2.debug.Debugger)6 Frame (org.mvel2.debug.Frame)6 SimpleTemplateRegistry (org.mvel2.templates.SimpleTemplateRegistry)6 HashSet (java.util.HashSet)5 CompiledTemplate (org.mvel2.templates.CompiledTemplate)5 TemplateRegistry (org.mvel2.templates.TemplateRegistry)5 TemplateRuntimeError (org.mvel2.templates.TemplateRuntimeError)5 Serializable (java.io.Serializable)3 List (java.util.List)3 Map (java.util.Map)3 ClassObjectType (org.drools.core.base.ClassObjectType)3 Declaration (org.drools.core.rule.Declaration)3