Skip to content

Commit

Permalink
Added support for guarded evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Jun 4, 2019
1 parent 293eec2 commit f12a882
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ public class EvaluationExample extends Example {
)
private boolean filterOutput = false;

@Parameter (
names = {"--safe"},
description = "Guard against ill-fated derived field and function evaluations",
hidden = true
)
private boolean safe = false;

@Parameter (
names = "--optimize",
description = "Optimize PMML class model",
Expand Down Expand Up @@ -289,11 +296,17 @@ public void execute() throws Exception {
System.out.println("\t" + "Other objects: " + numberFormat.format(objectCount - pmmlObjectCount));
}

EvaluatorBuilder evaluatorBuilder = new ModelEvaluatorBuilder(pmml, this.modelName)
ModelEvaluatorBuilder evaluatorBuilder = new ModelEvaluatorBuilder(pmml, this.modelName)
.setModelEvaluatorFactory((ModelEvaluatorFactory)newInstance(this.modelEvaluatorFactoryClazz))
.setValueFactoryFactory((ValueFactoryFactory)newInstance(this.valueFactoryFactoryClazz))
.setOutputFilter(this.filterOutput ? OutputFilters.KEEP_FINAL_RESULTS : OutputFilters.KEEP_ALL);

if(this.safe){
evaluatorBuilder = evaluatorBuilder
.setDerivedFieldGuard(new FieldNameSet(8))
.setFunctionGuard(new FunctionNameStack(4));
}

Evaluator evaluator = evaluatorBuilder.build();

// Perform self-testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public EvaluatorBuilder getEvaluatorBuilder() throws Exception {
VisitorBattery visitorBattery = new DefaultVisitorBattery();
visitorBattery.applyTo(pmml);

EvaluatorBuilder evaluatorBuilder = new ModelEvaluatorBuilder(pmml);
EvaluatorBuilder evaluatorBuilder = new ModelEvaluatorBuilder(pmml)
.setDerivedFieldGuard(new FieldNameSet(8))
.setFunctionGuard(new FunctionNameStack(4));

return evaluatorBuilder;
}
Expand Down

0 comments on commit f12a882

Please sign in to comment.