use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class InstanceFactoriesTestCommon method commonVerifyKiePMMLParameterField.
static void commonVerifyKiePMMLParameterField(KiePMMLParameterField toVerify, ParameterField source) {
assertNotNull(toVerify);
assertEquals(source.getName().getValue(), toVerify.getName());
DATA_TYPE expectedDataType = DATA_TYPE.byName(source.getDataType().value());
assertEquals(expectedDataType, toVerify.getDataType());
OP_TYPE expectedOpType = OP_TYPE.byName(source.getOpType().value());
assertEquals(expectedOpType, toVerify.getOpType());
String expectedDisplayName = "Display-" + source.getName().getValue();
assertEquals(expectedDisplayName, toVerify.getDisplayName());
}
use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class InstanceFactoriesTestCommon method commonVerifyKiePMMLTarget.
static void commonVerifyKiePMMLTarget(KiePMMLTarget toVerify, Target source) {
assertNotNull(toVerify);
assertEquals(toVerify.getTargetValues().size(), source.getTargetValues().size());
OP_TYPE expectedOpType = OP_TYPE.byName(source.getOpType().value());
assertEquals(expectedOpType, toVerify.getOpType());
assertEquals(source.getField().getValue(), toVerify.getField());
CAST_INTEGER expectedCastInteger = CAST_INTEGER.byName(source.getCastInteger().value());
assertEquals(expectedCastInteger, toVerify.getCastInteger());
assertEquals(source.getMin().doubleValue(), toVerify.getMin(), 0.0);
assertEquals(source.getMax().doubleValue(), toVerify.getMax(), 0.0);
assertEquals(source.getRescaleConstant().doubleValue(), toVerify.getRescaleConstant(), 0.0);
assertEquals(source.getRescaleFactor().doubleValue(), toVerify.getRescaleFactor(), 0.0);
}
use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class ModelUtilsTest method convertToKieOutputField.
@Test
public void convertToKieOutputField() {
final OutputField toConvert = getRandomOutputField();
org.kie.pmml.api.models.OutputField retrieved = ModelUtils.convertToKieOutputField(toConvert, null);
assertNotNull(retrieved);
assertEquals(toConvert.getName().getValue(), retrieved.getName());
OP_TYPE expectedOpType = OP_TYPE.byName(toConvert.getOpType().value());
assertEquals(expectedOpType, retrieved.getOpType());
DATA_TYPE expectedDataType = DATA_TYPE.byName(toConvert.getDataType().value());
assertEquals(expectedDataType, retrieved.getDataType());
assertEquals(toConvert.getTargetField().getValue(), retrieved.getTargetField());
RESULT_FEATURE expectedResultFeature = RESULT_FEATURE.byName(toConvert.getResultFeature().value());
assertEquals(expectedResultFeature, retrieved.getResultFeature());
toConvert.setOpType(null);
toConvert.setTargetField(null);
retrieved = ModelUtils.convertToKieOutputField(toConvert, null);
assertNull(retrieved.getOpType());
assertNull(retrieved.getTargetField());
}
use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class ModelUtilsTest method getTargetFieldsWithTargetFieldsWithoutOptType.
@Test
public void getTargetFieldsWithTargetFieldsWithoutOptType() {
final Model model = new RegressionModel();
final DataDictionary dataDictionary = new DataDictionary();
final MiningSchema miningSchema = new MiningSchema();
IntStream.range(0, 3).forEach(i -> {
final String fieldName = "fieldName-" + i;
final DataField dataField = getDataField(fieldName, OpType.CATEGORICAL, DataType.STRING);
dataDictionary.addDataFields(dataField);
final MiningField miningField = getMiningField(fieldName, MiningField.UsageType.PREDICTED);
miningField.setOpType(null);
miningSchema.addMiningFields(miningField);
});
model.setMiningSchema(miningSchema);
List<KiePMMLNameOpType> retrieved = ModelUtils.getTargetFields(getFieldsFromDataDictionary(dataDictionary), model);
assertNotNull(retrieved);
assertEquals(miningSchema.getMiningFields().size(), retrieved.size());
retrieved.forEach(kiePMMLNameOpType -> {
assertTrue(miningSchema.getMiningFields().stream().anyMatch(fld -> kiePMMLNameOpType.getName().equals(fld.getName().getValue())));
Optional<DataField> optionalDataField = dataDictionary.getDataFields().stream().filter(fld -> kiePMMLNameOpType.getName().equals(fld.getName().getValue())).findFirst();
assertTrue(optionalDataField.isPresent());
DataField dataField = optionalDataField.get();
OP_TYPE expected = OP_TYPE.byName(dataField.getOpType().value());
assertEquals(expected, kiePMMLNameOpType.getOpType());
});
}
use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class ModelUtilsTest method getOpTypeByMiningFields.
@Test
public void getOpTypeByMiningFields() {
final Model model = new RegressionModel();
final DataDictionary dataDictionary = new DataDictionary();
final MiningSchema miningSchema = new MiningSchema();
IntStream.range(0, 3).forEach(i -> {
final DataField dataField = getRandomDataField();
dataDictionary.addDataFields(dataField);
final MiningField miningField = getRandomMiningField();
miningField.setName(dataField.getName());
miningSchema.addMiningFields(miningField);
});
model.setMiningSchema(miningSchema);
miningSchema.getMiningFields().forEach(miningField -> {
OP_TYPE retrieved = ModelUtils.getOpType(getFieldsFromDataDictionary(dataDictionary), model, miningField.getName().getValue());
assertNotNull(retrieved);
OP_TYPE expected = OP_TYPE.byName(miningField.getOpType().value());
assertEquals(expected, retrieved);
});
}
Aggregations