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