use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class ModelUtilsTest method getOpTypeFromFields.
@Test
public void getOpTypeFromFields() {
Optional<OP_TYPE> opType = ModelUtils.getOpTypeFromFields(null, "vsd");
assertNotNull(opType);
assertFalse(opType.isPresent());
final DataDictionary dataDictionary = new DataDictionary();
final List<Field<?>> fields = getFieldsFromDataDictionary(dataDictionary);
opType = ModelUtils.getOpTypeFromFields(fields, "vsd");
assertNotNull(opType);
assertFalse(opType.isPresent());
IntStream.range(0, 3).forEach(i -> {
final DataField dataField = getRandomDataField();
dataDictionary.addDataFields(dataField);
});
fields.clear();
fields.addAll(getFieldsFromDataDictionary(dataDictionary));
dataDictionary.getDataFields().forEach(dataField -> {
Optional<OP_TYPE> retrieved = ModelUtils.getOpTypeFromFields(fields, dataField.getName().getValue());
assertNotNull(retrieved);
assertTrue(retrieved.isPresent());
OP_TYPE expected = OP_TYPE.byName(dataField.getOpType().value());
assertEquals(expected, retrieved.get());
});
}
use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class ModelUtilsTest method getOpTypeFromMiningFields.
@Test
public void getOpTypeFromMiningFields() {
Optional<OP_TYPE> opType = ModelUtils.getOpTypeFromMiningFields(null, "vsd");
assertNotNull(opType);
assertFalse(opType.isPresent());
final MiningSchema miningSchema = new MiningSchema();
opType = ModelUtils.getOpTypeFromMiningFields(miningSchema, "vsd");
assertNotNull(opType);
assertFalse(opType.isPresent());
IntStream.range(0, 3).forEach(i -> {
final MiningField miningField = getRandomMiningField();
miningSchema.addMiningFields(miningField);
});
miningSchema.getMiningFields().forEach(miningField -> {
Optional<OP_TYPE> retrieved = ModelUtils.getOpTypeFromMiningFields(miningSchema, miningField.getName().getValue());
assertNotNull(retrieved);
assertTrue(retrieved.isPresent());
OP_TYPE expected = OP_TYPE.byName(miningField.getOpType().value());
assertEquals(expected, retrieved.get());
});
}
use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class ModelUtilsTest method getTargetFieldsWithTargetFieldsWithTargetsWithoutOptType.
@Test
public void getTargetFieldsWithTargetFieldsWithTargetsWithoutOptType() {
final Model model = new RegressionModel();
final DataDictionary dataDictionary = new DataDictionary();
final MiningSchema miningSchema = new MiningSchema();
final Targets targets = new Targets();
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(OpType.CONTINUOUS);
miningSchema.addMiningFields(miningField);
final Target targetField = getTarget(fieldName, null);
targets.addTargets(targetField);
});
model.setMiningSchema(miningSchema);
model.setTargets(targets);
List<KiePMMLNameOpType> retrieved = ModelUtils.getTargetFields(getFieldsFromDataDictionary(dataDictionary), model);
assertNotNull(retrieved);
assertEquals(miningSchema.getMiningFields().size(), retrieved.size());
retrieved.forEach(kiePMMLNameOpType -> {
Optional<MiningField> optionalMiningField = miningSchema.getMiningFields().stream().filter(fld -> kiePMMLNameOpType.getName().equals(fld.getName().getValue())).findFirst();
assertTrue(optionalMiningField.isPresent());
MiningField miningField = optionalMiningField.get();
OP_TYPE expected = OP_TYPE.byName(miningField.getOpType().value());
assertEquals(expected, kiePMMLNameOpType.getOpType());
});
}
use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class ModelUtilsTest method getTargetFieldsWithTargetFieldsWithOptType.
@Test
public void getTargetFieldsWithTargetFieldsWithOptType() {
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(OpType.CONTINUOUS);
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 -> {
Optional<MiningField> optionalMiningField = miningSchema.getMiningFields().stream().filter(fld -> kiePMMLNameOpType.getName().equals(fld.getName().getValue())).findFirst();
assertTrue(optionalMiningField.isPresent());
MiningField miningField = optionalMiningField.get();
OP_TYPE expected = OP_TYPE.byName(miningField.getOpType().value());
assertEquals(expected, kiePMMLNameOpType.getOpType());
});
}
use of org.kie.pmml.api.enums.OP_TYPE in project drools by kiegroup.
the class CommonCodegenUtils method getExpressionForOpType.
public static Expression getExpressionForOpType(OpType opTypeParam) {
final Expression toReturn;
if (opTypeParam != null) {
final OP_TYPE opType = OP_TYPE.byName(opTypeParam.value());
toReturn = new NameExpr(OP_TYPE.class.getName() + "." + opType.name());
} else {
toReturn = new NullLiteralExpr();
}
return toReturn;
}
Aggregations