Search in sources :

Example 66 with DataField

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

the class KiePMMLMiningFieldFactoryTest method getMiningFieldVariableDeclarationNoAllowedValuesNoIntervals.

@Test
public void getMiningFieldVariableDeclarationNoAllowedValuesNoIntervals() throws IOException {
    DataField dataField = getRandomDataField();
    dataField.getValues().clear();
    dataField.getIntervals().clear();
    MiningField miningField = new MiningField();
    miningField.setName(dataField.getName());
    miningField.setUsageType(MiningField.UsageType.TARGET);
    BlockStmt retrieved = KiePMMLMiningFieldFactory.getMiningFieldVariableDeclaration(VARIABLE_NAME, miningField, Collections.singletonList(dataField));
    String dataTypeString = DATA_TYPE.class.getName() + "." + DATA_TYPE.byName(dataField.getDataType().value()).name();
    String text = getFileContent(TEST_01_SOURCE);
    Statement expected = JavaParserUtils.parseBlock(String.format(text, VARIABLE_NAME, miningField.getName().getValue(), dataTypeString));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
    List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLInterval.class, KiePMMLMiningField.class, DATA_TYPE.class);
    commonValidateCompilationWithImports(retrieved, imports);
}
Also used : KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) MiningField(org.dmg.pmml.MiningField) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) DataField(org.dmg.pmml.DataField) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) Test(org.junit.Test)

Example 67 with DataField

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

the class KiePMMLMiningFieldFactoryTest method getMiningFieldVariableDeclarationWithAllowedValuesNoIntervals.

@Test
public void getMiningFieldVariableDeclarationWithAllowedValuesNoIntervals() throws IOException {
    DataField dataField = getRandomDataField();
    dataField.getIntervals().clear();
    MiningField miningField = new MiningField();
    miningField.setName(dataField.getName());
    miningField.setUsageType(MiningField.UsageType.TARGET);
    BlockStmt retrieved = KiePMMLMiningFieldFactory.getMiningFieldVariableDeclaration(VARIABLE_NAME, miningField, Collections.singletonList(dataField));
    String dataTypeString = DATA_TYPE.class.getName() + "." + DATA_TYPE.byName(dataField.getDataType().value()).name();
    String text = getFileContent(TEST_02_SOURCE);
    Statement expected = JavaParserUtils.parseBlock(String.format(text, VARIABLE_NAME, miningField.getName().getValue(), dataTypeString, dataField.getValues().get(0).getValue(), dataField.getValues().get(1).getValue(), dataField.getValues().get(2).getValue()));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
    List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLInterval.class, KiePMMLMiningField.class, DATA_TYPE.class);
    commonValidateCompilationWithImports(retrieved, imports);
}
Also used : KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) MiningField(org.dmg.pmml.MiningField) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) DataField(org.dmg.pmml.DataField) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) Test(org.junit.Test)

Example 68 with DataField

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

the class KiePMMLMiningFieldFactoryTest method getMiningFieldVariableDeclarationWithAllowedValuesAndIntervals.

@Test
public void getMiningFieldVariableDeclarationWithAllowedValuesAndIntervals() throws IOException {
    DataField dataField = getRandomDataField();
    MiningField miningField = new MiningField();
    miningField.setName(dataField.getName());
    miningField.setUsageType(MiningField.UsageType.TARGET);
    BlockStmt retrieved = KiePMMLMiningFieldFactory.getMiningFieldVariableDeclaration(VARIABLE_NAME, miningField, Collections.singletonList(dataField));
    String dataTypeString = DATA_TYPE.class.getName() + "." + DATA_TYPE.byName(dataField.getDataType().value()).name();
    String text = getFileContent(TEST_03_SOURCE);
    Statement expected = JavaParserUtils.parseBlock(String.format(text, VARIABLE_NAME, miningField.getName().getValue(), dataTypeString, dataField.getValues().get(0).getValue(), dataField.getValues().get(1).getValue(), dataField.getValues().get(2).getValue(), dataField.getIntervals().get(0).getLeftMargin(), dataField.getIntervals().get(0).getRightMargin(), dataField.getIntervals().get(0).getClosure().name(), dataField.getIntervals().get(1).getLeftMargin(), dataField.getIntervals().get(1).getRightMargin(), dataField.getIntervals().get(1).getClosure().name(), dataField.getIntervals().get(2).getLeftMargin(), dataField.getIntervals().get(2).getRightMargin(), dataField.getIntervals().get(2).getClosure().name()));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
    List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLInterval.class, KiePMMLMiningField.class, DATA_TYPE.class);
    commonValidateCompilationWithImports(retrieved, imports);
}
Also used : KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) MiningField(org.dmg.pmml.MiningField) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) DataField(org.dmg.pmml.DataField) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) Test(org.junit.Test)

Example 69 with DataField

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

the class KiePMMLDataDictionaryASTFactoryTest method declareTypes.

@Test
public void declareTypes() {
    List<DataField> dataFields = Arrays.asList(getTypeDataField(), getDottedTypeDataField(), getTypeDataField(), getDottedTypeDataField());
    DataDictionary dataDictionary = new DataDictionary(dataFields);
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
    List<KiePMMLDroolsType> retrieved = KiePMMLDataDictionaryASTFactory.factory(fieldTypeMap).declareTypes(getFieldsFromDataDictionary(dataDictionary));
    assertNotNull(retrieved);
    assertEquals(dataFields.size(), retrieved.size());
    IntStream.range(0, dataFields.size()).forEach(i -> commonVerifyTypeDeclarationDescr(dataFields.get(i), fieldTypeMap, retrieved.get(i)));
}
Also used : KiePMMLASTTestUtils.getDottedTypeDataField(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getDottedTypeDataField) DataField(org.dmg.pmml.DataField) KiePMMLASTTestUtils.getTypeDataField(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getTypeDataField) HashMap(java.util.HashMap) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 70 with DataField

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

the class KiePMMLASTTestUtils method getTypeDataField.

public static DataField getTypeDataField() {
    DataField toReturn = new DataField();
    toReturn.setOpType(OpType.CONTINUOUS);
    toReturn.setDataType(DataType.DATE);
    toReturn.setName(FieldName.create("dataField"));
    return toReturn;
}
Also used : DataField(org.dmg.pmml.DataField)

Aggregations

DataField (org.dmg.pmml.DataField)101 Test (org.junit.Test)51 DataDictionary (org.dmg.pmml.DataDictionary)42 MiningField (org.dmg.pmml.MiningField)42 MiningSchema (org.dmg.pmml.MiningSchema)30 PMMLModelTestUtils.getRandomDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField)28 RegressionModel (org.dmg.pmml.regression.RegressionModel)27 CommonTestingUtils.getFieldsFromDataDictionary (org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary)27 FieldName (org.dmg.pmml.FieldName)24 Model (org.dmg.pmml.Model)24 PMMLModelTestUtils.getDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getDataField)22 DataType (org.dmg.pmml.DataType)19 OutputField (org.dmg.pmml.OutputField)19 PMMLModelTestUtils.getRandomMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomMiningField)19 PMMLModelTestUtils.getMiningField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getMiningField)18 ArrayList (java.util.ArrayList)17 List (java.util.List)17 PMML (org.dmg.pmml.PMML)17 Collectors (java.util.stream.Collectors)16 OpType (org.dmg.pmml.OpType)15