use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLDiscretizeBinFactory method getDiscretizeBinVariableDeclaration.
static BlockStmt getDiscretizeBinVariableDeclaration(final String variableName, final DiscretizeBin discretizeBin) {
final MethodDeclaration methodDeclaration = DISCRETIZE_BIN_TEMPLATE.getMethodsByName(GETKIEPMMLDISCRETIZE_BIN).get(0).clone();
final BlockStmt discretizeBinBody = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(discretizeBinBody, DISCRETIZE_BIN).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, DISCRETIZE_BIN, discretizeBinBody)));
variableDeclarator.setName(variableName);
final BlockStmt toReturn = new BlockStmt();
String nestedVariableName = String.format("%s_Interval", variableName);
BlockStmt toAdd = getIntervalVariableDeclaration(nestedVariableName, discretizeBin.getInterval());
toAdd.getStatements().forEach(toReturn::addStatement);
final ObjectCreationExpr objectCreationExpr = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, DISCRETIZE_BIN, discretizeBinBody))).asObjectCreationExpr();
final Expression nameExpr = new StringLiteralExpr(variableName);
final Expression binValueExpr = getExpressionForObject(discretizeBin.getBinValue());
final NameExpr intervalExpr = new NameExpr(nestedVariableName);
objectCreationExpr.getArguments().set(0, nameExpr);
objectCreationExpr.getArguments().set(2, binValueExpr);
objectCreationExpr.getArguments().set(3, intervalExpr);
discretizeBinBody.getStatements().forEach(toReturn::addStatement);
return toReturn;
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLNormContinuousFactory method getNormContinuousVariableDeclaration.
static BlockStmt getNormContinuousVariableDeclaration(final String variableName, final NormContinuous normContinuous) {
final MethodDeclaration methodDeclaration = NORMCONTINUOUS_TEMPLATE.getMethodsByName(GETKIEPMMLNORMCONTINUOUS).get(0).clone();
final BlockStmt toReturn = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(toReturn, NORM_CONTINUOUS).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, NORM_CONTINUOUS, toReturn)));
variableDeclarator.setName(variableName);
final ObjectCreationExpr objectCreationExpr = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, NORM_CONTINUOUS, toReturn))).asObjectCreationExpr();
final StringLiteralExpr nameExpr = new StringLiteralExpr(normContinuous.getField().getValue());
final OUTLIER_TREATMENT_METHOD outlierTreatmentMethod = OUTLIER_TREATMENT_METHOD.byName(normContinuous.getOutliers().value());
final NameExpr outlierTreatmentMethodExpr = new NameExpr(OUTLIER_TREATMENT_METHOD.class.getName() + "." + outlierTreatmentMethod.name());
NodeList<Expression> arguments = new NodeList<>();
int counter = 0;
for (LinearNorm linearNorm : normContinuous.getLinearNorms()) {
arguments.add(getNewKiePMMLLinearNormExpression(linearNorm, "LinearNorm-" + counter));
}
final Expression mapMissingToExpr = getExpressionForObject(normContinuous.getMapMissingTo());
objectCreationExpr.getArguments().set(0, nameExpr);
objectCreationExpr.getArguments().get(2).asMethodCallExpr().setArguments(arguments);
objectCreationExpr.getArguments().set(3, outlierTreatmentMethodExpr);
objectCreationExpr.getArguments().set(4, mapMissingToExpr);
return toReturn;
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLNormContinuousFactory method getNewKiePMMLLinearNormExpression.
static Expression getNewKiePMMLLinearNormExpression(LinearNorm linearNorm, String name) {
ObjectCreationExpr toReturn = new ObjectCreationExpr();
toReturn.setType(KiePMMLLinearNorm.class);
NodeList<Expression> arguments = new NodeList<>();
arguments.add(new StringLiteralExpr(name));
arguments.add(new MethodCallExpr(new NameExpr("Collections"), "emptyList"));
arguments.add(getExpressionForObject(linearNorm.getOrig()));
arguments.add(getExpressionForObject(linearNorm.getNorm()));
toReturn.setArguments(arguments);
return toReturn;
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLTargetValueFactory method getKiePMMLTargetValueVariableInitializer.
static MethodCallExpr getKiePMMLTargetValueVariableInitializer(final TargetValue targetValueField) {
final MethodDeclaration methodDeclaration = TARGETVALUE_TEMPLATE.getMethodsByName(GETKIEPMMLTARGETVALUE).get(0).clone();
final BlockStmt targetValueBody = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(targetValueBody, TARGETVALUE).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, TARGETVALUE, targetValueBody)));
variableDeclarator.setName(targetValueField.getName());
final ObjectCreationExpr targetValueFieldInstance = TargetValueFactory.getTargetValueVariableInitializer(targetValueField);
final MethodCallExpr toReturn = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, TARGETVALUE, targetValueBody))).asMethodCallExpr();
final MethodCallExpr builder = getChainedMethodCallExprFrom("builder", toReturn);
final StringLiteralExpr nameExpr = new StringLiteralExpr(targetValueField.getName());
builder.setArgument(0, nameExpr);
builder.setArgument(2, targetValueFieldInstance);
return toReturn;
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLModelFactoryUtils method populateGetCreatedOutputFieldsMethod.
/**
* Populate the <code>getCreatedKiePMMLMiningFields</code> method
* @param modelTemplate
* @param outputFields
*/
public static void populateGetCreatedOutputFieldsMethod(final ClassOrInterfaceDeclaration modelTemplate, final List<OutputField> outputFields) {
final MethodDeclaration methodDeclaration = modelTemplate.getMethodsByName(GET_CREATED_OUTPUTFIELDS).get(0);
final List<ObjectCreationExpr> outputFieldsObjectCreations = getOutputFieldsObjectCreations(outputFields);
populateListInListGetter(outputFieldsObjectCreations, methodDeclaration, TO_RETURN);
}
Aggregations