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