Search in sources :

Example 21 with DataDictionary

use of org.dmg.pmml.DataDictionary in project drools by kiegroup.

the class PMMLModelTestUtils method getDataDictionary.

public static DataDictionary getDataDictionary(List<DataField> dataFields) {
    DataDictionary toReturn = new DataDictionary();
    toReturn.addDataFields(dataFields.toArray(new DataField[0]));
    return toReturn;
}
Also used : DataField(org.dmg.pmml.DataField) DataDictionary(org.dmg.pmml.DataDictionary)

Example 22 with DataDictionary

use of org.dmg.pmml.DataDictionary in project drools by kiegroup.

the class PMMLModelTestUtils method getPMMLWithRandomTestModel.

public static PMML getPMMLWithRandomTestModel() {
    PMML toReturn = new PMML();
    DataDictionary dataDictionary = getRandomDataDictionary();
    toReturn.setDataDictionary(dataDictionary);
    toReturn.addModels(getRandomTestModel(dataDictionary));
    return toReturn;
}
Also used : PMML(org.dmg.pmml.PMML) DataDictionary(org.dmg.pmml.DataDictionary)

Example 23 with DataDictionary

use of org.dmg.pmml.DataDictionary in project drools by kiegroup.

the class PMMLModelTestUtils method getRandomDataDictionary.

public static DataDictionary getRandomDataDictionary() {
    DataDictionary toReturn = new DataDictionary();
    IntStream.range(0, new Random().nextInt(3) + 2).forEach(i -> toReturn.addDataFields(getRandomDataField()));
    return toReturn;
}
Also used : Random(java.util.Random) DataDictionary(org.dmg.pmml.DataDictionary)

Example 24 with DataDictionary

use of org.dmg.pmml.DataDictionary in project drools by kiegroup.

the class KiePMMLSimpleSetPredicateFactoryTest method getSimpleSetPredicateVariableDeclaration.

@Test
public void getSimpleSetPredicateVariableDeclaration() throws IOException {
    String variableName = "variableName";
    Array.Type arrayType = Array.Type.STRING;
    List<String> values = getStringObjects(arrayType, 4);
    SimpleSetPredicate simpleSetPredicate = getSimpleSetPredicate(values, arrayType, SimpleSetPredicate.BooleanOperator.IS_IN);
    String arrayTypeString = ARRAY_TYPE.class.getName() + "." + ARRAY_TYPE.byName(simpleSetPredicate.getArray().getType().value());
    String booleanOperatorString = IN_NOTIN.class.getName() + "." + IN_NOTIN.byName(simpleSetPredicate.getBooleanOperator().value());
    String valuesString = values.stream().map(valueString -> "\"" + valueString + "\"").collect(Collectors.joining(","));
    DataField dataField = new DataField();
    dataField.setName(simpleSetPredicate.getField());
    dataField.setDataType(DataType.DOUBLE);
    DataDictionary dataDictionary = new DataDictionary();
    dataDictionary.addDataFields(dataField);
    BlockStmt retrieved = KiePMMLSimpleSetPredicateFactory.getSimpleSetPredicateVariableDeclaration(variableName, simpleSetPredicate);
    String text = getFileContent(TEST_01_SOURCE);
    Statement expected = JavaParserUtils.parseBlock(String.format(text, variableName, simpleSetPredicate.getField().getValue(), arrayTypeString, booleanOperatorString, valuesString));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
    List<Class<?>> imports = Arrays.asList(KiePMMLSimpleSetPredicate.class, Arrays.class, Collections.class);
    commonValidateCompilationWithImports(retrieved, imports);
}
Also used : Array(org.dmg.pmml.Array) PMMLModelTestUtils.getArray(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getArray) ARRAY_TYPE(org.kie.pmml.api.enums.ARRAY_TYPE) Arrays(java.util.Arrays) JavaParserUtils(org.kie.pmml.compiler.commons.utils.JavaParserUtils) DataType(org.dmg.pmml.DataType) KiePMMLSimpleSetPredicate(org.kie.pmml.commons.model.predicates.KiePMMLSimpleSetPredicate) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) DataDictionary(org.dmg.pmml.DataDictionary) Test(org.junit.Test) Statement(com.github.javaparser.ast.stmt.Statement) Collectors(java.util.stream.Collectors) Array(org.dmg.pmml.Array) FileUtils.getFileContent(org.kie.test.util.filesystem.FileUtils.getFileContent) DataField(org.dmg.pmml.DataField) FieldName(org.dmg.pmml.FieldName) List(java.util.List) PMMLModelTestUtils.getStringObjects(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getStringObjects) CodegenTestUtils.commonValidateCompilationWithImports(org.kie.pmml.compiler.commons.testutils.CodegenTestUtils.commonValidateCompilationWithImports) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) IN_NOTIN(org.kie.pmml.api.enums.IN_NOTIN) PMMLModelTestUtils.getArray(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getArray) Collections(java.util.Collections) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) DataField(org.dmg.pmml.DataField) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) DataDictionary(org.dmg.pmml.DataDictionary) KiePMMLSimpleSetPredicate(org.kie.pmml.commons.model.predicates.KiePMMLSimpleSetPredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) Test(org.junit.Test)

Example 25 with DataDictionary

use of org.dmg.pmml.DataDictionary in project drools by kiegroup.

the class KiePMMLTreeModelFactoryTest method getKiePMMLDroolsAST.

@Test
public void getKiePMMLDroolsAST() {
    final DataDictionary dataDictionary = pmml.getDataDictionary();
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = getFieldTypeMap(pmml.getDataDictionary(), pmml.getTransformationDictionary(), treeModel.getLocalTransformations());
    KiePMMLDroolsAST retrieved = KiePMMLTreeModelFactory.getKiePMMLDroolsAST(getFieldsFromDataDictionary(dataDictionary), treeModel, fieldTypeMap, Collections.emptyList());
    assertNotNull(retrieved);
    List<DataField> dataFields = dataDictionary.getDataFields();
    assertEquals(dataFields.size(), fieldTypeMap.size());
    dataFields.forEach(dataField -> assertTrue(fieldTypeMap.containsKey(dataField.getName().getValue())));
}
Also used : KiePMMLDroolsAST(org.kie.pmml.models.drools.ast.KiePMMLDroolsAST) DataField(org.dmg.pmml.DataField) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Aggregations

DataDictionary (org.dmg.pmml.DataDictionary)48 DataField (org.dmg.pmml.DataField)41 Test (org.junit.Test)41 CommonTestingUtils.getFieldsFromDataDictionary (org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary)30 MiningSchema (org.dmg.pmml.MiningSchema)28 MiningField (org.dmg.pmml.MiningField)27 RegressionModel (org.dmg.pmml.regression.RegressionModel)27 PMMLModelTestUtils.getDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField)21 PMMLModelTestUtils.getRandomDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField)21 Model (org.dmg.pmml.Model)19 PMMLModelTestUtils.getMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField)17 PMMLModelTestUtils.getRandomMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField)17 PMML (org.dmg.pmml.PMML)12 OutputField (org.dmg.pmml.OutputField)11 Collectors (java.util.stream.Collectors)10 Assert.assertTrue (org.junit.Assert.assertTrue)10 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)10 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)10 HasClassLoaderMock (org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock)10 Arrays (java.util.Arrays)9