use of org.dmg.pmml.DataField 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.DataField in project drools by kiegroup.
the class PMMLModelTestUtils method getDataField.
public static DataField getDataField(String fieldName, OpType opType) {
DataField toReturn = new DataField();
toReturn.setName(FieldName.create(fieldName));
toReturn.setOpType(opType);
return toReturn;
}
use of org.dmg.pmml.DataField 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.DataField in project drools by kiegroup.
the class KiePMMLMiningFieldInstanceFactoryTest method getKiePMMLMiningField.
@Test
public void getKiePMMLMiningField() {
DataField dataField = getRandomDataField();
MiningField toConvert = getRandomMiningField(dataField);
KiePMMLMiningField toVerify = KiePMMLMiningFieldInstanceFactory.getKiePMMLMiningField(toConvert, dataField);
commonVerifyKiePMMLMiningField(toVerify, toConvert, dataField);
}
use of org.dmg.pmml.DataField in project drools by kiegroup.
the class KiePMMLUtil method load.
/**
* @param is
* @return
* @throws SAXException
* @throws JAXBException
* @see org.jpmml.model.PMMLUtil#unmarshal(InputStream)
*/
public static PMML load(final InputStream is, final String fileName) throws SAXException, JAXBException {
PMML toReturn = org.jpmml.model.PMMLUtil.unmarshal(is);
String cleanedFileName = fileName.contains(".") ? fileName.substring(0, fileName.indexOf('.')) : fileName;
List<DataField> dataFields = toReturn.getDataDictionary().getDataFields();
List<Model> models = toReturn.getModels();
for (int i = 0; i < models.size(); i++) {
Model model = models.get(i);
populateMissingModelName(model, cleanedFileName, i);
populateMissingOutputFieldDataType(model, dataFields);
populateMissingMiningTargetField(model, dataFields);
populateMissingPredictedOutputFieldTarget(model);
if (model instanceof MiningModel) {
populateCorrectMiningModel((MiningModel) model);
}
}
return toReturn;
}
Aggregations