Search in sources :

Example 6 with TemplateRegistry

use of org.mvel2.templates.TemplateRegistry in project drools by kiegroup.

the class PMML4Helper method applyTemplate.

public void applyTemplate(String templateName, Object context, TemplateRegistry registry, Map vars, StringBuilder builder) {
    CompiledTemplate template = registry.getNamedTemplate(templateName);
    String result = (String) TemplateRuntime.execute(template, context, vars, registry);
    builder.append(result);
}
Also used : CompiledTemplate(org.mvel2.templates.CompiledTemplate)

Example 7 with TemplateRegistry

use of org.mvel2.templates.TemplateRegistry in project drools by kiegroup.

the class AbstractModel method getMappedOutputPojo.

public Map.Entry<String, String> getMappedOutputPojo() {
    Map<String, String> result = new HashMap<>();
    if (!templateRegistry.contains(getOutputPojoTemplateName())) {
        this.addOutputTemplateToRegistry(templateRegistry);
    }
    List<PMMLOutputField> dataFields = this.getOutputFields();
    Map<String, Object> vars = new HashMap<>();
    String className = this.getOutputPojoClassName();
    vars.put("pmmlPackageName", PMML_JAVA_PACKAGE_NAME);
    vars.put("className", className);
    vars.put("imports", new ArrayList<>());
    vars.put("dataFields", dataFields);
    vars.put("modelName", this.getModelId());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        TemplateRuntime.execute(templateRegistry.getNamedTemplate(this.getOutputPojoTemplateName()), null, new MapVariableResolverFactory(vars), baos);
    } catch (TemplateError te) {
        return null;
    } catch (TemplateRuntimeError tre) {
        // need to figure out logging here
        return null;
    }
    result.put(className, new String(baos.toByteArray()));
    return result.entrySet().iterator().next();
}
Also used : TemplateRuntimeError(org.mvel2.templates.TemplateRuntimeError) HashMap(java.util.HashMap) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TemplateError(org.mvel2.templates.TemplateError)

Example 8 with TemplateRegistry

use of org.mvel2.templates.TemplateRegistry in project drools by kiegroup.

the class Miningmodel method addMiningTemplateToRegistry.

@Override
protected void addMiningTemplateToRegistry(TemplateRegistry registry) {
    InputStream inputStream = Scorecard.class.getResourceAsStream(MINING_POJO_TEMPLATE);
    if (inputStream != null) {
        CompiledTemplate ct = TemplateCompiler.compileTemplate(inputStream);
        registry.addNamedTemplate(getMiningPojoTemplateName(), ct);
    }
}
Also used : InputStream(java.io.InputStream) CompiledTemplate(org.mvel2.templates.CompiledTemplate)

Example 9 with TemplateRegistry

use of org.mvel2.templates.TemplateRegistry in project drools by kiegroup.

the class Regression method addMiningTemplateToRegistry.

@Override
protected void addMiningTemplateToRegistry(TemplateRegistry registry) {
    InputStream inputStream = Scorecard.class.getResourceAsStream(MINING_POJO_TEMPLATE);
    if (inputStream != null) {
        CompiledTemplate ct = TemplateCompiler.compileTemplate(inputStream);
        registry.addNamedTemplate(getMiningPojoTemplateName(), ct);
    }
}
Also used : InputStream(java.io.InputStream) CompiledTemplate(org.mvel2.templates.CompiledTemplate)

Example 10 with TemplateRegistry

use of org.mvel2.templates.TemplateRegistry in project drools by kiegroup.

the class ScorecardModel method addMiningTemplateToRegistry.

@Override
protected void addMiningTemplateToRegistry(TemplateRegistry registry) {
    InputStream inputStream = Scorecard.class.getResourceAsStream(SCORECARD_MINING_POJO_TEMPLATE);
    if (inputStream != null) {
        CompiledTemplate ct = TemplateCompiler.compileTemplate(inputStream);
        registry.addNamedTemplate(getMiningPojoTemplateName(), ct);
    }
}
Also used : InputStream(java.io.InputStream) CompiledTemplate(org.mvel2.templates.CompiledTemplate)

Aggregations

MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)8 CompiledTemplate (org.mvel2.templates.CompiledTemplate)8 SimpleTemplateRegistry (org.mvel2.templates.SimpleTemplateRegistry)7 TemplateRegistry (org.mvel2.templates.TemplateRegistry)7 HashMap (java.util.HashMap)6 InputStream (java.io.InputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)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 PatternExtractor (org.drools.core.spi.PatternExtractor)3 Test (org.junit.Test)3 TemplateRuntimeError (org.mvel2.templates.TemplateRuntimeError)3 Cheese (org.drools.compiler.Cheese)2 Person (org.drools.compiler.Person)2 TemplateError (org.mvel2.templates.TemplateError)2 Node (org.mvel2.templates.res.Node)2 PMMLRequestData (org.kie.api.pmml.PMMLRequestData)1