Search in sources :

Example 6 with TargetField

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

the class KiePMMLModelFactoryUtilsTest method setKiePMMLModelConstructor.

@Test
public void setKiePMMLModelConstructor() {
    String generatedClassName = "generatedClassName";
    String name = "newName";
    List<MiningField> miningFields = IntStream.range(0, 3).mapToObj(i -> ModelUtils.convertToKieMiningField(getRandomMiningField(), getRandomDataField())).collect(Collectors.toList());
    List<OutputField> outputFields = IntStream.range(0, 2).mapToObj(i -> ModelUtils.convertToKieOutputField(getRandomOutputField(), getRandomDataField())).collect(Collectors.toList());
    List<TargetField> targetFields = IntStream.range(0, 2).mapToObj(i -> ModelUtils.convertToKieTargetField(getRandomTarget())).collect(Collectors.toList());
    KiePMMLModelFactoryUtils.setKiePMMLModelConstructor(generatedClassName, constructorDeclaration, name, miningFields, outputFields, targetFields);
    commonVerifySuperInvocation(generatedClassName, name);
    List<MethodCallExpr> retrieved = getMethodCallExprList(constructorDeclaration.getBody(), miningFields.size(), "miningFields", "add");
    MethodCallExpr addMethodCall = retrieved.get(0);
    NodeList<Expression> arguments = addMethodCall.getArguments();
    commonVerifyMiningFieldsObjectCreation(arguments, miningFields);
    retrieved = getMethodCallExprList(constructorDeclaration.getBody(), outputFields.size(), "outputFields", "add");
    addMethodCall = retrieved.get(0);
    arguments = addMethodCall.getArguments();
    commonVerifyOutputFieldsObjectCreation(arguments, outputFields);
    retrieved = getMethodCallExprList(constructorDeclaration.getBody(), outputFields.size(), "kiePMMLTargets", "add");
    addMethodCall = retrieved.get(0);
    arguments = addMethodCall.getArguments();
    commonVerifyKiePMMLTargetFieldsMethodCallExpr(arguments, targetFields);
}
Also used : RESULT_FEATURE(org.kie.pmml.api.enums.RESULT_FEATURE) Arrays(java.util.Arrays) Spliterators(java.util.Spliterators) Random(java.util.Random) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) FIELD_USAGE_TYPE(org.kie.pmml.api.enums.FIELD_USAGE_TYPE) GET_CREATED_MININGFIELDS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_MININGFIELDS) KiePMMLUtil(org.kie.pmml.compiler.commons.utils.KiePMMLUtil) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) GET_CREATED_LOCAL_TRANSFORMATIONS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_LOCAL_TRANSFORMATIONS) GET_CREATED_TRANSFORMATION_DICTIONARY(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_TRANSFORMATION_DICTIONARY) ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) GET_CREATED_OUTPUTFIELDS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_OUTPUTFIELDS) GET_CREATED_KIEPMMLOUTPUTFIELDS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_KIEPMMLOUTPUTFIELDS) Expression(com.github.javaparser.ast.expr.Expression) Assert.fail(org.junit.Assert.fail) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Interval(org.kie.pmml.api.models.Interval) ModelUtils(org.kie.pmml.compiler.api.utils.ModelUtils) NodeList(com.github.javaparser.ast.NodeList) PMML(org.dmg.pmml.PMML) CommonCodegenUtils(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils) KiePMMLTargetValue(org.kie.pmml.commons.model.KiePMMLTargetValue) GET_CREATED_KIEPMMLTARGETS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_KIEPMMLTARGETS) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) TreeModel(org.dmg.pmml.tree.TreeModel) Collectors(java.util.stream.Collectors) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) FileUtils.getFileContent(org.kie.test.util.filesystem.FileUtils.getFileContent) List(java.util.List) Stream(java.util.stream.Stream) CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) Optional(java.util.Optional) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) Spliterator(java.util.Spliterator) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) IntStream(java.util.stream.IntStream) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) BeforeClass(org.junit.BeforeClass) OutputField(org.kie.pmml.api.models.OutputField) JavaParserUtils.getFromFileName(org.kie.pmml.compiler.commons.utils.JavaParserUtils.getFromFileName) TargetField(org.kie.pmml.api.models.TargetField) MiningField(org.kie.pmml.api.models.MiningField) CAST_INTEGER(org.kie.pmml.api.enums.CAST_INTEGER) StreamSupport(java.util.stream.StreamSupport) GET_CREATED_KIEPMMLMININGFIELDS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_KIEPMMLMININGFIELDS) MISSING_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD) Before(org.junit.Before) INVALID_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD) CompilationDTO(org.kie.pmml.compiler.api.dto.CompilationDTO) JavaParserUtils(org.kie.pmml.compiler.commons.utils.JavaParserUtils) PACKAGE_NAME(org.kie.pmml.commons.Constants.PACKAGE_NAME) CommonCodegenUtils.getChainedMethodCallExprFrom(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getChainedMethodCallExprFrom) Assert.assertNotNull(org.junit.Assert.assertNotNull) PMMLModelTestUtils.getRandomOpType(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomOpType) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) NameExpr(com.github.javaparser.ast.expr.NameExpr) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) Statement(com.github.javaparser.ast.stmt.Statement) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) PMMLModelTestUtils.getRandomOutputField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomOutputField) PMMLModelTestUtils.getRandomTarget(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomTarget) KiePMMLTarget(org.kie.pmml.commons.model.KiePMMLTarget) FileUtils.getFileInputStream(org.kie.test.util.filesystem.FileUtils.getFileInputStream) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) CodegenTestUtils.commonValidateCompilationWithImports(org.kie.pmml.compiler.commons.testutils.CodegenTestUtils.commonValidateCompilationWithImports) PMMLModelTestUtils.getRandomCastInteger(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomCastInteger) PMMLModelTestUtils.getRandomMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) GET_MODEL(org.kie.pmml.commons.Constants.GET_MODEL) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TargetValue(org.kie.pmml.api.models.TargetValue) MiningField(org.kie.pmml.api.models.MiningField) PMMLModelTestUtils.getRandomMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField) Expression(com.github.javaparser.ast.expr.Expression) OutputField(org.kie.pmml.api.models.OutputField) PMMLModelTestUtils.getRandomOutputField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomOutputField) TargetField(org.kie.pmml.api.models.TargetField) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Test(org.junit.Test)

Example 7 with TargetField

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

the class KiePMMLModelFactoryUtilsTest method populateGetCreatedKiePMMLTargetsMethod.

@Test
public void populateGetCreatedKiePMMLTargetsMethod() throws IOException {
    Random random = new Random();
    List<TargetField> kiePMMLTargets = IntStream.range(0, 3).mapToObj(i -> new TargetField(Collections.emptyList(), OP_TYPE.byName(getRandomOpType().value()), "Target-" + i, CAST_INTEGER.byName(getRandomCastInteger().value()), (double) random.nextInt(20), (double) random.nextInt(60) + 20, (double) random.nextInt(100) / 100, (double) random.nextInt(100) / 100)).collect(Collectors.toList());
    String opType0 = OP_TYPE.class.getCanonicalName() + "." + kiePMMLTargets.get(0).getOpType().toString();
    String castInteger0 = CAST_INTEGER.class.getCanonicalName() + "." + kiePMMLTargets.get(0).getCastInteger().toString();
    String opType1 = OP_TYPE.class.getCanonicalName() + "." + kiePMMLTargets.get(1).getOpType().toString();
    String castInteger1 = CAST_INTEGER.class.getCanonicalName() + "." + kiePMMLTargets.get(1).getCastInteger().toString();
    String opType2 = OP_TYPE.class.getCanonicalName() + "." + kiePMMLTargets.get(2).getOpType().toString();
    String castInteger2 = CAST_INTEGER.class.getCanonicalName() + "." + kiePMMLTargets.get(2).getCastInteger().toString();
    KiePMMLModelFactoryUtils.populateGetCreatedKiePMMLTargetsMethod(classOrInterfaceDeclaration, kiePMMLTargets);
    final MethodDeclaration retrieved = classOrInterfaceDeclaration.getMethodsByName(GET_CREATED_KIEPMMLTARGETS).get(0);
    String text = getFileContent(TEST_10_SOURCE);
    MethodDeclaration expected = JavaParserUtils.parseMethod(String.format(text, kiePMMLTargets.get(0).getName(), opType0, castInteger0, kiePMMLTargets.get(0).getMin(), kiePMMLTargets.get(0).getMax(), kiePMMLTargets.get(0).getRescaleConstant(), kiePMMLTargets.get(0).getRescaleFactor(), kiePMMLTargets.get(1).getName(), opType1, castInteger1, kiePMMLTargets.get(1).getMin(), kiePMMLTargets.get(1).getMax(), kiePMMLTargets.get(1).getRescaleConstant(), kiePMMLTargets.get(1).getRescaleFactor(), kiePMMLTargets.get(2).getName(), opType2, castInteger2, kiePMMLTargets.get(2).getMin(), kiePMMLTargets.get(2).getMax(), kiePMMLTargets.get(2).getRescaleConstant(), kiePMMLTargets.get(2).getRescaleFactor()));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
}
Also used : RESULT_FEATURE(org.kie.pmml.api.enums.RESULT_FEATURE) Arrays(java.util.Arrays) Spliterators(java.util.Spliterators) Random(java.util.Random) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) FIELD_USAGE_TYPE(org.kie.pmml.api.enums.FIELD_USAGE_TYPE) GET_CREATED_MININGFIELDS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_MININGFIELDS) KiePMMLUtil(org.kie.pmml.compiler.commons.utils.KiePMMLUtil) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) GET_CREATED_LOCAL_TRANSFORMATIONS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_LOCAL_TRANSFORMATIONS) GET_CREATED_TRANSFORMATION_DICTIONARY(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_TRANSFORMATION_DICTIONARY) ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) GET_CREATED_OUTPUTFIELDS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_OUTPUTFIELDS) GET_CREATED_KIEPMMLOUTPUTFIELDS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_KIEPMMLOUTPUTFIELDS) Expression(com.github.javaparser.ast.expr.Expression) Assert.fail(org.junit.Assert.fail) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Interval(org.kie.pmml.api.models.Interval) ModelUtils(org.kie.pmml.compiler.api.utils.ModelUtils) NodeList(com.github.javaparser.ast.NodeList) PMML(org.dmg.pmml.PMML) CommonCodegenUtils(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils) KiePMMLTargetValue(org.kie.pmml.commons.model.KiePMMLTargetValue) GET_CREATED_KIEPMMLTARGETS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_KIEPMMLTARGETS) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) TreeModel(org.dmg.pmml.tree.TreeModel) Collectors(java.util.stream.Collectors) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) FileUtils.getFileContent(org.kie.test.util.filesystem.FileUtils.getFileContent) List(java.util.List) Stream(java.util.stream.Stream) CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) Optional(java.util.Optional) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) Spliterator(java.util.Spliterator) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) IntStream(java.util.stream.IntStream) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) BeforeClass(org.junit.BeforeClass) OutputField(org.kie.pmml.api.models.OutputField) JavaParserUtils.getFromFileName(org.kie.pmml.compiler.commons.utils.JavaParserUtils.getFromFileName) TargetField(org.kie.pmml.api.models.TargetField) MiningField(org.kie.pmml.api.models.MiningField) CAST_INTEGER(org.kie.pmml.api.enums.CAST_INTEGER) StreamSupport(java.util.stream.StreamSupport) GET_CREATED_KIEPMMLMININGFIELDS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_KIEPMMLMININGFIELDS) MISSING_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD) Before(org.junit.Before) INVALID_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD) CompilationDTO(org.kie.pmml.compiler.api.dto.CompilationDTO) JavaParserUtils(org.kie.pmml.compiler.commons.utils.JavaParserUtils) PACKAGE_NAME(org.kie.pmml.commons.Constants.PACKAGE_NAME) CommonCodegenUtils.getChainedMethodCallExprFrom(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getChainedMethodCallExprFrom) Assert.assertNotNull(org.junit.Assert.assertNotNull) PMMLModelTestUtils.getRandomOpType(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomOpType) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) NameExpr(com.github.javaparser.ast.expr.NameExpr) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) Statement(com.github.javaparser.ast.stmt.Statement) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) PMMLModelTestUtils.getRandomOutputField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomOutputField) PMMLModelTestUtils.getRandomTarget(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomTarget) KiePMMLTarget(org.kie.pmml.commons.model.KiePMMLTarget) FileUtils.getFileInputStream(org.kie.test.util.filesystem.FileUtils.getFileInputStream) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) CodegenTestUtils.commonValidateCompilationWithImports(org.kie.pmml.compiler.commons.testutils.CodegenTestUtils.commonValidateCompilationWithImports) PMMLModelTestUtils.getRandomCastInteger(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomCastInteger) PMMLModelTestUtils.getRandomMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) GET_MODEL(org.kie.pmml.commons.Constants.GET_MODEL) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TargetValue(org.kie.pmml.api.models.TargetValue) Random(java.util.Random) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) TargetField(org.kie.pmml.api.models.TargetField) Test(org.junit.Test)

Example 8 with TargetField

use of org.kie.pmml.api.models.TargetField 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)

Example 9 with TargetField

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

the class KiePMMLModelFactoryUtilsTest method commonVerifyKiePMMLTargetFieldsMethodCallExpr.

private void commonVerifyKiePMMLTargetFieldsMethodCallExpr(List<Expression> toVerify, List<TargetField> targetFields) {
    toVerify.forEach(argument -> {
        assertTrue(argument instanceof MethodCallExpr);
        MethodCallExpr mtdfClExpr = (MethodCallExpr) argument;
        assertEquals("build", mtdfClExpr.getName().asString());
        final MethodCallExpr builder = getChainedMethodCallExprFrom("builder", mtdfClExpr);
        Optional<TargetField> targetFieldOpt = targetFields.stream().filter(targetField -> targetField.getName().equals(builder.getArgument(0).asStringLiteralExpr().asString())).findFirst();
        assertTrue(targetFieldOpt.isPresent());
        TargetField targetField = targetFieldOpt.get();
        try {
            commonVerifyKiePMMLTargetFieldsMethodCallExpr(mtdfClExpr, targetField);
        } catch (IOException e) {
            fail(e.getMessage());
        }
    });
}
Also used : RESULT_FEATURE(org.kie.pmml.api.enums.RESULT_FEATURE) Arrays(java.util.Arrays) Spliterators(java.util.Spliterators) Random(java.util.Random) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) FIELD_USAGE_TYPE(org.kie.pmml.api.enums.FIELD_USAGE_TYPE) GET_CREATED_MININGFIELDS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_MININGFIELDS) KiePMMLUtil(org.kie.pmml.compiler.commons.utils.KiePMMLUtil) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) GET_CREATED_LOCAL_TRANSFORMATIONS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_LOCAL_TRANSFORMATIONS) GET_CREATED_TRANSFORMATION_DICTIONARY(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_TRANSFORMATION_DICTIONARY) ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) GET_CREATED_OUTPUTFIELDS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_OUTPUTFIELDS) GET_CREATED_KIEPMMLOUTPUTFIELDS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_KIEPMMLOUTPUTFIELDS) Expression(com.github.javaparser.ast.expr.Expression) Assert.fail(org.junit.Assert.fail) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Interval(org.kie.pmml.api.models.Interval) ModelUtils(org.kie.pmml.compiler.api.utils.ModelUtils) NodeList(com.github.javaparser.ast.NodeList) PMML(org.dmg.pmml.PMML) CommonCodegenUtils(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils) KiePMMLTargetValue(org.kie.pmml.commons.model.KiePMMLTargetValue) GET_CREATED_KIEPMMLTARGETS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_KIEPMMLTARGETS) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) TreeModel(org.dmg.pmml.tree.TreeModel) Collectors(java.util.stream.Collectors) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) FileUtils.getFileContent(org.kie.test.util.filesystem.FileUtils.getFileContent) List(java.util.List) Stream(java.util.stream.Stream) CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) Optional(java.util.Optional) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) Spliterator(java.util.Spliterator) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) IntStream(java.util.stream.IntStream) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) BeforeClass(org.junit.BeforeClass) OutputField(org.kie.pmml.api.models.OutputField) JavaParserUtils.getFromFileName(org.kie.pmml.compiler.commons.utils.JavaParserUtils.getFromFileName) TargetField(org.kie.pmml.api.models.TargetField) MiningField(org.kie.pmml.api.models.MiningField) CAST_INTEGER(org.kie.pmml.api.enums.CAST_INTEGER) StreamSupport(java.util.stream.StreamSupport) GET_CREATED_KIEPMMLMININGFIELDS(org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils.GET_CREATED_KIEPMMLMININGFIELDS) MISSING_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD) Before(org.junit.Before) INVALID_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD) CompilationDTO(org.kie.pmml.compiler.api.dto.CompilationDTO) JavaParserUtils(org.kie.pmml.compiler.commons.utils.JavaParserUtils) PACKAGE_NAME(org.kie.pmml.commons.Constants.PACKAGE_NAME) CommonCodegenUtils.getChainedMethodCallExprFrom(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getChainedMethodCallExprFrom) Assert.assertNotNull(org.junit.Assert.assertNotNull) PMMLModelTestUtils.getRandomOpType(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomOpType) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) NameExpr(com.github.javaparser.ast.expr.NameExpr) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) Statement(com.github.javaparser.ast.stmt.Statement) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) PMMLModelTestUtils.getRandomOutputField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomOutputField) PMMLModelTestUtils.getRandomTarget(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomTarget) KiePMMLTarget(org.kie.pmml.commons.model.KiePMMLTarget) FileUtils.getFileInputStream(org.kie.test.util.filesystem.FileUtils.getFileInputStream) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) CodegenTestUtils.commonValidateCompilationWithImports(org.kie.pmml.compiler.commons.testutils.CodegenTestUtils.commonValidateCompilationWithImports) PMMLModelTestUtils.getRandomCastInteger(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomCastInteger) PMMLModelTestUtils.getRandomMiningField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) GET_MODEL(org.kie.pmml.commons.Constants.GET_MODEL) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TargetValue(org.kie.pmml.api.models.TargetValue) IOException(java.io.IOException) TargetField(org.kie.pmml.api.models.TargetField) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 10 with TargetField

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

the class KiePMMLTargetFactoryTest method getKiePMMLTargetValueVariableInitializer.

@Test
public void getKiePMMLTargetValueVariableInitializer() throws IOException {
    TargetField kieTargetField = ModelUtils.convertToKieTargetField(getRandomTarget());
    MethodCallExpr retrieved = KiePMMLTargetFactory.getKiePMMLTargetVariableInitializer(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, 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) TargetField(org.kie.pmml.api.models.TargetField) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Test(org.junit.Test)

Aggregations

TargetField (org.kie.pmml.api.models.TargetField)15 Test (org.junit.Test)12 Expression (com.github.javaparser.ast.expr.Expression)6 TargetValue (org.kie.pmml.api.models.TargetValue)6 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)5 CAST_INTEGER (org.kie.pmml.api.enums.CAST_INTEGER)5 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)5 KiePMMLTarget (org.kie.pmml.commons.model.KiePMMLTarget)5 KiePMMLTargetValue (org.kie.pmml.commons.model.KiePMMLTargetValue)5 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)4 NameExpr (com.github.javaparser.ast.expr.NameExpr)4 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)4 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)4 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)4 CompilationUnit (com.github.javaparser.ast.CompilationUnit)3 NodeList (com.github.javaparser.ast.NodeList)3 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)3 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)3 ExplicitConstructorInvocationStmt (com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt)3 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)3