use of com.github.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class KiePMMLRegressionTableFactory method getNumericPredictorExpression.
/**
* Create a <b>NumericPredictor</b> <code>CastExpr</code>
* @param numericPredictor
* @return
*/
static CastExpr getNumericPredictorExpression(final NumericPredictor numericPredictor) {
boolean withExponent = !Objects.equals(1, numericPredictor.getExponent());
final String lambdaExpressionMethodName = withExponent ? "evaluateNumericWithExponent" : "evaluateNumericWithoutExponent";
final String parameterName = "input";
final MethodCallExpr lambdaMethodCallExpr = new MethodCallExpr();
lambdaMethodCallExpr.setName(lambdaExpressionMethodName);
lambdaMethodCallExpr.setScope(new NameExpr(KiePMMLRegressionTable.class.getSimpleName()));
final NodeList<Expression> arguments = new NodeList<>();
arguments.add(0, new NameExpr(parameterName));
arguments.add(1, getExpressionForObject(numericPredictor.getCoefficient().doubleValue()));
if (withExponent) {
arguments.add(2, getExpressionForObject(numericPredictor.getExponent().doubleValue()));
}
lambdaMethodCallExpr.setArguments(arguments);
final ExpressionStmt lambdaExpressionStmt = new ExpressionStmt(lambdaMethodCallExpr);
final LambdaExpr lambdaExpr = new LambdaExpr();
final Parameter lambdaParameter = new Parameter(new UnknownType(), parameterName);
lambdaExpr.setParameters(NodeList.nodeList(lambdaParameter));
lambdaExpr.setBody(lambdaExpressionStmt);
final String doubleClassName = Double.class.getSimpleName();
final ClassOrInterfaceType serializableFunctionType = getTypedClassOrInterfaceTypeByTypeNames(SerializableFunction.class.getCanonicalName(), Arrays.asList(doubleClassName, doubleClassName));
final CastExpr toReturn = new CastExpr();
toReturn.setType(serializableFunctionType);
toReturn.setExpression(lambdaExpr);
return toReturn;
}
use of com.github.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class KiePMMLRegressionTableFactory method getPredictorTermFunction.
/**
* Get the <b>PredictorTerm</b> <code>VariableDeclarationExpr</code>
* @param predictorTerm
* @return
*/
static LambdaExpr getPredictorTermFunction(final PredictorTerm predictorTerm) {
try {
LambdaExpr toReturn = new LambdaExpr();
toReturn.setParameters(NodeList.nodeList(new Parameter(new UnknownType(), "resultMap")));
final BlockStmt body = getPredictorTermBody(predictorTerm);
toReturn.setBody(body);
return toReturn;
} catch (Exception e) {
throw new KiePMMLInternalException(String.format("Failed to get PredictorTermFunction for %s", predictorTerm), e);
}
}
use of com.github.javaparser.ast.expr.LambdaExpr in project drools by kiegroup.
the class KiePMMLRegressionTableFactoryTest method getPredictorTermFunction.
@Test
public void getPredictorTermFunction() throws IOException {
String predictorName = "predictorName";
double coefficient = 23.12;
String fieldRef = "fieldRef";
PredictorTerm predictorTerm = PMMLModelTestUtils.getPredictorTerm(predictorName, coefficient, Collections.singletonList(fieldRef));
LambdaExpr retrieved = KiePMMLRegressionTableFactory.getPredictorTermFunction(predictorTerm);
String text = getFileContent(TEST_07_SOURCE);
Expression expected = JavaParserUtils.parseExpression(String.format(text, fieldRef, coefficient));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
}
use of com.github.javaparser.ast.expr.LambdaExpr in project checker-framework by typetools.
the class JointJavacJavaParserVisitor method visitLambdaExpression.
@Override
public Void visitLambdaExpression(LambdaExpressionTree javacTree, Node javaParserNode) {
LambdaExpr node = castNode(LambdaExpr.class, javaParserNode, javacTree);
processLambdaExpression(javacTree, node);
visitLists(javacTree.getParameters(), node.getParameters());
switch(javacTree.getBodyKind()) {
case EXPRESSION:
assert node.getBody() instanceof ExpressionStmt;
ExpressionStmt body = (ExpressionStmt) node.getBody();
javacTree.getBody().accept(this, body.getExpression());
break;
case STATEMENT:
javacTree.getBody().accept(this, node.getBody());
break;
}
return null;
}
use of com.github.javaparser.ast.expr.LambdaExpr in project checker-framework by typetools.
the class DoubleJavaParserVisitor method visit.
@Override
public void visit(final LambdaExpr node1, final Node other) {
LambdaExpr node2 = (LambdaExpr) other;
defaultAction(node1, node2);
node1.getBody().accept(this, node2.getBody());
visitLists(node1.getParameters(), node2.getParameters());
}
Aggregations