Search in sources :

Example 1 with TargetValue

use of org.kie.pmml.api.models.TargetValue in project drools by kiegroup.

the class KiePMMLTargetInstanceFactory method getKiePMMLTarget.

public static KiePMMLTarget getKiePMMLTarget(final Target target) {
    final List<TargetValue> targetValues = target.hasTargetValues() ? target.getTargetValues().stream().map(KiePMMLTargetInstanceFactory::getKieTargetValue).collect(Collectors.toList()) : Collections.emptyList();
    final OP_TYPE opType = target.getOpType() != null ? OP_TYPE.byName(target.getOpType().value()) : null;
    final String field = target.getField() != null ? target.getField().getValue() : null;
    final CAST_INTEGER castInteger = target.getCastInteger() != null ? CAST_INTEGER.byName(target.getCastInteger().value()) : null;
    TargetField targetField = new TargetField(targetValues, opType, field, castInteger, target.getMin(), target.getMax(), target.getRescaleConstant(), target.getRescaleFactor());
    final KiePMMLTarget.Builder builder = KiePMMLTarget.builder(targetField.getName(), Collections.emptyList(), targetField);
    return builder.build();
}
Also used : TargetValue(org.kie.pmml.api.models.TargetValue) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) CAST_INTEGER(org.kie.pmml.api.enums.CAST_INTEGER) TargetField(org.kie.pmml.api.models.TargetField) KiePMMLTarget(org.kie.pmml.commons.model.KiePMMLTarget)

Example 2 with TargetValue

use of org.kie.pmml.api.models.TargetValue in project drools by kiegroup.

the class KiePMMLModelFactoryUtilsTest method commonVerifyKiePMMLTargetFieldsMethodCallExpr.

private void commonVerifyKiePMMLTargetFieldsMethodCallExpr(MethodCallExpr retrieved, TargetField kieTargetField) throws IOException {
    String text = getFileContent(TEST_15_SOURCE);
    List<TargetValue> kieTargetValues = kieTargetField.getTargetValues();
    String opType = OP_TYPE.class.getCanonicalName() + "." + kieTargetField.getOpType().toString();
    String castInteger = CAST_INTEGER.class.getCanonicalName() + "." + kieTargetField.getCastInteger().toString();
    Expression expected = JavaParserUtils.parseExpression(String.format(text, kieTargetField.getName(), kieTargetValues.get(0).getValue(), kieTargetValues.get(0).getDisplayValue(), kieTargetValues.get(0).getPriorProbability(), kieTargetValues.get(0).getDefaultValue(), kieTargetValues.get(1).getValue(), kieTargetValues.get(1).getDisplayValue(), kieTargetValues.get(1).getPriorProbability(), kieTargetValues.get(1).getDefaultValue(), kieTargetValues.get(2).getValue(), kieTargetValues.get(2).getDisplayValue(), kieTargetValues.get(2).getPriorProbability(), kieTargetValues.get(2).getDefaultValue(), opType, kieTargetField.getField(), castInteger, kieTargetField.getMin(), kieTargetField.getMax(), kieTargetField.getRescaleConstant(), kieTargetField.getRescaleFactor()));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
    List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLTarget.class, KiePMMLTargetValue.class, TargetField.class, TargetValue.class);
    commonValidateCompilationWithImports(retrieved, imports);
}
Also used : KiePMMLTargetValue(org.kie.pmml.commons.model.KiePMMLTargetValue) TargetValue(org.kie.pmml.api.models.TargetValue) Expression(com.github.javaparser.ast.expr.Expression) BeforeClass(org.junit.BeforeClass)

Example 3 with TargetValue

use of org.kie.pmml.api.models.TargetValue in project drools by kiegroup.

the class KiePMMLTargetValueFactoryTest method getKiePMMLTargetValueVariableInitializer.

@Test
public void getKiePMMLTargetValueVariableInitializer() throws IOException {
    TargetValue targetValue = convertToKieTargetValue(getRandomTargetValue());
    MethodCallExpr retrieved = KiePMMLTargetValueFactory.getKiePMMLTargetValueVariableInitializer(targetValue);
    String text = getFileContent(TEST_01_SOURCE);
    Expression expected = JavaParserUtils.parseExpression(String.format(text, targetValue.getName(), targetValue.getValue(), targetValue.getDisplayValue(), targetValue.getPriorProbability(), targetValue.getDefaultValue()));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
    List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLTargetValue.class, TargetValue.class);
    commonValidateCompilationWithImports(retrieved, imports);
}
Also used : KiePMMLTargetValue(org.kie.pmml.commons.model.KiePMMLTargetValue) ModelUtils.convertToKieTargetValue(org.kie.pmml.compiler.api.utils.ModelUtils.convertToKieTargetValue) PMMLModelTestUtils.getRandomTargetValue(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomTargetValue) TargetValue(org.kie.pmml.api.models.TargetValue) Expression(com.github.javaparser.ast.expr.Expression) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Test(org.junit.Test)

Example 4 with TargetValue

use of org.kie.pmml.api.models.TargetValue in project drools by kiegroup.

the class TargetValueFactoryTest method getTargetValueVariableInitializer.

@Test
public void getTargetValueVariableInitializer() throws IOException {
    TargetValue targetValue = convertToKieTargetValue(getRandomTargetValue());
    ObjectCreationExpr retrieved = TargetValueFactory.getTargetValueVariableInitializer(targetValue);
    String text = getFileContent(TEST_01_SOURCE);
    Expression expected = JavaParserUtils.parseExpression(String.format(text, targetValue.getValue(), targetValue.getDisplayValue(), targetValue.getPriorProbability(), targetValue.getDefaultValue()));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
    List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLTargetValue.class, TargetValue.class);
    commonValidateCompilationWithImports(retrieved, imports);
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) KiePMMLTargetValue(org.kie.pmml.commons.model.KiePMMLTargetValue) ModelUtils.convertToKieTargetValue(org.kie.pmml.compiler.api.utils.ModelUtils.convertToKieTargetValue) PMMLModelTestUtils.getRandomTargetValue(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomTargetValue) TargetValue(org.kie.pmml.api.models.TargetValue) Expression(com.github.javaparser.ast.expr.Expression) Test(org.junit.Test)

Example 5 with TargetValue

use of org.kie.pmml.api.models.TargetValue in project drools by kiegroup.

the class TargetFieldFactoryTest method getTargetFieldVariableInitializer.

@Test
public void getTargetFieldVariableInitializer() throws IOException {
    TargetField kieTargetField = ModelUtils.convertToKieTargetField(getRandomTarget());
    ObjectCreationExpr retrieved = TargetFieldFactory.getTargetFieldVariableInitializer(kieTargetField);
    String text = getFileContent(TEST_01_SOURCE);
    List<TargetValue> kieTargetValues = kieTargetField.getTargetValues();
    String opType = OP_TYPE.class.getCanonicalName() + "." + kieTargetField.getOpType().toString();
    String castInteger = CAST_INTEGER.class.getCanonicalName() + "." + kieTargetField.getCastInteger().toString();
    Expression expected = JavaParserUtils.parseExpression(String.format(text, kieTargetValues.get(0).getValue(), kieTargetValues.get(0).getDisplayValue(), kieTargetValues.get(0).getPriorProbability(), kieTargetValues.get(0).getDefaultValue(), kieTargetValues.get(1).getValue(), kieTargetValues.get(1).getDisplayValue(), kieTargetValues.get(1).getPriorProbability(), kieTargetValues.get(1).getDefaultValue(), kieTargetValues.get(2).getValue(), kieTargetValues.get(2).getDisplayValue(), kieTargetValues.get(2).getPriorProbability(), kieTargetValues.get(2).getDefaultValue(), opType, kieTargetField.getField(), castInteger, kieTargetField.getMin(), kieTargetField.getMax(), kieTargetField.getRescaleConstant(), kieTargetField.getRescaleFactor()));
    assertEquals(expected.toString(), retrieved.toString());
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
    List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLTarget.class, KiePMMLTargetValue.class, TargetField.class, TargetValue.class);
    commonValidateCompilationWithImports(retrieved, imports);
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) KiePMMLTargetValue(org.kie.pmml.commons.model.KiePMMLTargetValue) TargetValue(org.kie.pmml.api.models.TargetValue) Expression(com.github.javaparser.ast.expr.Expression) TargetField(org.kie.pmml.api.models.TargetField) Test(org.junit.Test)

Aggregations

TargetValue (org.kie.pmml.api.models.TargetValue)7 Expression (com.github.javaparser.ast.expr.Expression)6 KiePMMLTargetValue (org.kie.pmml.commons.model.KiePMMLTargetValue)5 Test (org.junit.Test)4 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)3 TargetField (org.kie.pmml.api.models.TargetField)3 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)2 CAST_INTEGER (org.kie.pmml.api.enums.CAST_INTEGER)2 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)2 PMMLModelTestUtils.getRandomTargetValue (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomTargetValue)2 ModelUtils.convertToKieTargetValue (org.kie.pmml.compiler.api.utils.ModelUtils.convertToKieTargetValue)2 NodeList (com.github.javaparser.ast.NodeList)1 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)1 NameExpr (com.github.javaparser.ast.expr.NameExpr)1 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 BeforeClass (org.junit.BeforeClass)1 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)1 KiePMMLTarget (org.kie.pmml.commons.model.KiePMMLTarget)1