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);
}
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);
}
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);
}
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)));
}
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;
}
Aggregations