use of org.dmg.pmml.TransformationDictionary in project drools by kiegroup.
the class KiePMMLTransformationDictionaryFactoryTest method getKiePMMLTransformationDictionaryVariableDeclaration.
@Test
public void getKiePMMLTransformationDictionaryVariableDeclaration() throws IOException {
TransformationDictionary transformationDictionary = new TransformationDictionary();
transformationDictionary.addDefineFunctions(getDefineFunctions());
transformationDictionary.addDerivedFields(getDerivedFields());
BlockStmt retrieved = KiePMMLTransformationDictionaryFactory.getKiePMMLTransformationDictionaryVariableDeclaration(transformationDictionary);
String text = getFileContent(TEST_01_SOURCE);
Statement expected = JavaParserUtils.parseBlock(text);
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(KiePMMLParameterField.class, KiePMMLConstant.class, KiePMMLFieldRef.class, KiePMMLApply.class, KiePMMLDerivedField.class, KiePMMLDefineFunction.class, KiePMMLTransformationDictionary.class, Arrays.class, Collections.class);
commonValidateCompilationWithImports(retrieved, imports);
}
use of org.dmg.pmml.TransformationDictionary in project drools by kiegroup.
the class KiePMMLTransformationDictionaryInstanceFactoryTest method getKiePMMLTransformationDictionary.
@Test
public void getKiePMMLTransformationDictionary() {
final TransformationDictionary toConvert = getRandomTransformationDictionary();
KiePMMLTransformationDictionary retrieved = KiePMMLTransformationDictionaryInstanceFactory.getKiePMMLTransformationDictionary(toConvert, Collections.emptyList());
assertNotNull(retrieved);
List<DerivedField> derivedFields = toConvert.getDerivedFields();
List<KiePMMLDerivedField> derivedFieldsToVerify = retrieved.getDerivedFields();
assertEquals(derivedFields.size(), derivedFieldsToVerify.size());
derivedFields.forEach(derivedFieldSource -> {
Optional<KiePMMLDerivedField> derivedFieldToVerify = derivedFieldsToVerify.stream().filter(param -> param.getName().equals(derivedFieldSource.getName().getValue())).findFirst();
assertTrue(derivedFieldToVerify.isPresent());
commonVerifyKiePMMLDerivedField(derivedFieldToVerify.get(), derivedFieldSource);
});
List<DefineFunction> defineFunctions = toConvert.getDefineFunctions();
List<KiePMMLDefineFunction> defineFunctionsToVerify = retrieved.getDefineFunctions();
assertEquals(defineFunctions.size(), defineFunctionsToVerify.size());
defineFunctions.forEach(defineFunctionSource -> {
Optional<KiePMMLDefineFunction> defineFunctionToVerify = defineFunctionsToVerify.stream().filter(param -> param.getName().equals(defineFunctionSource.getName())).findFirst();
assertTrue(defineFunctionToVerify.isPresent());
commonVerifyKiePMMLDefineFunction(defineFunctionToVerify.get(), defineFunctionSource);
});
}
use of org.dmg.pmml.TransformationDictionary in project drools by kiegroup.
the class KiePMMLRegressionModelFactoryTest method setup.
@BeforeClass
public static void setup() {
Random random = new Random();
Set<String> fieldNames = new HashSet<>();
regressionTables = IntStream.range(0, 3).mapToObj(i -> {
List<CategoricalPredictor> categoricalPredictors = new ArrayList<>();
List<NumericPredictor> numericPredictors = new ArrayList<>();
List<PredictorTerm> predictorTerms = new ArrayList<>();
IntStream.range(0, 3).forEach(j -> {
String catFieldName = "CatPred-" + j;
String numFieldName = "NumPred-" + j;
categoricalPredictors.add(getCategoricalPredictor(catFieldName, random.nextDouble(), random.nextDouble()));
numericPredictors.add(getNumericPredictor(numFieldName, random.nextInt(), random.nextDouble()));
predictorTerms.add(getPredictorTerm("PredTerm-" + j, random.nextDouble(), Arrays.asList(catFieldName, numFieldName)));
fieldNames.add(catFieldName);
fieldNames.add(numFieldName);
});
return getRegressionTable(categoricalPredictors, numericPredictors, predictorTerms, tableIntercept + random.nextDouble(), tableTargetCategory + "-" + i);
}).collect(Collectors.toList());
dataFields = new ArrayList<>();
miningFields = new ArrayList<>();
fieldNames.forEach(fieldName -> {
dataFields.add(getDataField(fieldName, OpType.CATEGORICAL, DataType.STRING));
miningFields.add(getMiningField(fieldName, MiningField.UsageType.ACTIVE));
});
targetMiningField = miningFields.get(0);
targetMiningField.setUsageType(MiningField.UsageType.TARGET);
dataDictionary = getDataDictionary(dataFields);
transformationDictionary = new TransformationDictionary();
miningSchema = getMiningSchema(miningFields);
regressionModel = getRegressionModel(modelName, MiningFunction.REGRESSION, miningSchema, regressionTables);
COMPILATION_UNIT = getFromFileName(KIE_PMML_REGRESSION_MODEL_TEMPLATE_JAVA);
MODEL_TEMPLATE = COMPILATION_UNIT.getClassByName(KIE_PMML_REGRESSION_MODEL_TEMPLATE).get();
pmml = new PMML();
pmml.setDataDictionary(dataDictionary);
pmml.setTransformationDictionary(transformationDictionary);
pmml.addModels(regressionModel);
}
use of org.dmg.pmml.TransformationDictionary in project drools by kiegroup.
the class PMMLModelTestUtils method getRandomTransformationDictionary.
public static TransformationDictionary getRandomTransformationDictionary() {
final TransformationDictionary toReturn = new TransformationDictionary();
IntStream.range(0, 3).forEach(i -> {
toReturn.addDerivedFields(getDerivedField("DerivedField-" + i));
toReturn.addDefineFunctions(getDefineFunction("DefineFunction-" + i));
});
return toReturn;
}
Aggregations