use of com.github.javaparser.ast.expr.VariableDeclarationExpr in project drools by kiegroup.
the class KiePMMLNodeFactoryTest method populateEvaluateNodeWithMissingValuePenalty.
@Test
public void populateEvaluateNodeWithMissingValuePenalty() {
final BlockStmt toPopulate = new BlockStmt();
final VariableDeclarator variableDeclarator = new VariableDeclarator();
variableDeclarator.setType("double");
variableDeclarator.setName(MISSING_VALUE_PENALTY);
toPopulate.addStatement(new VariableDeclarationExpr(variableDeclarator));
assertFalse(variableDeclarator.getInitializer().isPresent());
final double missingValuePenalty = new Random().nextDouble();
KiePMMLNodeFactory.populateEvaluateNodeWithMissingValuePenalty(toPopulate, missingValuePenalty);
assertTrue(variableDeclarator.getInitializer().isPresent());
Expression expression = variableDeclarator.getInitializer().get();
assertTrue(expression instanceof DoubleLiteralExpr);
DoubleLiteralExpr doubleLiteralExpr = (DoubleLiteralExpr) expression;
assertEquals(missingValuePenalty, doubleLiteralExpr.asDouble(), 0.0);
}
use of com.github.javaparser.ast.expr.VariableDeclarationExpr in project drools by kiegroup.
the class KiePMMLNodeFactoryTest method populateEvaluateNodeWithScore.
@Test
public void populateEvaluateNodeWithScore() {
final BlockStmt toPopulate = new BlockStmt();
final VariableDeclarator variableDeclarator = new VariableDeclarator();
variableDeclarator.setType("Object");
variableDeclarator.setName(SCORE);
toPopulate.addStatement(new VariableDeclarationExpr(variableDeclarator));
assertFalse(variableDeclarator.getInitializer().isPresent());
// null score
Object score = null;
KiePMMLNodeFactory.populateEvaluateNodeWithScore(toPopulate, score);
commonVerifyEvaluateNodeWithScore(variableDeclarator, score);
// string score
score = "scoreValue";
KiePMMLNodeFactory.populateEvaluateNodeWithScore(toPopulate, score);
commonVerifyEvaluateNodeWithScore(variableDeclarator, score);
// not-string score
score = 54345.34;
KiePMMLNodeFactory.populateEvaluateNodeWithScore(toPopulate, score);
commonVerifyEvaluateNodeWithScore(variableDeclarator, score);
}
use of com.github.javaparser.ast.expr.VariableDeclarationExpr in project drools by kiegroup.
the class KiePMMLRegressionTableFactory method populateWithGroupedCategoricalPredictorMap.
/**
* Populate the given <b>body</b> with the creation of a <code>Map</code> for the given <b>categoricalPredictors</b>
* @param categoricalPredictors
* @param toPopulate
* @param categoricalPredictorMapName
* @return
*/
static void populateWithGroupedCategoricalPredictorMap(final List<CategoricalPredictor> categoricalPredictors, final BlockStmt toPopulate, final String categoricalPredictorMapName) {
final VariableDeclarator categoricalMapDeclarator = new VariableDeclarator(getTypedClassOrInterfaceTypeByTypeNames(Map.class.getName(), Arrays.asList(String.class.getSimpleName(), Double.class.getSimpleName())), categoricalPredictorMapName);
final ObjectCreationExpr categoricalMapInitializer = new ObjectCreationExpr();
categoricalMapInitializer.setType(getTypedClassOrInterfaceTypeByTypeNames(HashMap.class.getName(), Arrays.asList(String.class.getSimpleName(), Double.class.getSimpleName())));
categoricalMapDeclarator.setInitializer(categoricalMapInitializer);
final VariableDeclarationExpr categoricalMapDeclarationExpr = new VariableDeclarationExpr(categoricalMapDeclarator);
toPopulate.addStatement(categoricalMapDeclarationExpr);
final Map<String, Expression> mapExpressions = new LinkedHashMap<>();
categoricalPredictors.forEach(categoricalPredictor -> mapExpressions.put(categoricalPredictor.getValue().toString(), getExpressionForObject(categoricalPredictor.getCoefficient().doubleValue())));
addMapPopulationExpressions(mapExpressions, toPopulate, categoricalPredictorMapName);
}
Aggregations