use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class KiePMMLDerivedFieldASTFactoryTest method getDerivedField.
private DerivedField getDerivedField(String fieldName) {
DerivedField toReturn = new DerivedField();
toReturn.setName(FieldName.create(fieldName));
final DATA_TYPE[] values = DATA_TYPE.values();
int rndInt = new Random().nextInt(values.length - 1);
DATA_TYPE dataType = values[rndInt];
toReturn.setDataType(DataType.fromValue(dataType.getName()));
return toReturn;
}
use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class KiePMMLTreeModelASTFactory method getKiePMMLDroolsAST.
/**
* Returns the <code>KiePMMLDroolsAST</code> built out of the given parameters.
* It also <b>populate</b> the <b>fieldNameTypeNameMap</b> with mapping between original field' name and <b>original type/generated type</b> tupla
*
* @param dataDictionary
* @param model
* @param fieldTypeMap
* @param types
* @return
*/
public static KiePMMLDroolsAST getKiePMMLDroolsAST(final List<Field<?>> fields, final TreeModel model, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap, final List<KiePMMLDroolsType> types) {
logger.trace("getKiePMMLDroolsAST {} {}", fields, model);
DATA_TYPE targetType = getTargetFieldType(fields, model);
List<OutputField> outputFields = model.getOutput() != null ? model.getOutput().getOutputFields() : Collections.emptyList();
List<KiePMMLDroolsRule> rules = KiePMMLTreeModelNodeASTFactory.factory(fieldTypeMap, outputFields, model.getNoTrueChildStrategy(), targetType).declareRulesFromRootNode(model.getNode(), "");
return new KiePMMLDroolsAST(types, rules);
}
use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class KiePMMLTreeModelNodeASTFactoryTest method declareRulesFromRootIrisNode.
@Test
public void declareRulesFromRootIrisNode() {
Node rootNode = irisModel.getNode();
assertEquals("setosa", rootNode.getScore());
final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
final List<Field<?>> fields = getFieldsFromDataDictionary(irisPmml.getDataDictionary());
DATA_TYPE targetType = getTargetFieldType(fields, irisModel);
KiePMMLDataDictionaryASTFactory.factory(fieldTypeMap).declareTypes(fields);
KiePMMLTreeModelNodeASTFactory.factory(fieldTypeMap, Collections.emptyList(), TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION, targetType).declareRulesFromRootNode(rootNode, "_setosa");
assertFalse(fieldTypeMap.isEmpty());
}
use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class KiePMMLTreeModelNodeASTFactoryTest method isFinalLeaf.
@Test
public void isFinalLeaf() {
Node node = new LeafNode();
DATA_TYPE targetType = DATA_TYPE.STRING;
KiePMMLTreeModelNodeASTFactory.factory(new HashMap<>(), Collections.emptyList(), TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION, targetType).isFinalLeaf(node);
assertTrue(KiePMMLTreeModelNodeASTFactory.factory(new HashMap<>(), Collections.emptyList(), TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION, targetType).isFinalLeaf(node));
node = new ClassifierNode();
assertTrue(KiePMMLTreeModelNodeASTFactory.factory(new HashMap<>(), Collections.emptyList(), TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION, targetType).isFinalLeaf(node));
node.addNodes(new LeafNode());
assertFalse(KiePMMLTreeModelNodeASTFactory.factory(new HashMap<>(), Collections.emptyList(), TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION, targetType).isFinalLeaf(node));
}
use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class ModelUtils method convertToKieOutputField.
/**
* Return a <code>org.kie.pmml.api.models.OutputField</code> out of a <code>org.dmg.pmml.OutputField</code> one
* @param toConvert
* @param field - this may be <code>null</code>
* @return
*/
public static org.kie.pmml.api.models.OutputField convertToKieOutputField(final OutputField toConvert, final Field<?> field) {
final String name = toConvert.getName() != null ? toConvert.getName().getValue() : null;
final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
final DATA_TYPE dataFieldDataType = field != null ? DATA_TYPE.byName(field.getDataType().value()) : null;
final DATA_TYPE dataType = toConvert.getDataType() != null ? DATA_TYPE.byName(toConvert.getDataType().value()) : dataFieldDataType;
final String targetField = toConvert.getTargetField() != null ? toConvert.getTargetField().getValue() : null;
final RESULT_FEATURE resultFeature = toConvert.getResultFeature() != null ? RESULT_FEATURE.byName(toConvert.getResultFeature().value()) : null;
final List<String> allowedValues = field instanceof DataField ? convertDataFieldValues(((DataField) field).getValues()) : null;
return new org.kie.pmml.api.models.OutputField(name, opType, dataType, targetField, resultFeature, allowedValues);
}
Aggregations