Search in sources :

Example 6 with HasClassLoaderMock

use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock in project drools by kiegroup.

the class KiePMMLRegressionTableFactoryTest method getRegressionTable.

@Test
public void getRegressionTable() {
    regressionTable = getRegressionTable(3.5, "professional");
    RegressionModel regressionModel = new RegressionModel();
    regressionModel.setNormalizationMethod(RegressionModel.NormalizationMethod.CAUCHIT);
    regressionModel.addRegressionTables(regressionTable);
    regressionModel.setModelName(getGeneratedClassName("RegressionModel"));
    String targetField = "targetField";
    DataField dataField = new DataField();
    dataField.setName(FieldName.create(targetField));
    dataField.setOpType(OpType.CATEGORICAL);
    DataDictionary dataDictionary = new DataDictionary();
    dataDictionary.addDataFields(dataField);
    MiningField miningField = new MiningField();
    miningField.setUsageType(MiningField.UsageType.TARGET);
    miningField.setName(dataField.getName());
    MiningSchema miningSchema = new MiningSchema();
    miningSchema.addMiningFields(miningField);
    regressionModel.setMiningSchema(miningSchema);
    PMML pmml = new PMML();
    pmml.setDataDictionary(dataDictionary);
    pmml.addModels(regressionModel);
    final CommonCompilationDTO<RegressionModel> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, regressionModel, new HasClassLoaderMock());
    final RegressionCompilationDTO compilationDTO = RegressionCompilationDTO.fromCompilationDTORegressionTablesAndNormalizationMethod(source, new ArrayList<>(), regressionModel.getNormalizationMethod());
    KiePMMLRegressionTable retrieved = KiePMMLRegressionTableFactory.getRegressionTable(regressionTable, compilationDTO);
    assertNotNull(retrieved);
    commonEvaluateRegressionTable(retrieved, regressionTable);
}
Also used : MiningField(org.dmg.pmml.MiningField) DataField(org.dmg.pmml.DataField) MiningSchema(org.dmg.pmml.MiningSchema) KiePMMLRegressionTable(org.kie.pmml.models.regression.model.KiePMMLRegressionTable) PMML(org.dmg.pmml.PMML) RegressionCompilationDTO(org.kie.pmml.models.regression.compiler.dto.RegressionCompilationDTO) DataDictionary(org.dmg.pmml.DataDictionary) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) RegressionModel(org.dmg.pmml.regression.RegressionModel) Test(org.junit.Test)

Example 7 with HasClassLoaderMock

use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock in project drools by kiegroup.

the class KiePMMLRegressionTableFactoryTest method getRegressionTableBuilder.

@Test
public void getRegressionTableBuilder() {
    regressionTable = getRegressionTable(3.5, "professional");
    RegressionModel regressionModel = new RegressionModel();
    regressionModel.setNormalizationMethod(RegressionModel.NormalizationMethod.CAUCHIT);
    regressionModel.addRegressionTables(regressionTable);
    regressionModel.setModelName(getGeneratedClassName("RegressionModel"));
    String targetField = "targetField";
    DataField dataField = new DataField();
    dataField.setName(FieldName.create(targetField));
    dataField.setOpType(OpType.CATEGORICAL);
    DataDictionary dataDictionary = new DataDictionary();
    dataDictionary.addDataFields(dataField);
    MiningField miningField = new MiningField();
    miningField.setUsageType(MiningField.UsageType.TARGET);
    miningField.setName(dataField.getName());
    MiningSchema miningSchema = new MiningSchema();
    miningSchema.addMiningFields(miningField);
    regressionModel.setMiningSchema(miningSchema);
    PMML pmml = new PMML();
    pmml.setDataDictionary(dataDictionary);
    pmml.addModels(regressionModel);
    final CommonCompilationDTO<RegressionModel> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, regressionModel, new HasClassLoaderMock());
    final RegressionCompilationDTO compilationDTO = RegressionCompilationDTO.fromCompilationDTORegressionTablesAndNormalizationMethod(source, new ArrayList<>(), regressionModel.getNormalizationMethod());
    Map.Entry<String, String> retrieved = KiePMMLRegressionTableFactory.getRegressionTableBuilder(regressionTable, compilationDTO);
    assertNotNull(retrieved);
    Map<String, String> sources = new HashMap<>();
    sources.put(retrieved.getKey(), retrieved.getValue());
    commonValidateCompilation(sources);
}
Also used : MiningField(org.dmg.pmml.MiningField) HashMap(java.util.HashMap) DataDictionary(org.dmg.pmml.DataDictionary) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) RegressionModel(org.dmg.pmml.regression.RegressionModel) DataField(org.dmg.pmml.DataField) MiningSchema(org.dmg.pmml.MiningSchema) PMML(org.dmg.pmml.PMML) RegressionCompilationDTO(org.kie.pmml.models.regression.compiler.dto.RegressionCompilationDTO) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with HasClassLoaderMock

use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock in project drools by kiegroup.

the class KiePMMLScorecardModelFactoryTest method getKiePMMLScorecardModel.

@Test
public void getKiePMMLScorecardModel() {
    final CommonCompilationDTO<Scorecard> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, basicComplexPartialScorePmml, basicComplexPartialScore, new HasClassLoaderMock());
    KiePMMLScorecardModel retrieved = KiePMMLScorecardModelFactory.getKiePMMLScorecardModel(ScorecardCompilationDTO.fromCompilationDTO(source));
    assertNotNull(retrieved);
}
Also used : KiePMMLScorecardModel(org.kie.pmml.models.scorecard.model.KiePMMLScorecardModel) Scorecard(org.dmg.pmml.scorecard.Scorecard) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 9 with HasClassLoaderMock

use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock in project drools by kiegroup.

the class KiePMMLScorecardModelFactoryTest method getKiePMMLScorecardModelSourcesMap.

@Test
public void getKiePMMLScorecardModelSourcesMap() {
    final CommonCompilationDTO<Scorecard> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, basicComplexPartialScorePmml, basicComplexPartialScore, new HasClassLoaderMock());
    ScorecardCompilationDTO compilationDTO = ScorecardCompilationDTO.fromCompilationDTO(source);
    final Map<String, String> retrieved = KiePMMLScorecardModelFactory.getKiePMMLScorecardModelSourcesMap(compilationDTO);
    assertNotNull(retrieved);
    assertEquals(2, retrieved.size());
    assertTrue(retrieved.containsKey(compilationDTO.getPackageCanonicalClassName()));
    assertTrue(retrieved.containsKey(compilationDTO.getPackageCanonicalCharacteristicsClassName()));
    try {
        KieMemoryCompiler.compile(retrieved, Thread.currentThread().getContextClassLoader());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : ScorecardCompilationDTO(org.kie.pmml.models.scorecard.compiler.ScorecardCompilationDTO) Scorecard(org.dmg.pmml.scorecard.Scorecard) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) Test(org.junit.Test)

Example 10 with HasClassLoaderMock

use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock in project drools by kiegroup.

the class KiePMMLScorecardModelFactoryTest method setConstructor.

@Test
public void setConstructor() {
    String fullCharacteristicsClassName = PACKAGE_NAME + ".fullCharacteristicsClassName";
    final CommonCompilationDTO<Scorecard> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, basicComplexPartialScorePmml, basicComplexPartialScore, new HasClassLoaderMock());
    KiePMMLScorecardModelFactory.setConstructor(ScorecardCompilationDTO.fromCompilationDTO(source), scorecardTemplate, fullCharacteristicsClassName);
    final ConstructorDeclaration constructorDeclaration = scorecardTemplate.getDefaultConstructor().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, scorecardTemplate.getName())));
    final BlockStmt body = constructorDeclaration.getBody();
    final ExplicitConstructorInvocationStmt retrieved = CommonCodegenUtils.getExplicitConstructorInvocationStmt(body).orElseThrow(() -> new KiePMMLException(String.format(MISSING_CONSTRUCTOR_IN_BODY, body)));
    Statement expected = JavaParserUtils.parseStatement(String.format("super(\"%1$s\", Collections.emptyList()" + ", new %2$s" + "(), %3$s, %4$s, %5$s, %6$s);\n", getSanitizedClassName(basicComplexPartialScore.getModelName()), fullCharacteristicsClassName, basicComplexPartialScore.getInitialScore(), basicComplexPartialScore.isUseReasonCodes(), REASONCODE_ALGORITHM.class.getName() + "." + REASONCODE_ALGORITHM.byName(basicComplexPartialScore.getReasonCodeAlgorithm().value()), basicComplexPartialScore.getBaselineScore()));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
}
Also used : ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) Scorecard(org.dmg.pmml.scorecard.Scorecard) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)48 HasClassLoaderMock (org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock)48 RegressionModel (org.dmg.pmml.regression.RegressionModel)15 PMML (org.dmg.pmml.PMML)14 CommonCompilationDTO (org.kie.pmml.compiler.api.dto.CommonCompilationDTO)14 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)11 DataDictionary (org.dmg.pmml.DataDictionary)10 DataField (org.dmg.pmml.DataField)10 MiningField (org.dmg.pmml.MiningField)10 MiningSchema (org.dmg.pmml.MiningSchema)10 RegressionCompilationDTO (org.kie.pmml.models.regression.compiler.dto.RegressionCompilationDTO)10 Scorecard (org.dmg.pmml.scorecard.Scorecard)9 CompilationDTO (org.kie.pmml.compiler.api.dto.CompilationDTO)8 Serializable (java.io.Serializable)6 TreeModel (org.dmg.pmml.tree.TreeModel)6 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)6 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)5 Expression (com.github.javaparser.ast.expr.Expression)5 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)5 RegressionTable (org.dmg.pmml.regression.RegressionTable)5